UNPKG

1.06 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 /** Add `bottom` prop if image is at bottom of card */
8 bottom: PropTypes.bool,
9 /** Add custom class */
10 className: PropTypes.string,
11 /** Change existing className with a new className */
12 cssModule: PropTypes.object,
13 /** Set a custom element for this component */
14 tag: tagPropType,
15 /** Add `top` prop if image is at top of card */
16 top: PropTypes.bool,
17};
18
19function 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
45CardImg.propTypes = propTypes;
46
47export default CardImg;
48
\No newline at end of file