UNPKG

1.32 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 /** Toggles card padding using `.card-body` */
8 body: PropTypes.bool,
9 /** Add custom class */
10 className: PropTypes.string,
11 /** Change background color of component */
12 color: PropTypes.string,
13 /** Change underlying component's CSS base class name */
14 cssModule: PropTypes.object,
15 innerRef: PropTypes.oneOfType([
16 PropTypes.object,
17 PropTypes.string,
18 PropTypes.func,
19 ]),
20 /** Inverts the color */
21 inverse: PropTypes.bool,
22 /** Changes the card to have only outline */
23 outline: PropTypes.bool,
24 /** Set a custom element for this component */
25 tag: tagPropType,
26};
27
28function Card(props) {
29 const {
30 className,
31 cssModule,
32 color,
33 body,
34 inverse,
35 outline,
36 tag: Tag = 'div',
37 innerRef,
38 ...attributes
39 } = props;
40 const classes = mapToCssModules(
41 classNames(
42 className,
43 'card',
44 inverse ? 'text-white' : false,
45 body ? 'card-body' : false,
46 color ? `${outline ? 'border' : 'bg'}-${color}` : false,
47 ),
48 cssModule,
49 );
50
51 return <Tag {...attributes} className={classes} ref={innerRef} />;
52}
53
54Card.propTypes = propTypes;
55
56export default Card;
57
\No newline at end of file