|
1 | 1 | import * as React from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | 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'; |
5 | 6 | import StepperContext from '../Stepper/StepperContext'; |
6 | 7 | import StepContext from './StepContext'; |
| 8 | +import useThemeProps from '../styles/useThemeProps'; |
| 9 | +import experimentalStyled from '../styles/experimentalStyled'; |
| 10 | +import { getStepUtilityClass } from './stepClasses'; |
7 | 11 |
|
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 }) => ({ |
11 | 41 | /* Styles applied to the root element if `orientation="horizontal"`. */ |
12 | | - horizontal: { |
| 42 | + ...(styleProps.orientation === 'horizontal' && { |
13 | 43 | paddingLeft: 8, |
14 | 44 | paddingRight: 8, |
15 | | - }, |
16 | | - /* Styles applied to the root element if `orientation="vertical"`. */ |
17 | | - vertical: {}, |
| 45 | + }), |
18 | 46 | /* Styles applied to the root element if `alternativeLabel={true}`. */ |
19 | | - alternativeLabel: { |
| 47 | + ...(styleProps.alternativeLabel && { |
20 | 48 | flex: 1, |
21 | 49 | position: 'relative', |
22 | | - }, |
23 | | - /* Pseudo-class applied to the root element if `completed={true}`. */ |
24 | | - completed: {}, |
25 | | -}; |
| 50 | + }), |
| 51 | +})); |
26 | 52 |
|
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' }); |
28 | 55 | const { |
29 | 56 | active: activeProp, |
30 | 57 | children, |
31 | | - classes, |
32 | 58 | className, |
33 | 59 | completed: completedProp, |
34 | 60 | disabled: disabledProp, |
@@ -61,23 +87,28 @@ const Step = React.forwardRef(function Step(props, ref) { |
61 | 87 | [index, last, expanded, active, completed, disabled], |
62 | 88 | ); |
63 | 89 |
|
| 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 | + |
64 | 102 | 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)} |
75 | 105 | ref={ref} |
| 106 | + styleProps={styleProps} |
76 | 107 | {...other} |
77 | 108 | > |
78 | 109 | {connector && alternativeLabel && index !== 0 ? connector : null} |
79 | 110 | {children} |
80 | | - </div> |
| 111 | + </StepRoot> |
81 | 112 | ); |
82 | 113 |
|
83 | 114 | return ( |
@@ -139,6 +170,10 @@ Step.propTypes = { |
139 | 170 | * The prop defaults to the value inherited from the parent Stepper component. |
140 | 171 | */ |
141 | 172 | last: PropTypes.bool, |
| 173 | + /** |
| 174 | + * The system prop that allows defining system overrides as well as additional CSS styles. |
| 175 | + */ |
| 176 | + sx: PropTypes.object, |
142 | 177 | }; |
143 | 178 |
|
144 | | -export default withStyles(styles, { name: 'MuiStep' })(Step); |
| 179 | +export default Step; |
0 commit comments