Skip to content

Commit 2b56383

Browse files
authored
[Step] Migrate to emotion (#24678)
1 parent 5eefc9e commit 2b56383

File tree

10 files changed

+108
-39
lines changed

10 files changed

+108
-39
lines changed

docs/pages/api-docs/step.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"disabled": { "type": { "name": "bool" } },
88
"expanded": { "type": { "name": "bool" } },
99
"index": { "type": { "name": "number" } },
10-
"last": { "type": { "name": "bool" } }
10+
"last": { "type": { "name": "bool" } },
11+
"sx": { "type": { "name": "object" } }
1112
},
1213
"name": "Step",
1314
"styles": {
@@ -20,6 +21,6 @@
2021
"filename": "/packages/material-ui/src/Step/Step.js",
2122
"inheritance": null,
2223
"demos": "<ul><li><a href=\"/components/steppers/\">Steppers</a></li></ul>",
23-
"styledComponent": false,
24+
"styledComponent": true,
2425
"cssComponent": false
2526
}

docs/translations/api-docs/step/step.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"disabled": "If <code>true</code>, the step is disabled, will also disable the button if <code>StepButton</code> is a child of <code>Step</code>. Is passed to child components.",
99
"expanded": "Expand the step.",
1010
"index": "The position of the step. The prop defaults to the value inherited from the parent Stepper component.",
11-
"last": "If <code>true</code>, the Step is displayed as rendered last. The prop defaults to the value inherited from the parent Stepper component."
11+
"last": "If <code>true</code>, the Step is displayed as rendered last. The prop defaults to the value inherited from the parent Stepper component.",
12+
"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."
1213
},
1314
"classDescriptions": {
1415
"root": { "description": "Styles applied to the root element." },

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { SxProps } from '@material-ui/system';
12
import * as React from 'react';
2-
import { InternalStandardProps as StandardProps } from '..';
3+
import { InternalStandardProps as StandardProps, Theme } from '..';
34

45
export interface StepProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
56
/**
@@ -49,6 +50,10 @@ export interface StepProps extends StandardProps<React.HTMLAttributes<HTMLDivEle
4950
* The prop defaults to the value inherited from the parent Stepper component.
5051
*/
5152
last?: boolean;
53+
/**
54+
* The system prop that allows defining system overrides as well as additional CSS styles.
55+
*/
56+
sx?: SxProps<Theme>;
5257
}
5358

5459
export type StepClasskey = keyof NonNullable<StepProps['classes']>;

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

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
11
import * as React from 'react';
22
import PropTypes from 'prop-types';
33
import clsx from 'clsx';
4-
import withStyles from '../styles/withStyles';
4+
import { deepmerge } from '@material-ui/utils';
5+
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
56
import StepperContext from '../Stepper/StepperContext';
67
import StepContext from './StepContext';
8+
import useThemeProps from '../styles/useThemeProps';
9+
import experimentalStyled from '../styles/experimentalStyled';
10+
import { getStepUtilityClass } from './stepClasses';
711

8-
export const styles = {
9-
/* Styles applied to the root element. */
10-
root: {},
12+
const overridesResolver = (props, styles) => {
13+
const { styleProps } = props;
14+
15+
return deepmerge(styles.root || {}, {
16+
...styles[styleProps.orientation],
17+
...(styleProps.alternativeLabel && styles.alternativeLabel),
18+
...(styleProps.completed && styles.completed),
19+
});
20+
};
21+
22+
const useUtilityClasses = (styleProps) => {
23+
const { classes, orientation, alternativeLabel, completed } = styleProps;
24+
25+
const slots = {
26+
root: ['root', orientation, alternativeLabel && 'alternativeLabel', completed && 'completed'],
27+
};
28+
29+
return composeClasses(slots, getStepUtilityClass, classes);
30+
};
31+
32+
const StepRoot = experimentalStyled(
33+
'div',
34+
{},
35+
{
36+
name: 'MuiStep',
37+
slot: 'Root',
38+
overridesResolver,
39+
},
40+
)(({ styleProps }) => ({
1141
/* Styles applied to the root element if `orientation="horizontal"`. */
12-
horizontal: {
42+
...(styleProps.orientation === 'horizontal' && {
1343
paddingLeft: 8,
1444
paddingRight: 8,
15-
},
16-
/* Styles applied to the root element if `orientation="vertical"`. */
17-
vertical: {},
45+
}),
1846
/* Styles applied to the root element if `alternativeLabel={true}`. */
19-
alternativeLabel: {
47+
...(styleProps.alternativeLabel && {
2048
flex: 1,
2149
position: 'relative',
22-
},
23-
/* Pseudo-class applied to the root element if `completed={true}`. */
24-
completed: {},
25-
};
50+
}),
51+
}));
2652

27-
const Step = React.forwardRef(function Step(props, ref) {
53+
const Step = React.forwardRef(function Step(inProps, ref) {
54+
const props = useThemeProps({ props: inProps, name: 'MuiStep' });
2855
const {
2956
active: activeProp,
3057
children,
31-
classes,
3258
className,
3359
completed: completedProp,
3460
disabled: disabledProp,
@@ -61,23 +87,28 @@ const Step = React.forwardRef(function Step(props, ref) {
6187
[index, last, expanded, active, completed, disabled],
6288
);
6389

90+
const styleProps = {
91+
...props,
92+
active,
93+
orientation,
94+
alternativeLabel,
95+
completed,
96+
disabled,
97+
expanded,
98+
};
99+
100+
const classes = useUtilityClasses(styleProps);
101+
64102
const newChildren = (
65-
<div
66-
className={clsx(
67-
classes.root,
68-
classes[orientation],
69-
{
70-
[classes.alternativeLabel]: alternativeLabel,
71-
[classes.completed]: completed,
72-
},
73-
className,
74-
)}
103+
<StepRoot
104+
className={clsx(classes.root, className)}
75105
ref={ref}
106+
styleProps={styleProps}
76107
{...other}
77108
>
78109
{connector && alternativeLabel && index !== 0 ? connector : null}
79110
{children}
80-
</div>
111+
</StepRoot>
81112
);
82113

83114
return (
@@ -139,6 +170,10 @@ Step.propTypes = {
139170
* The prop defaults to the value inherited from the parent Stepper component.
140171
*/
141172
last: PropTypes.bool,
173+
/**
174+
* The system prop that allows defining system overrides as well as additional CSS styles.
175+
*/
176+
sx: PropTypes.object,
142177
};
143178

144-
export default withStyles(styles, { name: 'MuiStep' })(Step);
179+
export default Step;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { getClasses, createMount, createClientRender, describeConformance } from 'test/utils';
3+
import { getClasses, createMount, createClientRender, describeConformanceV5 } from 'test/utils';
44
import Step from './Step';
55
import Stepper from '../Stepper';
66
import StepLabel from '../StepLabel';
77
import StepButton from '../StepButton';
8+
import classes from './stepClasses';
89

910
describe('<Step />', () => {
10-
let classes;
1111
let stepButtonClasses;
1212
let stepLabelClasses;
1313
const mount = createMount();
1414

1515
const render = createClientRender();
1616

1717
before(() => {
18-
classes = getClasses(<Step />);
1918
stepButtonClasses = getClasses(<StepButton />);
2019
stepLabelClasses = getClasses(<StepLabel />);
2120
});
2221

23-
describeConformance(<Step />, () => ({
22+
describeConformanceV5(<Step />, () => ({
2423
classes,
2524
inheritComponent: 'div',
2625
mount,
26+
muiName: 'MuiStep',
27+
testVariantProps: { variant: 'foo' },
2728
refInstanceof: window.HTMLDivElement,
28-
skip: ['componentProp'],
29+
skip: ['componentProp', 'componentsProp'],
2930
}));
3031

3132
it('merges styles and other props into the root node', () => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export { default } from './Step';
22
export * from './Step';
3+
4+
export { default as stepClasses } from './stepClasses';
5+
export * from './stepClasses';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
export { default } from './Step';
2+
3+
export { default as stepClasses } from './stepClasses';
4+
export * from './stepClasses';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { StepClasskey } from './Step';
2+
3+
declare const stepClasses: Record<StepClasskey, string>;
4+
5+
export function getStepUtilityClass(slot: string): string;
6+
7+
export default stepClasses;
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 getStepUtilityClass(slot) {
4+
return generateUtilityClass('MuiStep', slot);
5+
}
6+
7+
const stepClasses = generateUtilityClasses('MuiStep', [
8+
'root',
9+
'horizontal',
10+
'vertical',
11+
'alternativeLabel',
12+
'completed',
13+
]);
14+
15+
export default stepClasses;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
33
import { getClasses, createMount, createClientRender, describeConformance } from 'test/utils';
4-
import Step from '../Step';
4+
import Step, { stepClasses } from '../Step';
55
import StepLabel from '../StepLabel';
66
import StepConnector from '../StepConnector';
77
import StepContent from '../StepContent';
88
import Stepper from './Stepper';
99

1010
describe('<Stepper />', () => {
1111
let classes;
12-
let stepClasses;
1312
let stepConnectorClasses;
1413
const mount = createMount({ strict: true });
1514
const render = createClientRender();
1615

1716
before(() => {
1817
classes = getClasses(<Stepper />);
19-
stepClasses = getClasses(<Step />);
2018
stepConnectorClasses = getClasses(<StepConnector />);
2119
});
2220

0 commit comments

Comments
 (0)