1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import chainPropTypes from '@mui/utils/chainPropTypes';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import { styled } from "../zero-styled/index.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import { getCardMediaUtilityClass } from "./cardMediaClasses.js";
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | const useUtilityClasses = ownerState => {
|
13 | const {
|
14 | classes,
|
15 | isMediaComponent,
|
16 | isImageComponent
|
17 | } = ownerState;
|
18 | const slots = {
|
19 | root: ['root', isMediaComponent && 'media', isImageComponent && 'img']
|
20 | };
|
21 | return composeClasses(slots, getCardMediaUtilityClass, classes);
|
22 | };
|
23 | const CardMediaRoot = styled('div', {
|
24 | name: 'MuiCardMedia',
|
25 | slot: 'Root',
|
26 | overridesResolver: (props, styles) => {
|
27 | const {
|
28 | ownerState
|
29 | } = props;
|
30 | const {
|
31 | isMediaComponent,
|
32 | isImageComponent
|
33 | } = ownerState;
|
34 | return [styles.root, isMediaComponent && styles.media, isImageComponent && styles.img];
|
35 | }
|
36 | })({
|
37 | display: 'block',
|
38 | backgroundSize: 'cover',
|
39 | backgroundRepeat: 'no-repeat',
|
40 | backgroundPosition: 'center',
|
41 | variants: [{
|
42 | props: {
|
43 | isMediaComponent: true
|
44 | },
|
45 | style: {
|
46 | width: '100%'
|
47 | }
|
48 | }, {
|
49 | props: {
|
50 | isImageComponent: true
|
51 | },
|
52 | style: {
|
53 | objectFit: 'cover'
|
54 | }
|
55 | }]
|
56 | });
|
57 | const MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
|
58 | const IMAGE_COMPONENTS = ['picture', 'img'];
|
59 | const CardMedia = React.forwardRef(function CardMedia(inProps, ref) {
|
60 | const props = useDefaultProps({
|
61 | props: inProps,
|
62 | name: 'MuiCardMedia'
|
63 | });
|
64 | const {
|
65 | children,
|
66 | className,
|
67 | component = 'div',
|
68 | image,
|
69 | src,
|
70 | style,
|
71 | ...other
|
72 | } = props;
|
73 | const isMediaComponent = MEDIA_COMPONENTS.includes(component);
|
74 | const composedStyle = !isMediaComponent && image ? {
|
75 | backgroundImage: `url("${image}")`,
|
76 | ...style
|
77 | } : style;
|
78 | const ownerState = {
|
79 | ...props,
|
80 | component,
|
81 | isMediaComponent,
|
82 | isImageComponent: IMAGE_COMPONENTS.includes(component)
|
83 | };
|
84 | const classes = useUtilityClasses(ownerState);
|
85 | return _jsx(CardMediaRoot, {
|
86 | className: clsx(classes.root, className),
|
87 | as: component,
|
88 | role: !isMediaComponent && image ? 'img' : undefined,
|
89 | ref: ref,
|
90 | style: composedStyle,
|
91 | ownerState: ownerState,
|
92 | src: isMediaComponent ? image || src : undefined,
|
93 | ...other,
|
94 | children: children
|
95 | });
|
96 | });
|
97 | process.env.NODE_ENV !== "production" ? CardMedia.propTypes = {
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | |
103 |
|
104 |
|
105 | children: chainPropTypes(PropTypes.node, props => {
|
106 | if (!props.children && !props.image && !props.src && !props.component) {
|
107 | return new Error('MUI: Either `children`, `image`, `src` or `component` prop must be specified.');
|
108 | }
|
109 | return null;
|
110 | }),
|
111 | |
112 |
|
113 |
|
114 | classes: PropTypes.object,
|
115 | |
116 |
|
117 |
|
118 | className: PropTypes.string,
|
119 | |
120 |
|
121 |
|
122 |
|
123 | component: PropTypes.elementType,
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 | image: PropTypes.string,
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 | src: PropTypes.string,
|
136 | |
137 |
|
138 |
|
139 | style: PropTypes.object,
|
140 | |
141 |
|
142 |
|
143 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
144 | } : void 0;
|
145 | export default CardMedia; |
\ | No newline at end of file |