@material-ui/core
Version:
React components that implement Google's Material Design.
86 lines (79 loc) • 2.84 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import warning from 'warning';
import withStyles from '../styles/withStyles';
export var styles = {
/* Styles applied to the root element. */
root: {
display: 'block',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center'
},
/* Styles applied to the root element if `component="video, audio, picture, iframe, or img"`. */
media: {
width: '100%',
// ⚠️ object-fit is not supported by IE 11.
objectFit: 'cover'
}
};
var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
var CardMedia = React.forwardRef(function CardMedia(props, ref) {
var classes = props.classes,
className = props.className,
_props$component = props.component,
Component = _props$component === void 0 ? 'div' : _props$component,
image = props.image,
src = props.src,
style = props.style,
other = _objectWithoutProperties(props, ["classes", "className", "component", "image", "src", "style"]);
process.env.NODE_ENV !== "production" ? warning('children' in other || Boolean(image || src), 'Material-UI: either `children`, `image` or `src` prop must be specified.') : void 0;
var isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
var composedStyle = !isMediaComponent && image ? _extends({
backgroundImage: "url(\"".concat(image, "\")")
}, style) : style;
return React.createElement(Component, _extends({
className: clsx(classes.root, className, isMediaComponent && classes.media),
ref: ref,
style: composedStyle,
src: isMediaComponent ? image || src : undefined
}, other));
});
process.env.NODE_ENV !== "production" ? CardMedia.propTypes = {
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Component for rendering image.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.elementType,
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image: PropTypes.string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src: PropTypes.string,
/**
* @ignore
*/
style: PropTypes.object
} : void 0;
export default withStyles(styles, {
name: 'MuiCardMedia'
})(CardMedia);