UNPKG

4.23 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
23
24var _utils = require("@material-ui/utils");
25
26var styles = {
27 /* Styles applied to the root element. */
28 root: {
29 display: 'block',
30 backgroundSize: 'cover',
31 backgroundRepeat: 'no-repeat',
32 backgroundPosition: 'center'
33 },
34
35 /* Styles applied to the root element if `component="video, audio, picture, iframe, or img"`. */
36 media: {
37 width: '100%'
38 },
39
40 /* Styles applied to the root element if `component="picture or img"`. */
41 img: {
42 // ⚠️ object-fit is not supported by IE 11.
43 objectFit: 'cover'
44 }
45};
46exports.styles = styles;
47var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
48var CardMedia = /*#__PURE__*/React.forwardRef(function CardMedia(props, ref) {
49 var children = props.children,
50 classes = props.classes,
51 className = props.className,
52 _props$component = props.component,
53 Component = _props$component === void 0 ? 'div' : _props$component,
54 image = props.image,
55 src = props.src,
56 style = props.style,
57 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "component", "image", "src", "style"]);
58 var isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
59 var composedStyle = !isMediaComponent && image ? (0, _extends2.default)({
60 backgroundImage: "url(\"".concat(image, "\")")
61 }, style) : style;
62 return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
63 className: (0, _clsx.default)(classes.root, className, isMediaComponent && classes.media, "picture img".indexOf(Component) !== -1 && classes.img),
64 ref: ref,
65 style: composedStyle,
66 src: isMediaComponent ? image || src : undefined
67 }, other), children);
68});
69process.env.NODE_ENV !== "production" ? CardMedia.propTypes = {
70 // ----------------------------- Warning --------------------------------
71 // | These PropTypes are generated from the TypeScript type definitions |
72 // | To update them edit the d.ts file and run "yarn proptypes" |
73 // ----------------------------------------------------------------------
74
75 /**
76 * The content of the component.
77 */
78 children: (0, _utils.chainPropTypes)(_propTypes.default.node, function (props) {
79 if (!props.children && !props.image && !props.src && !props.component) {
80 return new Error('Material-UI: Either `children`, `image`, `src` or `component` prop must be specified.');
81 }
82
83 return null;
84 }),
85
86 /**
87 * Override or extend the styles applied to the component.
88 * See [CSS API](#css) below for more details.
89 */
90 classes: _propTypes.default.object,
91
92 /**
93 * @ignore
94 */
95 className: _propTypes.default.string,
96
97 /**
98 * The component used for the root node.
99 * Either a string to use a HTML element or a component.
100 */
101 component: _propTypes.default
102 /* @typescript-to-proptypes-ignore */
103 .elementType,
104
105 /**
106 * Image to be displayed as a background image.
107 * Either `image` or `src` prop must be specified.
108 * Note that caller must specify height otherwise the image will not be visible.
109 */
110 image: _propTypes.default.string,
111
112 /**
113 * An alias for `image` property.
114 * Available only with media components.
115 * Media components: `video`, `audio`, `picture`, `iframe`, `img`.
116 */
117 src: _propTypes.default.string,
118
119 /**
120 * @ignore
121 */
122 style: _propTypes.default.object
123} : void 0;
124
125var _default = (0, _withStyles.default)(styles, {
126 name: 'MuiCardMedia'
127})(CardMedia);
128
129exports.default = _default;
\No newline at end of file