UNPKG

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