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 { styled } from "../zero-styled/index.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import { getStepperUtilityClass } from "./stepperClasses.js";
|
11 | import StepConnector from "../StepConnector/index.js";
|
12 | import StepperContext from "./StepperContext.js";
|
13 | import { jsx as _jsx } from "react/jsx-runtime";
|
14 | const useUtilityClasses = ownerState => {
|
15 | const {
|
16 | orientation,
|
17 | nonLinear,
|
18 | alternativeLabel,
|
19 | classes
|
20 | } = ownerState;
|
21 | const slots = {
|
22 | root: ['root', orientation, nonLinear && 'nonLinear', alternativeLabel && 'alternativeLabel']
|
23 | };
|
24 | return composeClasses(slots, getStepperUtilityClass, classes);
|
25 | };
|
26 | const StepperRoot = styled('div', {
|
27 | name: 'MuiStepper',
|
28 | slot: 'Root',
|
29 | overridesResolver: (props, styles) => {
|
30 | const {
|
31 | ownerState
|
32 | } = props;
|
33 | return [styles.root, styles[ownerState.orientation], ownerState.alternativeLabel && styles.alternativeLabel, ownerState.nonLinear && styles.nonLinear];
|
34 | }
|
35 | })({
|
36 | display: 'flex',
|
37 | variants: [{
|
38 | props: {
|
39 | orientation: 'horizontal'
|
40 | },
|
41 | style: {
|
42 | flexDirection: 'row',
|
43 | alignItems: 'center'
|
44 | }
|
45 | }, {
|
46 | props: {
|
47 | orientation: 'vertical'
|
48 | },
|
49 | style: {
|
50 | flexDirection: 'column'
|
51 | }
|
52 | }, {
|
53 | props: {
|
54 | alternativeLabel: true
|
55 | },
|
56 | style: {
|
57 | alignItems: 'flex-start'
|
58 | }
|
59 | }]
|
60 | });
|
61 | const defaultConnector = _jsx(StepConnector, {});
|
62 | const Stepper = React.forwardRef(function Stepper(inProps, ref) {
|
63 | const props = useDefaultProps({
|
64 | props: inProps,
|
65 | name: 'MuiStepper'
|
66 | });
|
67 | const {
|
68 | activeStep = 0,
|
69 | alternativeLabel = false,
|
70 | children,
|
71 | className,
|
72 | component = 'div',
|
73 | connector = defaultConnector,
|
74 | nonLinear = false,
|
75 | orientation = 'horizontal',
|
76 | ...other
|
77 | } = props;
|
78 | const ownerState = {
|
79 | ...props,
|
80 | nonLinear,
|
81 | alternativeLabel,
|
82 | orientation,
|
83 | component
|
84 | };
|
85 | const classes = useUtilityClasses(ownerState);
|
86 | const childrenArray = React.Children.toArray(children).filter(Boolean);
|
87 | const steps = childrenArray.map((step, index) => {
|
88 | return React.cloneElement(step, {
|
89 | index,
|
90 | last: index + 1 === childrenArray.length,
|
91 | ...step.props
|
92 | });
|
93 | });
|
94 | const contextValue = React.useMemo(() => ({
|
95 | activeStep,
|
96 | alternativeLabel,
|
97 | connector,
|
98 | nonLinear,
|
99 | orientation
|
100 | }), [activeStep, alternativeLabel, connector, nonLinear, orientation]);
|
101 | return _jsx(StepperContext.Provider, {
|
102 | value: contextValue,
|
103 | children: _jsx(StepperRoot, {
|
104 | as: component,
|
105 | ownerState: ownerState,
|
106 | className: clsx(classes.root, className),
|
107 | ref: ref,
|
108 | ...other,
|
109 | children: steps
|
110 | })
|
111 | });
|
112 | });
|
113 | process.env.NODE_ENV !== "production" ? Stepper.propTypes = {
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 | activeStep: integerPropType,
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 | alternativeLabel: PropTypes.bool,
|
130 | |
131 |
|
132 |
|
133 | children: PropTypes.node,
|
134 | |
135 |
|
136 |
|
137 | classes: PropTypes.object,
|
138 | |
139 |
|
140 |
|
141 | className: PropTypes.string,
|
142 | |
143 |
|
144 |
|
145 |
|
146 | component: PropTypes.elementType,
|
147 | |
148 |
|
149 |
|
150 |
|
151 | connector: PropTypes.element,
|
152 | |
153 |
|
154 |
|
155 |
|
156 | nonLinear: PropTypes.bool,
|
157 | |
158 |
|
159 |
|
160 |
|
161 | orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
162 | |
163 |
|
164 |
|
165 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
166 | } : void 0;
|
167 | export default Stepper; |
\ | No newline at end of file |