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