1 | 'use client';
|
2 |
|
3 | import composeClasses from '@mui/utils/composeClasses';
|
4 | import integerPropType from '@mui/utils/integerPropType';
|
5 | import clsx from 'clsx';
|
6 | import PropTypes from 'prop-types';
|
7 | import * as React from 'react';
|
8 | import { isFragment } from 'react-is';
|
9 | import ImageListContext from "../ImageList/ImageListContext.js";
|
10 | import { styled } from "../zero-styled/index.js";
|
11 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
12 | import isMuiElement from "../utils/isMuiElement.js";
|
13 | import imageListItemClasses, { getImageListItemUtilityClass } from "./imageListItemClasses.js";
|
14 | import { jsx as _jsx } from "react/jsx-runtime";
|
15 | const useUtilityClasses = ownerState => {
|
16 | const {
|
17 | classes,
|
18 | variant
|
19 | } = ownerState;
|
20 | const slots = {
|
21 | root: ['root', variant],
|
22 | img: ['img']
|
23 | };
|
24 | return composeClasses(slots, getImageListItemUtilityClass, classes);
|
25 | };
|
26 | const ImageListItemRoot = styled('li', {
|
27 | name: 'MuiImageListItem',
|
28 | slot: 'Root',
|
29 | overridesResolver: (props, styles) => {
|
30 | const {
|
31 | ownerState
|
32 | } = props;
|
33 | return [{
|
34 | [`& .${imageListItemClasses.img}`]: styles.img
|
35 | }, styles.root, styles[ownerState.variant]];
|
36 | }
|
37 | })({
|
38 | display: 'block',
|
39 | position: 'relative',
|
40 | [`& .${imageListItemClasses.img}`]: {
|
41 | objectFit: 'cover',
|
42 | width: '100%',
|
43 | height: '100%',
|
44 | display: 'block'
|
45 | },
|
46 | variants: [{
|
47 | props: {
|
48 | variant: 'standard'
|
49 | },
|
50 | style: {
|
51 |
|
52 | display: 'flex',
|
53 | flexDirection: 'column'
|
54 | }
|
55 | }, {
|
56 | props: {
|
57 | variant: 'woven'
|
58 | },
|
59 | style: {
|
60 | height: '100%',
|
61 | alignSelf: 'center',
|
62 | '&:nth-of-type(even)': {
|
63 | height: '70%'
|
64 | }
|
65 | }
|
66 | }, {
|
67 | props: {
|
68 | variant: 'standard'
|
69 | },
|
70 | style: {
|
71 | [`& .${imageListItemClasses.img}`]: {
|
72 | height: 'auto',
|
73 | flexGrow: 1
|
74 | }
|
75 | }
|
76 | }]
|
77 | });
|
78 | const ImageListItem = React.forwardRef(function ImageListItem(inProps, ref) {
|
79 | const props = useDefaultProps({
|
80 | props: inProps,
|
81 | name: 'MuiImageListItem'
|
82 | });
|
83 |
|
84 |
|
85 | const {
|
86 | children,
|
87 | className,
|
88 | cols = 1,
|
89 | component = 'li',
|
90 | rows = 1,
|
91 | style,
|
92 | ...other
|
93 | } = props;
|
94 | const {
|
95 | rowHeight = 'auto',
|
96 | gap,
|
97 | variant
|
98 | } = React.useContext(ImageListContext);
|
99 | let height = 'auto';
|
100 | if (variant === 'woven') {
|
101 | height = undefined;
|
102 | } else if (rowHeight !== 'auto') {
|
103 | height = rowHeight * rows + gap * (rows - 1);
|
104 | }
|
105 | const ownerState = {
|
106 | ...props,
|
107 | cols,
|
108 | component,
|
109 | gap,
|
110 | rowHeight,
|
111 | rows,
|
112 | variant
|
113 | };
|
114 | const classes = useUtilityClasses(ownerState);
|
115 | return _jsx(ImageListItemRoot, {
|
116 | as: component,
|
117 | className: clsx(classes.root, classes[variant], className),
|
118 | ref: ref,
|
119 | style: {
|
120 | height,
|
121 | gridColumnEnd: variant !== 'masonry' ? `span ${cols}` : undefined,
|
122 | gridRowEnd: variant !== 'masonry' ? `span ${rows}` : undefined,
|
123 | marginBottom: variant === 'masonry' ? gap : undefined,
|
124 | breakInside: variant === 'masonry' ? 'avoid' : undefined,
|
125 | ...style
|
126 | },
|
127 | ownerState: ownerState,
|
128 | ...other,
|
129 | children: React.Children.map(children, child => {
|
130 | if (! React.isValidElement(child)) {
|
131 | return null;
|
132 | }
|
133 | if (process.env.NODE_ENV !== 'production') {
|
134 | if (isFragment(child)) {
|
135 | console.error(["MUI: The ImageListItem component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
|
136 | }
|
137 | }
|
138 | if (child.type === 'img' || isMuiElement(child, ['Image'])) {
|
139 | return React.cloneElement(child, {
|
140 | className: clsx(classes.img, child.props.className)
|
141 | });
|
142 | }
|
143 | return child;
|
144 | })
|
145 | });
|
146 | });
|
147 | process.env.NODE_ENV !== "production" ? ImageListItem.propTypes = {
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | |
153 |
|
154 |
|
155 | children: PropTypes.node,
|
156 | |
157 |
|
158 |
|
159 | classes: PropTypes.object,
|
160 | |
161 |
|
162 |
|
163 | className: PropTypes.string,
|
164 | |
165 |
|
166 |
|
167 |
|
168 | cols: integerPropType,
|
169 | |
170 |
|
171 |
|
172 |
|
173 | component: PropTypes.elementType,
|
174 | |
175 |
|
176 |
|
177 |
|
178 | rows: integerPropType,
|
179 | |
180 |
|
181 |
|
182 | style: PropTypes.object,
|
183 | |
184 |
|
185 |
|
186 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
187 | } : void 0;
|
188 | export default ImageListItem; |
\ | No newline at end of file |