UNPKG

2.72 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _react = _interopRequireDefault(require("react"));
8var _propTypes = _interopRequireDefault(require("prop-types"));
9var _classnames = _interopRequireDefault(require("classnames"));
10var _utils = require("./utils");
11const _excluded = ["className", "cssModule", "top", "bottom", "tag"];
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13function _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); }
14function _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; }
15function _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; }
16const propTypes = {
17 /** Add `bottom` prop if image is at bottom of card */
18 bottom: _propTypes.default.bool,
19 /** Add custom class */
20 className: _propTypes.default.string,
21 /** Change existing className with a new className */
22 cssModule: _propTypes.default.object,
23 /** Set a custom element for this component */
24 tag: _utils.tagPropType,
25 /** Add `top` prop if image is at top of card */
26 top: _propTypes.default.bool
27};
28function CardImg(props) {
29 const {
30 className,
31 cssModule,
32 top,
33 bottom,
34 tag: Tag = 'img'
35 } = props,
36 attributes = _objectWithoutProperties(props, _excluded);
37 let cardImgClassName = 'card-img';
38 if (top) {
39 cardImgClassName = 'card-img-top';
40 }
41 if (bottom) {
42 cardImgClassName = 'card-img-bottom';
43 }
44 const classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, cardImgClassName), cssModule);
45 return /*#__PURE__*/_react.default.createElement(Tag, _extends({}, attributes, {
46 className: classes
47 }));
48}
49CardImg.propTypes = propTypes;
50var _default = CardImg;
51exports.default = _default;
\No newline at end of file