UNPKG

2.44 kBJavaScriptView Raw
1var _excluded = ["className", "cssModule", "top", "bottom", "tag"];
2function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5import React from 'react';
6import PropTypes from 'prop-types';
7import classNames from 'classnames';
8import { mapToCssModules, tagPropType } from './utils';
9var propTypes = {
10 /** Add `bottom` prop if image is at bottom of card */
11 bottom: PropTypes.bool,
12 /** Add custom class */
13 className: PropTypes.string,
14 /** Change existing className with a new className */
15 cssModule: PropTypes.object,
16 /** Set a custom element for this component */
17 tag: tagPropType,
18 /** Add `top` prop if image is at top of card */
19 top: PropTypes.bool
20};
21function CardImg(props) {
22 var className = props.className,
23 cssModule = props.cssModule,
24 top = props.top,
25 bottom = props.bottom,
26 _props$tag = props.tag,
27 Tag = _props$tag === void 0 ? 'img' : _props$tag,
28 attributes = _objectWithoutProperties(props, _excluded);
29 var cardImgClassName = 'card-img';
30 if (top) {
31 cardImgClassName = 'card-img-top';
32 }
33 if (bottom) {
34 cardImgClassName = 'card-img-bottom';
35 }
36 var classes = mapToCssModules(classNames(className, cardImgClassName), cssModule);
37 return /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
38 className: classes
39 }));
40}
41CardImg.propTypes = propTypes;
42export default CardImg;
\No newline at end of file