11import * as React from 'react' ;
22import PropTypes from 'prop-types' ;
33import clsx from 'clsx' ;
4- import { integerPropType } from '@material-ui/utils' ;
5- import withStyles from '../styles/withStyles ' ;
4+ import { integerPropType , deepmerge } from '@material-ui/utils' ;
5+ import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled ' ;
66import Paper from '../Paper' ;
77import capitalize from '../utils/capitalize' ;
88import LinearProgress from '../LinearProgress' ;
99
10- export const styles = ( theme ) => ( {
11- /* Styles applied to the root element. */
12- root : {
13- display : 'flex' ,
14- flexDirection : 'row' ,
15- justifyContent : 'space-between' ,
16- alignItems : 'center' ,
17- background : theme . palette . background . default ,
18- padding : 8 ,
10+ import useThemeProps from '../styles/useThemeProps' ;
11+ import experimentalStyled from '../styles/experimentalStyled' ;
12+ import mobileStepperClasses , { getMobileStepperUtilityClass } from './mobileStepperClasses' ;
13+
14+ const overridesResolver = ( props , styles ) => {
15+ const { styleProps } = props ;
16+
17+ return deepmerge (
18+ {
19+ ...styles [ `position${ capitalize ( styleProps . position ) } ` ] ,
20+ [ `& .${ mobileStepperClasses . dots } ` ] : styles . dots ,
21+ [ `& .${ mobileStepperClasses . dot } ` ] : {
22+ ...styles . dot ,
23+ ...( styleProps . dotActive && styles . dotActive ) ,
24+ } ,
25+ [ `& .${ mobileStepperClasses . dotActive } ` ] : styles . dotActive ,
26+ [ `& .${ mobileStepperClasses . progress } ` ] : styles . progress ,
27+ } ,
28+ styles . root || { } ,
29+ ) ;
30+ } ;
31+
32+ const useUtilityClasses = ( styleProps ) => {
33+ const { classes, position } = styleProps ;
34+
35+ const slots = {
36+ root : [ 'root' , `position${ capitalize ( position ) } ` ] ,
37+ dots : [ 'dots' ] ,
38+ dot : [ 'dot' ] ,
39+ dotActive : [ 'dotActive' ] ,
40+ progress : [ 'progress' ] ,
41+ } ;
42+
43+ return composeClasses ( slots , getMobileStepperUtilityClass , classes ) ;
44+ } ;
45+
46+ const MobileStepperRoot = experimentalStyled (
47+ Paper ,
48+ { } ,
49+ {
50+ name : 'MuiMobileStepper' ,
51+ slot : 'Root' ,
52+ overridesResolver,
1953 } ,
54+ ) ( ( { theme, styleProps } ) => ( {
55+ /* Styles applied to the root element. */
56+ display : 'flex' ,
57+ flexDirection : 'row' ,
58+ justifyContent : 'space-between' ,
59+ alignItems : 'center' ,
60+ background : theme . palette . background . default ,
61+ padding : 8 ,
2062 /* Styles applied to the root element if `position="bottom"`. */
21- positionBottom : {
63+ ... ( styleProps . position === 'bottom' && {
2264 position : 'fixed' ,
2365 bottom : 0 ,
2466 left : 0 ,
2567 right : 0 ,
2668 zIndex : theme . zIndex . mobileStepper ,
27- } ,
69+ } ) ,
2870 /* Styles applied to the root element if `position="top"`. */
29- positionTop : {
71+ ... ( styleProps . position === 'top' && {
3072 position : 'fixed' ,
3173 top : 0 ,
3274 left : 0 ,
3375 right : 0 ,
3476 zIndex : theme . zIndex . mobileStepper ,
35- } ,
36- /* Styles applied to the root element if `position="static"`. */
37- positionStatic : { } ,
77+ } ) ,
78+ } ) ) ;
79+
80+ const MobileStepperDots = experimentalStyled (
81+ 'div' ,
82+ { } ,
83+ { name : 'MuiMobileStepper' , slot : 'Dots' } ,
84+ ) ( ( { styleProps } ) => ( {
3885 /* Styles applied to the dots container if `variant="dots"`. */
39- dots : {
86+ ... ( styleProps . variant === ' dots' && {
4087 display : 'flex' ,
4188 flexDirection : 'row' ,
42- } ,
89+ } ) ,
90+ } ) ) ;
91+
92+ const MobileStepperDot = experimentalStyled (
93+ 'div' ,
94+ { } ,
95+ { name : 'MuiMobileStepper' , slot : 'Dot' } ,
96+ ) ( ( { theme, styleProps } ) => ( {
4397 /* Styles applied to each dot if `variant="dots"`. */
44- dot : {
98+ ... ( styleProps . variant === 'dots' && {
4599 transition : theme . transitions . create ( 'background-color' , {
46100 duration : theme . transitions . duration . shortest ,
47101 } ) ,
@@ -50,22 +104,29 @@ export const styles = (theme) => ({
50104 width : 8 ,
51105 height : 8 ,
52106 margin : '0 2px' ,
53- } ,
54- /* Styles applied to a dot if `variant="dots"` and this is the active step. */
55- dotActive : {
56- backgroundColor : theme . palette . primary . main ,
57- } ,
107+ /* Styles applied to a dot if `variant="dots"` and this is the active step. */
108+ ...( styleProps . dotActive && {
109+ backgroundColor : theme . palette . primary . main ,
110+ } ) ,
111+ } ) ,
112+ } ) ) ;
113+
114+ const MobileStepperProgress = experimentalStyled (
115+ LinearProgress ,
116+ { } ,
117+ { name : 'MuiMobileStepper' , slot : 'Progress' } ,
118+ ) ( ( { styleProps } ) => ( {
58119 /* Styles applied to the Linear Progress component if `variant="progress"`. */
59- progress : {
120+ ... ( styleProps . variant === ' progress' && {
60121 width : '50%' ,
61- } ,
62- } ) ;
122+ } ) ,
123+ } ) ) ;
63124
64- const MobileStepper = React . forwardRef ( function MobileStepper ( props , ref ) {
125+ const MobileStepper = React . forwardRef ( function MobileStepper ( inProps , ref ) {
126+ const props = useThemeProps ( { props : inProps , name : 'MuiMobileStepper' } ) ;
65127 const {
66128 activeStep = 0 ,
67129 backButton,
68- classes,
69130 className,
70131 LinearProgressProps,
71132 nextButton,
@@ -75,12 +136,22 @@ const MobileStepper = React.forwardRef(function MobileStepper(props, ref) {
75136 ...other
76137 } = props ;
77138
139+ const styleProps = {
140+ ...props ,
141+ activeStep,
142+ position,
143+ variant,
144+ } ;
145+
146+ const classes = useUtilityClasses ( styleProps ) ;
147+
78148 return (
79- < Paper
149+ < MobileStepperRoot
80150 square
81151 elevation = { 0 }
82- className = { clsx ( classes . root , classes [ `position ${ capitalize ( position ) } ` ] , className ) }
152+ className = { clsx ( classes . root , className ) }
83153 ref = { ref }
154+ styleProps = { styleProps }
84155 { ...other }
85156 >
86157 { backButton }
@@ -91,20 +162,20 @@ const MobileStepper = React.forwardRef(function MobileStepper(props, ref) {
91162 ) }
92163
93164 { variant === 'dots' && (
94- < div className = { classes . dots } >
165+ < MobileStepperDots styleProps = { styleProps } className = { classes . dots } >
95166 { [ ...new Array ( steps ) ] . map ( ( _ , index ) => (
96- < div
167+ < MobileStepperDot
97168 key = { index }
98- className = { clsx ( classes . dot , {
99- [ classes . dotActive ] : index === activeStep ,
100- } ) }
169+ className = { clsx ( classes . dot , { [ classes . dotActive ] : index === activeStep } ) }
170+ styleProps = { { ...styleProps , dotActive : index === activeStep } }
101171 />
102172 ) ) }
103- </ div >
173+ </ MobileStepperDots >
104174 ) }
105175
106176 { variant === 'progress' && (
107- < LinearProgress
177+ < MobileStepperProgress
178+ styleProps = { styleProps }
108179 className = { classes . progress }
109180 variant = "determinate"
110181 value = { Math . ceil ( ( activeStep / ( steps - 1 ) ) * 100 ) }
@@ -113,7 +184,7 @@ const MobileStepper = React.forwardRef(function MobileStepper(props, ref) {
113184 ) }
114185
115186 { nextButton }
116- </ Paper >
187+ </ MobileStepperRoot >
117188 ) ;
118189} ) ;
119190
@@ -157,11 +228,15 @@ MobileStepper.propTypes /* remove-proptypes */ = {
157228 * The total steps.
158229 */
159230 steps : integerPropType . isRequired ,
231+ /**
232+ * The system prop that allows defining system overrides as well as additional CSS styles.
233+ */
234+ sx : PropTypes . object ,
160235 /**
161236 * The variant to use.
162237 * @default 'dots'
163238 */
164239 variant : PropTypes . oneOf ( [ 'dots' , 'progress' , 'text' ] ) ,
165240} ;
166241
167- export default withStyles ( styles , { name : 'MuiMobileStepper' } ) ( MobileStepper ) ;
242+ export default MobileStepper ;
0 commit comments