UNPKG

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