-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathCard.js
93 lines (84 loc) · 2.23 KB
/
Card.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import PropTypes from 'prop-types';
import className from 'classnames';
import omitProps from '../../util/omitProps';
import css from './Card.css';
import DefaultCardHeader from './headers/DefaultCardHeader';
import StripesOverlayWrapper from '../../util/StripesOverlayWrapper';
export default class Card extends React.Component {
static propTypes = {
bodyClass: PropTypes.string,
cardClass: PropTypes.string,
cardStyle: PropTypes.oneOf([
'default',
'negative',
'positive',
]),
children: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]).isRequired,
headerClass: PropTypes.string,
headerComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.string, PropTypes.func]),
headerEnd: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
headerProps: PropTypes.object,
headerStart: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]).isRequired,
marginBottom0: PropTypes.bool,
roundedBorder: PropTypes.bool,
}
static defaultProps = {
cardStyle: 'default',
headerComponent: DefaultCardHeader,
}
getCardStyle = () => {
return className(
css.card,
css[this.props.cardStyle],
{ [`${css.marginBottom0}`]: this.props.marginBottom0 },
{ [`${css.roundedBorder}`]: this.props.roundedBorder },
this.props.cardClass,
);
}
render() {
const {
bodyClass,
headerComponent: HeaderComponent,
children
} = this.props;
const customProps = omitProps(this.props, [
'bodyClass',
'cardClass',
'cardStyle',
'children',
'headerClass',
'headerComponent',
'headerEnd',
'headerProps',
'headerStart',
'marginBottom0',
'roundedBorder',
]);
return (
<StripesOverlayWrapper>
<div
className={this.getCardStyle()}
{...customProps}
>
<HeaderComponent {...this.props} />
<div
data-test-card-body
className={`${css.body} ${bodyClass || ''}`}
>
{children}
</div>
</div>
</StripesOverlayWrapper>
);
}
}