1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import integerPropType from '@mui/utils/integerPropType';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import Paper from "../Paper/index.js";
|
9 | import capitalize from "../utils/capitalize.js";
|
10 | import LinearProgress from "../LinearProgress/index.js";
|
11 | import { styled } from "../zero-styled/index.js";
|
12 | import memoTheme from "../utils/memoTheme.js";
|
13 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
14 | import slotShouldForwardProp from "../styles/slotShouldForwardProp.js";
|
15 | import { getMobileStepperUtilityClass } from "./mobileStepperClasses.js";
|
16 | import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
17 | const useUtilityClasses = ownerState => {
|
18 | const {
|
19 | classes,
|
20 | position
|
21 | } = ownerState;
|
22 | const slots = {
|
23 | root: ['root', `position${capitalize(position)}`],
|
24 | dots: ['dots'],
|
25 | dot: ['dot'],
|
26 | dotActive: ['dotActive'],
|
27 | progress: ['progress']
|
28 | };
|
29 | return composeClasses(slots, getMobileStepperUtilityClass, classes);
|
30 | };
|
31 | const MobileStepperRoot = styled(Paper, {
|
32 | name: 'MuiMobileStepper',
|
33 | slot: 'Root',
|
34 | overridesResolver: (props, styles) => {
|
35 | const {
|
36 | ownerState
|
37 | } = props;
|
38 | return [styles.root, styles[`position${capitalize(ownerState.position)}`]];
|
39 | }
|
40 | })(memoTheme(({
|
41 | theme
|
42 | }) => ({
|
43 | display: 'flex',
|
44 | flexDirection: 'row',
|
45 | justifyContent: 'space-between',
|
46 | alignItems: 'center',
|
47 | background: (theme.vars || theme).palette.background.default,
|
48 | padding: 8,
|
49 | variants: [{
|
50 | props: ({
|
51 | position
|
52 | }) => position === 'top' || position === 'bottom',
|
53 | style: {
|
54 | position: 'fixed',
|
55 | left: 0,
|
56 | right: 0,
|
57 | zIndex: (theme.vars || theme).zIndex.mobileStepper
|
58 | }
|
59 | }, {
|
60 | props: {
|
61 | position: 'top'
|
62 | },
|
63 | style: {
|
64 | top: 0
|
65 | }
|
66 | }, {
|
67 | props: {
|
68 | position: 'bottom'
|
69 | },
|
70 | style: {
|
71 | bottom: 0
|
72 | }
|
73 | }]
|
74 | })));
|
75 | const MobileStepperDots = styled('div', {
|
76 | name: 'MuiMobileStepper',
|
77 | slot: 'Dots',
|
78 | overridesResolver: (props, styles) => styles.dots
|
79 | })({
|
80 | variants: [{
|
81 | props: {
|
82 | variant: 'dots'
|
83 | },
|
84 | style: {
|
85 | display: 'flex',
|
86 | flexDirection: 'row'
|
87 | }
|
88 | }]
|
89 | });
|
90 | const MobileStepperDot = styled('div', {
|
91 | name: 'MuiMobileStepper',
|
92 | slot: 'Dot',
|
93 | shouldForwardProp: prop => slotShouldForwardProp(prop) && prop !== 'dotActive',
|
94 | overridesResolver: (props, styles) => {
|
95 | const {
|
96 | dotActive
|
97 | } = props;
|
98 | return [styles.dot, dotActive && styles.dotActive];
|
99 | }
|
100 | })(memoTheme(({
|
101 | theme
|
102 | }) => ({
|
103 | variants: [{
|
104 | props: {
|
105 | variant: 'dots'
|
106 | },
|
107 | style: {
|
108 | transition: theme.transitions.create('background-color', {
|
109 | duration: theme.transitions.duration.shortest
|
110 | }),
|
111 | backgroundColor: (theme.vars || theme).palette.action.disabled,
|
112 | borderRadius: '50%',
|
113 | width: 8,
|
114 | height: 8,
|
115 | margin: '0 2px'
|
116 | }
|
117 | }, {
|
118 | props: {
|
119 | variant: 'dots',
|
120 | dotActive: true
|
121 | },
|
122 | style: {
|
123 | backgroundColor: (theme.vars || theme).palette.primary.main
|
124 | }
|
125 | }]
|
126 | })));
|
127 | const MobileStepperProgress = styled(LinearProgress, {
|
128 | name: 'MuiMobileStepper',
|
129 | slot: 'Progress',
|
130 | overridesResolver: (props, styles) => styles.progress
|
131 | })({
|
132 | variants: [{
|
133 | props: {
|
134 | variant: 'progress'
|
135 | },
|
136 | style: {
|
137 | width: '50%'
|
138 | }
|
139 | }]
|
140 | });
|
141 | const MobileStepper = React.forwardRef(function MobileStepper(inProps, ref) {
|
142 | const props = useDefaultProps({
|
143 | props: inProps,
|
144 | name: 'MuiMobileStepper'
|
145 | });
|
146 | const {
|
147 | activeStep = 0,
|
148 | backButton,
|
149 | className,
|
150 | LinearProgressProps,
|
151 | nextButton,
|
152 | position = 'bottom',
|
153 | steps,
|
154 | variant = 'dots',
|
155 | ...other
|
156 | } = props;
|
157 | const ownerState = {
|
158 | ...props,
|
159 | activeStep,
|
160 | position,
|
161 | variant
|
162 | };
|
163 | let value;
|
164 | if (variant === 'progress') {
|
165 | if (steps === 1) {
|
166 | value = 100;
|
167 | } else {
|
168 | value = Math.ceil(activeStep / (steps - 1) * 100);
|
169 | }
|
170 | }
|
171 | const classes = useUtilityClasses(ownerState);
|
172 | return _jsxs(MobileStepperRoot, {
|
173 | square: true,
|
174 | elevation: 0,
|
175 | className: clsx(classes.root, className),
|
176 | ref: ref,
|
177 | ownerState: ownerState,
|
178 | ...other,
|
179 | children: [backButton, variant === 'text' && _jsxs(React.Fragment, {
|
180 | children: [activeStep + 1, " / ", steps]
|
181 | }), variant === 'dots' && _jsx(MobileStepperDots, {
|
182 | ownerState: ownerState,
|
183 | className: classes.dots,
|
184 | children: [...new Array(steps)].map((_, index) => _jsx(MobileStepperDot, {
|
185 | className: clsx(classes.dot, index === activeStep && classes.dotActive),
|
186 | ownerState: ownerState,
|
187 | dotActive: index === activeStep
|
188 | }, index))
|
189 | }), variant === 'progress' && _jsx(MobileStepperProgress, {
|
190 | ownerState: ownerState,
|
191 | className: classes.progress,
|
192 | variant: "determinate",
|
193 | value: value,
|
194 | ...LinearProgressProps
|
195 | }), nextButton]
|
196 | });
|
197 | });
|
198 | process.env.NODE_ENV !== "production" ? MobileStepper.propTypes = {
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | |
204 |
|
205 |
|
206 |
|
207 |
|
208 | activeStep: integerPropType,
|
209 | |
210 |
|
211 |
|
212 | backButton: PropTypes.node,
|
213 | |
214 |
|
215 |
|
216 | classes: PropTypes.object,
|
217 | |
218 |
|
219 |
|
220 | className: PropTypes.string,
|
221 | |
222 |
|
223 |
|
224 | LinearProgressProps: PropTypes.object,
|
225 | |
226 |
|
227 |
|
228 | nextButton: PropTypes.node,
|
229 | |
230 |
|
231 |
|
232 |
|
233 | position: PropTypes.oneOf(['bottom', 'static', 'top']),
|
234 | |
235 |
|
236 |
|
237 | steps: integerPropType.isRequired,
|
238 | |
239 |
|
240 |
|
241 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
242 | |
243 |
|
244 |
|
245 |
|
246 | variant: PropTypes.oneOf(['dots', 'progress', 'text'])
|
247 | } : void 0;
|
248 | export default MobileStepper; |
\ | No newline at end of file |