UNPKG

5.46 kBJavaScriptView Raw
1'use client';
2
3import composeClasses from '@mui/utils/composeClasses';
4import integerPropType from '@mui/utils/integerPropType';
5import clsx from 'clsx';
6import PropTypes from 'prop-types';
7import * as React from 'react';
8import { isFragment } from 'react-is';
9import ImageListContext from "../ImageList/ImageListContext.js";
10import { styled } from "../zero-styled/index.js";
11import { useDefaultProps } from "../DefaultPropsProvider/index.js";
12import isMuiElement from "../utils/isMuiElement.js";
13import imageListItemClasses, { getImageListItemUtilityClass } from "./imageListItemClasses.js";
14import { jsx as _jsx } from "react/jsx-runtime";
15const 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};
26const 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 // For titlebar under list item
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});
78const ImageListItem = /*#__PURE__*/React.forwardRef(function ImageListItem(inProps, ref) {
79 const props = useDefaultProps({
80 props: inProps,
81 name: 'MuiImageListItem'
82 });
83
84 // TODO: - Use jsdoc @default?: "cols rows default values are for docs only"
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 /*#__PURE__*/_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 (! /*#__PURE__*/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 /*#__PURE__*/React.cloneElement(child, {
140 className: clsx(classes.img, child.props.className)
141 });
142 }
143 return child;
144 })
145 });
146});
147process.env.NODE_ENV !== "production" ? ImageListItem.propTypes /* remove-proptypes */ = {
148 // ┌────────────────────────────── Warning ──────────────────────────────┐
149 // │ These PropTypes are generated from the TypeScript type definitions. │
150 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
151 // └─────────────────────────────────────────────────────────────────────┘
152 /**
153 * The content of the component, normally an `<img>`.
154 */
155 children: PropTypes.node,
156 /**
157 * Override or extend the styles applied to the component.
158 */
159 classes: PropTypes.object,
160 /**
161 * @ignore
162 */
163 className: PropTypes.string,
164 /**
165 * Width of the item in number of grid columns.
166 * @default 1
167 */
168 cols: integerPropType,
169 /**
170 * The component used for the root node.
171 * Either a string to use a HTML element or a component.
172 */
173 component: PropTypes.elementType,
174 /**
175 * Height of the item in number of grid rows.
176 * @default 1
177 */
178 rows: integerPropType,
179 /**
180 * @ignore
181 */
182 style: PropTypes.object,
183 /**
184 * The system prop that allows defining system overrides as well as additional CSS styles.
185 */
186 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
187} : void 0;
188export default ImageListItem;
\No newline at end of file