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