Skip to content

Commit c090f3d

Browse files
committed
[ImageList] Migrate to emotion
1 parent 2335e81 commit c090f3d

File tree

9 files changed

+121
-34
lines changed

9 files changed

+121
-34
lines changed

docs/pages/api-docs/image-list.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"type": { "name": "union", "description": "'auto'<br>&#124;&nbsp;number" },
1010
"default": "'auto'"
1111
},
12+
"sx": { "type": { "name": "object" } },
1213
"variant": {
1314
"type": {
1415
"name": "union",
@@ -28,6 +29,6 @@
2829
"filename": "/packages/material-ui/src/ImageList/ImageList.js",
2930
"inheritance": null,
3031
"demos": "<ul><li><a href=\"/components/image-list/\">Image List</a></li></ul>",
31-
"styledComponent": false,
32+
"styledComponent": true,
3233
"cssComponent": false
3334
}

docs/translations/api-docs/image-list/image-list.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
88
"gap": "The gap between items in px.",
99
"rowHeight": "The height of one row in px.",
10+
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/basics/#the-sx-prop\">`sx` page</a> for more details.",
1011
"variant": "The variant to use."
1112
},
1213
"classDescriptions": {

packages/material-ui/src/ImageList/ImageList.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import * as React from 'react';
1+
import { SxProps } from '@material-ui/system';
22
import { OverridableStringUnion } from '@material-ui/types';
3+
import * as React from 'react';
4+
import { Theme } from '..';
35
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
46

57
export interface ImageListPropsVariantOverrides {}
@@ -40,6 +42,10 @@ export interface ImageListTypeMap<P = {}, D extends React.ElementType = 'ul'> {
4042
* @default 'auto'
4143
*/
4244
rowHeight?: number | 'auto';
45+
/**
46+
* The system prop that allows defining system overrides as well as additional CSS styles.
47+
*/
48+
sx?: SxProps<Theme>;
4349
/**
4450
* The variant to use.
4551
* @default 'standard'

packages/material-ui/src/ImageList/ImageList.js

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,75 @@
1-
import * as React from 'react';
2-
import PropTypes from 'prop-types';
1+
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
2+
import { deepmerge } from '@material-ui/utils';
33
import clsx from 'clsx';
4-
import withStyles from '../styles/withStyles';
4+
import PropTypes from 'prop-types';
5+
import * as React from 'react';
6+
import experimentalStyled from '../styles/experimentalStyled';
7+
import useThemeProps from '../styles/useThemeProps';
8+
import { getImageListUtilityClass } from './imageListClasses';
59
import ImageListContext from './ImageListContext';
610

7-
export const styles = {
11+
const overridesResolver = (props, styles) => {
12+
const { styleProps } = props;
13+
14+
return deepmerge(styles.root || {}, {
15+
...styles[styleProps.variant],
16+
});
17+
};
18+
19+
const useUtilityClasses = (styleProps) => {
20+
const { classes, variant } = styleProps;
21+
22+
const slots = {
23+
root: ['root', variant],
24+
};
25+
26+
return composeClasses(slots, getImageListUtilityClass, classes);
27+
};
28+
29+
const ImageListRoot = experimentalStyled(
30+
'ul',
31+
{},
32+
{
33+
name: 'MuiImageList',
34+
slot: 'Root',
35+
overridesResolver,
36+
},
37+
)(({ theme, styleProps }) => {
838
/* Styles applied to the root element. */
9-
root: {
39+
return {
1040
display: 'grid',
1141
overflowY: 'auto',
1242
listStyle: 'none',
1343
padding: 0,
1444
WebkitOverflowScrolling: 'touch', // Add iOS momentum scrolling.
15-
},
16-
/* Styles applied to the root element if `variant="masonry"`. */
17-
masonry: {
18-
display: 'block',
19-
},
20-
/* Styles applied to the root element if `variant="quilted"`. */
21-
quilted: {},
22-
/* Styles applied to the root element if `variant="standard"`. */
23-
standard: {},
24-
/* Styles applied to the root element if `variant="woven"`. */
25-
woven: {},
26-
};
45+
/* Styles applied to the root element if `variant="masonry"`. */
46+
...(styleProps.variant === 'masonry' && {
47+
position: 'absolute',
48+
zIndex: theme.zIndex.appBar,
49+
top: 0,
50+
left: 'auto',
51+
right: 0,
52+
}),
53+
/* Styles applied to the root element if `variant="quilted"`. */
54+
...(styleProps.variant === 'quilted' && {}),
55+
/* Styles applied to the root element if `variant="standard"`. */
56+
...(styleProps.variant === 'standard' && {}),
57+
/* Styles applied to the root element if `variant="woven"`. */
58+
...(styleProps.variant === 'woven' && {}),
59+
};
60+
});
61+
62+
const ImageList = React.forwardRef(function ImageList(inProps, ref) {
63+
const props = useThemeProps({
64+
props: inProps,
65+
name: 'MuiImageList',
66+
});
2767

28-
const ImageList = React.forwardRef(function ImageList(props, ref) {
2968
const {
3069
children,
31-
classes,
3270
className,
3371
cols = 2,
34-
component: Component = 'ul',
72+
component = 'ul',
3573
rowHeight = 'auto',
3674
gap = 4,
3775
style: styleProp,
@@ -64,15 +102,21 @@ const ImageList = React.forwardRef(function ImageList(props, ref) {
64102
? { columnCount: cols, columnGap: gap, ...styleProp }
65103
: { gridTemplateColumns: `repeat(${cols}, 1fr)`, gap, ...styleProp };
66104

105+
const styleProps = { ...props, component, variant };
106+
107+
const classes = useUtilityClasses(styleProps);
108+
67109
return (
68-
<Component
110+
<ImageListRoot
111+
as={component}
69112
className={clsx(classes.root, classes[variant], className)}
70113
ref={ref}
71114
style={style}
115+
styleProps={styleProps}
72116
{...other}
73117
>
74118
<ImageListContext.Provider value={contextValue}>{children}</ImageListContext.Provider>
75-
</Component>
119+
</ImageListRoot>
76120
);
77121
});
78122

@@ -117,6 +161,10 @@ ImageList.propTypes = {
117161
* @ignore
118162
*/
119163
style: PropTypes.object,
164+
/**
165+
* The system prop that allows defining system overrides as well as additional CSS styles.
166+
*/
167+
sx: PropTypes.object,
120168
/**
121169
* The variant to use.
122170
* @default 'standard'
@@ -127,4 +175,4 @@ ImageList.propTypes = {
127175
]),
128176
};
129177

130-
export default withStyles(styles, { name: 'MuiImageList' })(ImageList);
178+
export default ImageList;

packages/material-ui/src/ImageList/ImageList.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import * as React from 'react';
21
import { expect } from 'chai';
3-
import { createClientRender, getClasses, createMount, describeConformance } from 'test/utils';
2+
import * as React from 'react';
3+
import { createClientRender, createMount, describeConformanceV5 } from 'test/utils';
44
import ImageList from './ImageList';
5+
import classes from './imageListClasses';
56

67
const itemsData = [
78
{
@@ -17,15 +18,10 @@ const itemsData = [
1718
];
1819

1920
describe('<ImageList />', () => {
20-
let classes;
2121
const mount = createMount();
2222
const render = createClientRender();
2323

24-
before(() => {
25-
classes = getClasses(<ImageList />);
26-
});
27-
28-
describeConformance(
24+
describeConformanceV5(
2925
<ImageList>
3026
<div />
3127
</ImageList>,
@@ -35,6 +31,9 @@ describe('<ImageList />', () => {
3531
mount,
3632
refInstanceof: window.HTMLUListElement,
3733
testComponentPropWith: 'li',
34+
muiName: 'MuiImageList',
35+
testVariantProps: { variant: 'masonry' },
36+
skip: ['componentProp', 'componentsProp'],
3837
}),
3938
);
4039

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface ImageListClasses {
2+
root: string;
3+
masonry: string;
4+
quilted: string;
5+
standard: string;
6+
woven: string;
7+
}
8+
9+
declare const imageListClasses: ImageListClasses;
10+
11+
export function getImageListUtilityClass(slot: string): string;
12+
13+
export default imageListClasses;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled';
2+
3+
export function getImageListUtilityClass(slot) {
4+
return generateUtilityClass('MuiImageList', slot);
5+
}
6+
7+
const imageListClasses = generateUtilityClasses('MuiImageList', [
8+
'root',
9+
'masonry',
10+
'quilted',
11+
'standard',
12+
'woven',
13+
]);
14+
15+
export default imageListClasses;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
export { default } from './ImageList';
21
export * from './ImageList';
2+
export { default } from './ImageList';
3+
export * from './imageListClasses';
4+
export { default as imageListClasses } from './imageListClasses';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export { default } from './ImageList';
2+
export * from './imageListClasses';
3+
export { default as imageListClasses } from './imageListClasses';

0 commit comments

Comments
 (0)