1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15 |
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
19 |
|
20 | var _clsx = _interopRequireDefault(require("clsx"));
|
21 |
|
22 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
23 |
|
24 | var _utils = require("@material-ui/utils");
|
25 |
|
26 | var styles = {
|
27 |
|
28 | root: {
|
29 | display: 'block',
|
30 | backgroundSize: 'cover',
|
31 | backgroundRepeat: 'no-repeat',
|
32 | backgroundPosition: 'center'
|
33 | },
|
34 |
|
35 |
|
36 | media: {
|
37 | width: '100%'
|
38 | },
|
39 |
|
40 |
|
41 | img: {
|
42 |
|
43 | objectFit: 'cover'
|
44 | }
|
45 | };
|
46 | exports.styles = styles;
|
47 | var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
|
48 | var CardMedia = 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 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 | });
|
69 | process.env.NODE_ENV !== "production" ? CardMedia.propTypes = {
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | |
76 |
|
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 |
|
88 |
|
89 |
|
90 | classes: _propTypes.default.object,
|
91 |
|
92 | |
93 |
|
94 |
|
95 | className: _propTypes.default.string,
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 | component: _propTypes.default
|
102 |
|
103 | .elementType,
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | image: _propTypes.default.string,
|
111 |
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | src: _propTypes.default.string,
|
118 |
|
119 | |
120 |
|
121 |
|
122 | style: _propTypes.default.object
|
123 | } : void 0;
|
124 |
|
125 | var _default = (0, _withStyles.default)(styles, {
|
126 | name: 'MuiCardMedia'
|
127 | })(CardMedia);
|
128 |
|
129 | exports.default = _default; |
\ | No newline at end of file |