UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

129 lines (106 loc) 4.23 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.styles = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _clsx = _interopRequireDefault(require("clsx")); var _withStyles = _interopRequireDefault(require("../styles/withStyles")); var _utils = require("@material-ui/utils"); 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%' }, /* Styles applied to the root element if `component="picture or img"`. */ img: { // ⚠️ object-fit is not supported by IE 11. objectFit: 'cover' } }; exports.styles = styles; var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img']; var CardMedia = /*#__PURE__*/React.forwardRef(function CardMedia(props, ref) { var children = props.children, 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 = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "component", "image", "src", "style"]); var isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1; var composedStyle = !isMediaComponent && image ? (0, _extends2.default)({ backgroundImage: "url(\"".concat(image, "\")") }, style) : style; return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({ className: (0, _clsx.default)(classes.root, className, isMediaComponent && classes.media, "picture img".indexOf(Component) !== -1 && classes.img), ref: ref, style: composedStyle, src: isMediaComponent ? image || src : undefined }, other), children); }); process.env.NODE_ENV !== "production" ? CardMedia.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the d.ts file and run "yarn proptypes" | // ---------------------------------------------------------------------- /** * The content of the component. */ children: (0, _utils.chainPropTypes)(_propTypes.default.node, function (props) { if (!props.children && !props.image && !props.src && !props.component) { return new Error('Material-UI: Either `children`, `image`, `src` or `component` prop must be specified.'); } return null; }), /** * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ classes: _propTypes.default.object, /** * @ignore */ className: _propTypes.default.string, /** * The component used for the root node. * Either a string to use a HTML element or a component. */ component: _propTypes.default /* @typescript-to-proptypes-ignore */ .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.default.string, /** * An alias for `image` property. * Available only with media components. * Media components: `video`, `audio`, `picture`, `iframe`, `img`. */ src: _propTypes.default.string, /** * @ignore */ style: _propTypes.default.object } : void 0; var _default = (0, _withStyles.default)(styles, { name: 'MuiCardMedia' })(CardMedia); exports.default = _default;