UNPKG

5.18 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _extends from "@babel/runtime/helpers/esm/extends";
5import * as React from 'react';
6import PropTypes from 'prop-types';
7import clsx from 'clsx';
8import chainPropTypes from '@mui/utils/chainPropTypes';
9import composeClasses from '@mui/utils/composeClasses';
10import { useDefaultProps } from '../DefaultPropsProvider';
11import styled from '../styles/styled';
12import { getCardMediaUtilityClass } from './cardMediaClasses';
13import { jsx as _jsx } from "react/jsx-runtime";
14var useUtilityClasses = function useUtilityClasses(ownerState) {
15 var classes = ownerState.classes,
16 isMediaComponent = ownerState.isMediaComponent,
17 isImageComponent = ownerState.isImageComponent;
18 var slots = {
19 root: ['root', isMediaComponent && 'media', isImageComponent && 'img']
20 };
21 return composeClasses(slots, getCardMediaUtilityClass, classes);
22};
23var CardMediaRoot = styled('div', {
24 name: 'MuiCardMedia',
25 slot: 'Root',
26 overridesResolver: function overridesResolver(props, styles) {
27 var ownerState = props.ownerState;
28 var isMediaComponent = ownerState.isMediaComponent,
29 isImageComponent = ownerState.isImageComponent;
30 return [styles.root, isMediaComponent && styles.media, isImageComponent && styles.img];
31 }
32})(function (_ref) {
33 var ownerState = _ref.ownerState;
34 return _extends({
35 display: 'block',
36 backgroundSize: 'cover',
37 backgroundRepeat: 'no-repeat',
38 backgroundPosition: 'center'
39 }, ownerState.isMediaComponent && {
40 width: '100%'
41 }, ownerState.isImageComponent && {
42 // ⚠️ object-fit is not supported by IE11.
43 objectFit: 'cover'
44 });
45});
46var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
47var IMAGE_COMPONENTS = ['picture', 'img'];
48var CardMedia = /*#__PURE__*/React.forwardRef(function CardMedia(inProps, ref) {
49 var props = useDefaultProps({
50 props: inProps,
51 name: 'MuiCardMedia'
52 });
53 var children = props.children,
54 className = props.className,
55 _props$component = props.component,
56 component = _props$component === void 0 ? 'div' : _props$component,
57 image = props.image,
58 src = props.src,
59 style = props.style,
60 other = _objectWithoutProperties(props, ["children", "className", "component", "image", "src", "style"]);
61 var isMediaComponent = MEDIA_COMPONENTS.indexOf(component) !== -1;
62 var composedStyle = !isMediaComponent && image ? _extends({
63 backgroundImage: "url(\"".concat(image, "\")")
64 }, style) : style;
65 var ownerState = _extends({}, props, {
66 component: component,
67 isMediaComponent: isMediaComponent,
68 isImageComponent: IMAGE_COMPONENTS.indexOf(component) !== -1
69 });
70 var classes = useUtilityClasses(ownerState);
71 return /*#__PURE__*/_jsx(CardMediaRoot, _extends({
72 className: clsx(classes.root, className),
73 as: component,
74 role: !isMediaComponent && image ? 'img' : undefined,
75 ref: ref,
76 style: composedStyle,
77 ownerState: ownerState,
78 src: isMediaComponent ? image || src : undefined
79 }, other, {
80 children: children
81 }));
82});
83process.env.NODE_ENV !== "production" ? CardMedia.propTypes /* remove-proptypes */ = {
84 // ┌────────────────────────────── Warning ──────────────────────────────┐
85 // │ These PropTypes are generated from the TypeScript type definitions. │
86 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
87 // └─────────────────────────────────────────────────────────────────────┘
88 /**
89 * The content of the component.
90 */
91 children: chainPropTypes(PropTypes.node, function (props) {
92 if (!props.children && !props.image && !props.src && !props.component) {
93 return new Error('MUI: Either `children`, `image`, `src` or `component` prop must be specified.');
94 }
95 return null;
96 }),
97 /**
98 * Override or extend the styles applied to the component.
99 */
100 classes: PropTypes.object,
101 /**
102 * @ignore
103 */
104 className: PropTypes.string,
105 /**
106 * The component used for the root node.
107 * Either a string to use a HTML element or a component.
108 */
109 component: PropTypes.elementType,
110 /**
111 * Image to be displayed as a background image.
112 * Either `image` or `src` prop must be specified.
113 * Note that caller must specify height otherwise the image will not be visible.
114 */
115 image: PropTypes.string,
116 /**
117 * An alias for `image` property.
118 * Available only with media components.
119 * Media components: `video`, `audio`, `picture`, `iframe`, `img`.
120 */
121 src: PropTypes.string,
122 /**
123 * @ignore
124 */
125 style: PropTypes.object,
126 /**
127 * The system prop that allows defining system overrides as well as additional CSS styles.
128 */
129 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
130} : void 0;
131export default CardMedia;
\No newline at end of file