UNPKG

6.98 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import integerPropType from '@mui/utils/integerPropType';
7import composeClasses from '@mui/utils/composeClasses';
8import Paper from "../Paper/index.js";
9import capitalize from "../utils/capitalize.js";
10import LinearProgress from "../LinearProgress/index.js";
11import { styled } from "../zero-styled/index.js";
12import memoTheme from "../utils/memoTheme.js";
13import { useDefaultProps } from "../DefaultPropsProvider/index.js";
14import slotShouldForwardProp from "../styles/slotShouldForwardProp.js";
15import { getMobileStepperUtilityClass } from "./mobileStepperClasses.js";
16import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
17const 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};
31const 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})));
75const 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});
90const 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})));
127const 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});
141const MobileStepper = /*#__PURE__*/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 /*#__PURE__*/_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' && /*#__PURE__*/_jsxs(React.Fragment, {
180 children: [activeStep + 1, " / ", steps]
181 }), variant === 'dots' && /*#__PURE__*/_jsx(MobileStepperDots, {
182 ownerState: ownerState,
183 className: classes.dots,
184 children: [...new Array(steps)].map((_, index) => /*#__PURE__*/_jsx(MobileStepperDot, {
185 className: clsx(classes.dot, index === activeStep && classes.dotActive),
186 ownerState: ownerState,
187 dotActive: index === activeStep
188 }, index))
189 }), variant === 'progress' && /*#__PURE__*/_jsx(MobileStepperProgress, {
190 ownerState: ownerState,
191 className: classes.progress,
192 variant: "determinate",
193 value: value,
194 ...LinearProgressProps
195 }), nextButton]
196 });
197});
198process.env.NODE_ENV !== "production" ? MobileStepper.propTypes /* remove-proptypes */ = {
199 // ┌────────────────────────────── Warning ──────────────────────────────┐
200 // │ These PropTypes are generated from the TypeScript type definitions. │
201 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
202 // └─────────────────────────────────────────────────────────────────────┘
203 /**
204 * Set the active step (zero based index).
205 * Defines which dot is highlighted when the variant is 'dots'.
206 * @default 0
207 */
208 activeStep: integerPropType,
209 /**
210 * A back button element. For instance, it can be a `Button` or an `IconButton`.
211 */
212 backButton: PropTypes.node,
213 /**
214 * Override or extend the styles applied to the component.
215 */
216 classes: PropTypes.object,
217 /**
218 * @ignore
219 */
220 className: PropTypes.string,
221 /**
222 * Props applied to the `LinearProgress` element.
223 */
224 LinearProgressProps: PropTypes.object,
225 /**
226 * A next button element. For instance, it can be a `Button` or an `IconButton`.
227 */
228 nextButton: PropTypes.node,
229 /**
230 * Set the positioning type.
231 * @default 'bottom'
232 */
233 position: PropTypes.oneOf(['bottom', 'static', 'top']),
234 /**
235 * The total steps.
236 */
237 steps: integerPropType.isRequired,
238 /**
239 * The system prop that allows defining system overrides as well as additional CSS styles.
240 */
241 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
242 /**
243 * The variant to use.
244 * @default 'dots'
245 */
246 variant: PropTypes.oneOf(['dots', 'progress', 'text'])
247} : void 0;
248export default MobileStepper;
\No newline at end of file