1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import classNames from 'classnames';
|
4 | import { mapToCssModules, tagPropType } from './utils';
|
5 |
|
6 | const propTypes = {
|
7 |
|
8 | bottom: PropTypes.bool,
|
9 |
|
10 | className: PropTypes.string,
|
11 |
|
12 | cssModule: PropTypes.object,
|
13 |
|
14 | tag: tagPropType,
|
15 |
|
16 | top: PropTypes.bool,
|
17 | };
|
18 |
|
19 | function CardImg(props) {
|
20 | const {
|
21 | className,
|
22 | cssModule,
|
23 | top,
|
24 | bottom,
|
25 | tag: Tag = 'img',
|
26 | ...attributes
|
27 | } = props;
|
28 |
|
29 | let cardImgClassName = 'card-img';
|
30 | if (top) {
|
31 | cardImgClassName = 'card-img-top';
|
32 | }
|
33 | if (bottom) {
|
34 | cardImgClassName = 'card-img-bottom';
|
35 | }
|
36 |
|
37 | const classes = mapToCssModules(
|
38 | classNames(className, cardImgClassName),
|
39 | cssModule,
|
40 | );
|
41 |
|
42 | return <Tag {...attributes} className={classes} />;
|
43 | }
|
44 |
|
45 | CardImg.propTypes = propTypes;
|
46 |
|
47 | export default CardImg;
|
48 |
|
\ | No newline at end of file |