UNPKG

5.96 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _extends from "@babel/runtime/helpers/esm/extends";
3import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
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
17var 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
27var 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 // For titlebar under list item
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});
59var ImageListItem = /*#__PURE__*/React.forwardRef(function ImageListItem(inProps, ref) {
60 var props = useThemeProps({
61 props: inProps,
62 name: 'MuiImageListItem'
63 }); // TODO: - Use jsdoc @default?: "cols rows default values are for docs only"
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 /*#__PURE__*/_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 (! /*#__PURE__*/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 /*#__PURE__*/React.cloneElement(child, {
125 className: clsx(classes.img, child.props.className)
126 });
127 }
128
129 return child;
130 })
131 }));
132});
133process.env.NODE_ENV !== "production" ? ImageListItem.propTypes
134/* remove-proptypes */
135= {
136 // ----------------------------- Warning --------------------------------
137 // | These PropTypes are generated from the TypeScript type definitions |
138 // | To update them edit the d.ts file and run "yarn proptypes" |
139 // ----------------------------------------------------------------------
140
141 /**
142 * The content of the component, normally an `<img>`.
143 */
144 children: PropTypes.node,
145
146 /**
147 * Override or extend the styles applied to the component.
148 */
149 classes: PropTypes.object,
150
151 /**
152 * @ignore
153 */
154 className: PropTypes.string,
155
156 /**
157 * Width of the item in number of grid columns.
158 * @default 1
159 */
160 cols: integerPropType,
161
162 /**
163 * The component used for the root node.
164 * Either a string to use a HTML element or a component.
165 */
166 component: PropTypes.elementType,
167
168 /**
169 * Height of the item in number of grid rows.
170 * @default 1
171 */
172 rows: integerPropType,
173
174 /**
175 * @ignore
176 */
177 style: PropTypes.object,
178
179 /**
180 * The system prop that allows defining system overrides as well as additional CSS styles.
181 */
182 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
183} : void 0;
184export default ImageListItem;
\No newline at end of file