UNPKG

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