Skip to content

Commit 77c5014

Browse files
authored
fix(card): update card design (#290)
* fix(card): update card component design #287 * fix(card): minor changes and fixes
1 parent 3e544ed commit 77c5014

File tree

3 files changed

+100
-81
lines changed

3 files changed

+100
-81
lines changed

lib/card/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { themr } from 'react-css-themr';
44
import classnames from 'classnames';
5+
import { FaAngleDoubleDown } from 'react-icons/fa';
56
import defaultTheme from './theme.module.scss';
67
import '../globals/fonts.scss';
78

@@ -11,12 +12,19 @@ class Card extends React.Component {
1112
this.state = {
1213
expanded: false,
1314
};
15+
this.expandedContentRef = null;
1416
}
1517

1618
toggleCard = () => {
1719
this.setState(prevState => ({
1820
expanded: !prevState.expanded,
1921
}));
22+
if (this.expandedContentRef.clientHeight) {
23+
this.expandedContentRef.style.height = 0;
24+
} else {
25+
const wrapper = this.expandedContentRef.firstChild;
26+
this.expandedContentRef.style.height = `${wrapper.clientHeight}px`;
27+
}
2028
};
2129

2230
renderFooter = () => {
@@ -35,10 +43,7 @@ class Card extends React.Component {
3543

3644
const iconProps = {
3745
onClick: this.toggleCard,
38-
className: classnames(
39-
theme['more-icon'],
40-
{ [theme['less-icon']]: expanded },
41-
),
46+
className: classnames(theme['expand-icon'], expanded ? theme.open : theme.close),
4247
'aria-label': 'more-icon',
4348
};
4449

@@ -52,16 +57,17 @@ class Card extends React.Component {
5257
</div>
5358
{/* eslint-disable jsx-a11y/click-events-have-key-events */}
5459
{/* eslint-disable jsx-a11y/no-static-element-interactions */}
55-
{expandedContent !== null && <div {...iconProps} />}
60+
{expandedContent !== null && <FaAngleDoubleDown {...iconProps} />}
5661
</div>
5762
);
5863
}
5964

6065
renderContent = () => {
61-
const { children } = this.props;
66+
const { children, theme } = this.props;
6267

6368
const contentAreaProps = {
6469
'aria-label': 'card-content',
70+
className: theme.cardContent,
6571
};
6672

6773
return (
@@ -131,15 +137,16 @@ class Card extends React.Component {
131137
<div {...rootProps}>
132138
{ this.renderHeader() }
133139
{ this.renderContent() }
134-
{ this.renderFooter() }
135140
<div
141+
ref={ref => this.expandedContentRef = ref}
136142
className={classnames(
137143
theme.expandedContent, 'expandedContent',
138144
expanded ? `${theme.expanded} expanded` : `${theme.collapsed} collapsed`,
139145
)}
140146
>
141147
{(expandedContent !== null) && <HiddenContent />}
142148
</div>
149+
{ this.renderFooter() }
143150
</div>
144151
);
145152
}

lib/card/tests/render.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Card Render tests', () => {
5353
wrappedComponent.setProps({ expandedContent: <div>This is expanded content</div> });
5454

5555
expect(simulatedValue()).to.equal(0);
56-
wrappedComponent.find('div[aria-label="more-icon"]').simulate('click');
56+
wrappedComponent.find('svg[aria-label="more-icon"]').simulate('click');
5757
expect(simulatedValue()).to.equal(1);
5858
});
5959
});

lib/card/theme.module.scss

Lines changed: 85 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,117 @@
11
@import '../globals/theme';
2-
32
:local(.card) {
4-
display: flex;
5-
flex-direction: column;
6-
box-sizing: border-box;
7-
background: $original-white;
8-
border-radius: 3px;
9-
padding: 15px 20px;
10-
margin: 5px;
11-
font-family: Roboto, sans-serif;
3+
display: flex;
4+
flex-direction: column;
5+
box-sizing: border-box;
6+
background: $original-white;
7+
border-radius: 3px;
8+
padding: 1.6%;
9+
margin: 5px;
10+
font-family: Roboto, sans-serif;
1211
}
12+
1313
.expandedContent {
14-
max-height: 0;
15-
overflow: hidden;
16-
&.expanded {
17-
max-height: 2000px;
18-
transition: max-height 1s ease;
19-
}
20-
&.collapsed {
21-
max-height: 0;
22-
transition: max-height 0.5s ease;
23-
}
14+
-moz-transition: height .5s;
15+
-ms-transition: height .5s;
16+
-o-transition: height .5s;
17+
-webkit-transition: height .5s;
18+
transition: height .5s;
19+
height: 0;
20+
overflow: hidden;
21+
@media only screen and (max-width: 768px) {
22+
padding: 0 3%;
23+
}
24+
@media only screen and (max-width:500px) {
25+
padding: 0 5%;
26+
line-height: 1.4em;
27+
}
2428
}
29+
2530
:local(.noPadding) {
26-
padding: 0;
31+
padding: 0;
2732
}
2833

2934
:local(.wrapContent) {
30-
display: inline-block;
35+
display: inline-block;
3136
}
3237

3338
:local(.elevation-low) {
34-
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14),
35-
0 3px 1px -2px rgba(0, 0, 0, 0.2),
36-
0 1px 5px 0 rgba(0, 0, 0, 0.12);
39+
-webkit-box-shadow: 0 1px 3px 1.5px #d4d4d5, 0 0 0 1px #d4d4d5;
40+
box-shadow: 0 1px 3px 1.5px #d4d4d5, 0 0 0 1px #d4d4d5;
3741
}
3842

3943
:local(.elevation-medium) {
40-
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14),
41-
0 1px 10px 0 rgba(0, 0, 0, 0.12),
42-
0 2px 4px -1px rgba(0, 0, 0, 0.2);
44+
-webkit-box-shadow: 0 1px 3px 3px #d4d4d5, 0 0 0 1px #d4d4d5;
45+
box-shadow: 0 1px 3px 3px #d4d4d5, 0 0 0 1px #d4d4d5;
4346
}
4447

4548
:local(.elevation-high) {
46-
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14),
47-
0 6px 30px 5px rgba(0, 0, 0, 0.12),
48-
0 8px 10px -5px rgba(0, 0, 0, 0.2);
49+
-webkit-box-shadow: 0 1px 3px 4px #d4d4d5, 0 0 0 2px #d4d4d5;
50+
box-shadow: 0 1px 3px 4px #d4d4d5, 0 0 0 2px #d4d4d5;
4951
}
5052

5153
:local(.cardHeader) {
52-
font-weight: bold;
53-
font-size: 18px;
54-
padding: 5px 0;
55-
margin-bottom: 15px;
54+
font-weight: bold;
55+
font-size: 18px;
56+
padding: 5px 0;
57+
margin-bottom: 15px;
58+
@media only screen and (max-width: 768px) {
59+
padding: 1% 3%;
60+
}
61+
@media only screen and (max-width:500px) {
62+
padding: 2% 5%;
63+
line-height: 1.4em;
64+
}
65+
}
66+
67+
:local(.cardContent) {
68+
margin-bottom: 0.5em;
69+
@media only screen and (max-width: 768px) {
70+
padding: 1% 3%;
71+
}
72+
@media only screen and (max-width:500px) {
73+
padding: 2% 5%;
74+
line-height: 1.4em;
75+
}
5676
}
5777

5878
:local(.cardFooter) {
59-
width: 100%;
60-
margin-top: 2%;
61-
display: flex;
62-
justify-content: space-between;
63-
box-sizing: border-box;
64-
padding: 1%;
65-
font-size: 0.8rem;
79+
width: 100%;
80+
margin-top: 0.2em;
81+
display: flex;
82+
justify-content: space-between;
83+
box-sizing: border-box;
84+
padding: 0.5%;
85+
font-size: 0.8rem;
86+
flex-direction: column;
87+
@media only screen and (max-width: 768px) {
88+
padding: 1% 3%;
89+
}
90+
@media only screen and (max-width:500px) {
91+
padding: 2% 5%;
92+
line-height: 1.4em;
93+
}
6694
}
6795

6896
:local(.card-actions) {
69-
float: left;
97+
float: left;
98+
align-self: center;
99+
height: 100%;
100+
width: 50%;
101+
}
102+
103+
:local(.expand-icon) {
70104
align-self: center;
71-
height: 100%;
72-
width: 50%;
105+
transition: transform 0.5s linear;
106+
padding: 1%;
107+
font-size: 1.36em;
108+
cursor: pointer;
73109
}
74110

75-
:local(.more-icon) {
76-
height: 20px;
77-
width: 20px;
78-
position: relative;
79-
border-radius: 50%;
80-
box-sizing: border-box;
81-
padding: 1em;
82-
&:hover {
83-
cursor: pointer;
84-
}
85-
&::after {
86-
position: absolute;
87-
content: '';
88-
display: block;
89-
border-left: 2px solid #454a4f;
90-
border-bottom: 2px solid #454a4f;
91-
height: 8px;
92-
width: 8px;
93-
top: 0.4em;
94-
left: 30%;
95-
transform: rotate(-45deg);
96-
transition: 0.5s ease-in-out;
97-
}
111+
:local(.open) {
112+
transform: rotate(180deg);
98113
}
99114

100-
:local(.less-icon) {
101-
&::after {
102-
top: 0.7em;
103-
transform: rotate(135deg);
104-
}
105-
}
115+
:local(.close) {
116+
transform: rotate(0deg);
117+
}

0 commit comments

Comments
 (0)