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