1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import withStyles from '../styles/withStyles';
|
7 | import { chainPropTypes } from '@material-ui/utils';
|
8 | export const styles = {
|
9 |
|
10 | root: {
|
11 | display: 'block',
|
12 | backgroundSize: 'cover',
|
13 | backgroundRepeat: 'no-repeat',
|
14 | backgroundPosition: 'center'
|
15 | },
|
16 |
|
17 |
|
18 | media: {
|
19 | width: '100%'
|
20 | },
|
21 |
|
22 |
|
23 | img: {
|
24 |
|
25 | objectFit: 'cover'
|
26 | }
|
27 | };
|
28 | const MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
|
29 | const CardMedia = React.forwardRef(function CardMedia(props, ref) {
|
30 | const {
|
31 | children,
|
32 | classes,
|
33 | className,
|
34 | component: Component = 'div',
|
35 | image,
|
36 | src,
|
37 | style
|
38 | } = props,
|
39 | other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "component", "image", "src", "style"]);
|
40 |
|
41 | const isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
|
42 | const composedStyle = !isMediaComponent && image ? _extends({
|
43 | backgroundImage: `url("${image}")`
|
44 | }, style) : style;
|
45 | return React.createElement(Component, _extends({
|
46 | className: clsx(classes.root, className, isMediaComponent && classes.media, "picture img".indexOf(Component) !== -1 && classes.img),
|
47 | ref: ref,
|
48 | style: composedStyle,
|
49 | src: isMediaComponent ? image || src : undefined
|
50 | }, other), children);
|
51 | });
|
52 | process.env.NODE_ENV !== "production" ? CardMedia.propTypes = {
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | |
59 |
|
60 |
|
61 | children: chainPropTypes(PropTypes.node, props => {
|
62 | if (!props.children && !props.image && !props.src && !props.component) {
|
63 | return new Error('Material-UI: Either `children`, `image`, `src` or `component` prop must be specified.');
|
64 | }
|
65 |
|
66 | return null;
|
67 | }),
|
68 |
|
69 | |
70 |
|
71 |
|
72 |
|
73 | classes: PropTypes.object,
|
74 |
|
75 | |
76 |
|
77 |
|
78 | className: PropTypes.string,
|
79 |
|
80 | |
81 |
|
82 |
|
83 |
|
84 | component: PropTypes
|
85 |
|
86 | .elementType,
|
87 |
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 | image: PropTypes.string,
|
94 |
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 | src: PropTypes.string,
|
101 |
|
102 | |
103 |
|
104 |
|
105 | style: PropTypes.object
|
106 | } : void 0;
|
107 | export default withStyles(styles, {
|
108 | name: 'MuiCardMedia'
|
109 | })(CardMedia); |
\ | No newline at end of file |