UNPKG

4.81 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2import _extends from "@babel/runtime/helpers/esm/extends";
3const _excluded = ["children", "className", "cols", "component", "rowHeight", "gap", "style", "variant"];
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 styled from '../styles/styled';
10import useThemeProps from '../styles/useThemeProps';
11import { getImageListUtilityClass } from './imageListClasses';
12import ImageListContext from './ImageListContext';
13import { jsx as _jsx } from "react/jsx-runtime";
14
15const useUtilityClasses = ownerState => {
16 const {
17 classes,
18 variant
19 } = ownerState;
20 const slots = {
21 root: ['root', variant]
22 };
23 return composeClasses(slots, getImageListUtilityClass, classes);
24};
25
26const ImageListRoot = styled('ul', {
27 name: 'MuiImageList',
28 slot: 'Root',
29 overridesResolver: (props, styles) => {
30 const {
31 ownerState
32 } = props;
33 return [styles.root, styles[ownerState.variant]];
34 }
35})(({
36 ownerState
37}) => {
38 return _extends({
39 display: 'grid',
40 overflowY: 'auto',
41 listStyle: 'none',
42 padding: 0,
43 // Add iOS momentum scrolling for iOS < 13.0
44 WebkitOverflowScrolling: 'touch'
45 }, ownerState.variant === 'masonry' && {
46 display: 'block'
47 });
48});
49const ImageList = /*#__PURE__*/React.forwardRef(function ImageList(inProps, ref) {
50 const props = useThemeProps({
51 props: inProps,
52 name: 'MuiImageList'
53 });
54
55 const {
56 children,
57 className,
58 cols = 2,
59 component = 'ul',
60 rowHeight = 'auto',
61 gap = 4,
62 style: styleProp,
63 variant = 'standard'
64 } = props,
65 other = _objectWithoutPropertiesLoose(props, _excluded);
66
67 const contextValue = React.useMemo(() => ({
68 rowHeight,
69 gap,
70 variant
71 }), [rowHeight, gap, variant]);
72 React.useEffect(() => {
73 if (process.env.NODE_ENV !== 'production') {
74 // Detect Internet Explorer 8+
75 if (document !== undefined && 'objectFit' in document.documentElement.style === false) {
76 console.error(['MUI: ImageList v5+ no longer natively supports Internet Explorer.', 'Use v4 of this component instead, or polyfill CSS object-fit.'].join('\n'));
77 }
78 }
79 }, []);
80 const style = variant === 'masonry' ? _extends({
81 columnCount: cols,
82 columnGap: gap
83 }, styleProp) : _extends({
84 gridTemplateColumns: `repeat(${cols}, 1fr)`,
85 gap
86 }, styleProp);
87
88 const ownerState = _extends({}, props, {
89 component,
90 gap,
91 rowHeight,
92 variant
93 });
94
95 const classes = useUtilityClasses(ownerState);
96 return /*#__PURE__*/_jsx(ImageListRoot, _extends({
97 as: component,
98 className: clsx(classes.root, classes[variant], className),
99 ref: ref,
100 style: style,
101 ownerState: ownerState
102 }, other, {
103 children: /*#__PURE__*/_jsx(ImageListContext.Provider, {
104 value: contextValue,
105 children: children
106 })
107 }));
108});
109process.env.NODE_ENV !== "production" ? ImageList.propTypes
110/* remove-proptypes */
111= {
112 // ----------------------------- Warning --------------------------------
113 // | These PropTypes are generated from the TypeScript type definitions |
114 // | To update them edit the d.ts file and run "yarn proptypes" |
115 // ----------------------------------------------------------------------
116
117 /**
118 * The content of the component, normally `ImageListItem`s.
119 */
120 children: PropTypes
121 /* @typescript-to-proptypes-ignore */
122 .node.isRequired,
123
124 /**
125 * Override or extend the styles applied to the component.
126 */
127 classes: PropTypes.object,
128
129 /**
130 * @ignore
131 */
132 className: PropTypes.string,
133
134 /**
135 * Number of columns.
136 * @default 2
137 */
138 cols: integerPropType,
139
140 /**
141 * The component used for the root node.
142 * Either a string to use a HTML element or a component.
143 */
144 component: PropTypes.elementType,
145
146 /**
147 * The gap between items in px.
148 * @default 4
149 */
150 gap: PropTypes.number,
151
152 /**
153 * The height of one row in px.
154 * @default 'auto'
155 */
156 rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
157
158 /**
159 * @ignore
160 */
161 style: PropTypes.object,
162
163 /**
164 * The system prop that allows defining system overrides as well as additional CSS styles.
165 */
166 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
167
168 /**
169 * The variant to use.
170 * @default 'standard'
171 */
172 variant: PropTypes
173 /* @typescript-to-proptypes-ignore */
174 .oneOfType([PropTypes.oneOf(['masonry', 'quilted', 'standard', 'woven']), PropTypes.string])
175} : void 0;
176export default ImageList;
\No newline at end of file