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 StepperContext from "../Stepper/StepperContext.js";
|
9 | import StepContext from "./StepContext.js";
|
10 | import { styled } from "../zero-styled/index.js";
|
11 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
12 | import { getStepUtilityClass } from "./stepClasses.js";
|
13 | import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
14 | const useUtilityClasses = ownerState => {
|
15 | const {
|
16 | classes,
|
17 | orientation,
|
18 | alternativeLabel,
|
19 | completed
|
20 | } = ownerState;
|
21 | const slots = {
|
22 | root: ['root', orientation, alternativeLabel && 'alternativeLabel', completed && 'completed']
|
23 | };
|
24 | return composeClasses(slots, getStepUtilityClass, classes);
|
25 | };
|
26 | const StepRoot = styled('div', {
|
27 | name: 'MuiStep',
|
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.completed && styles.completed];
|
34 | }
|
35 | })({
|
36 | variants: [{
|
37 | props: {
|
38 | orientation: 'horizontal'
|
39 | },
|
40 | style: {
|
41 | paddingLeft: 8,
|
42 | paddingRight: 8
|
43 | }
|
44 | }, {
|
45 | props: {
|
46 | alternativeLabel: true
|
47 | },
|
48 | style: {
|
49 | flex: 1,
|
50 | position: 'relative'
|
51 | }
|
52 | }]
|
53 | });
|
54 | const Step = React.forwardRef(function Step(inProps, ref) {
|
55 | const props = useDefaultProps({
|
56 | props: inProps,
|
57 | name: 'MuiStep'
|
58 | });
|
59 | const {
|
60 | active: activeProp,
|
61 | children,
|
62 | className,
|
63 | component = 'div',
|
64 | completed: completedProp,
|
65 | disabled: disabledProp,
|
66 | expanded = false,
|
67 | index,
|
68 | last,
|
69 | ...other
|
70 | } = props;
|
71 | const {
|
72 | activeStep,
|
73 | connector,
|
74 | alternativeLabel,
|
75 | orientation,
|
76 | nonLinear
|
77 | } = React.useContext(StepperContext);
|
78 | let [active = false, completed = false, disabled = false] = [activeProp, completedProp, disabledProp];
|
79 | if (activeStep === index) {
|
80 | active = activeProp !== undefined ? activeProp : true;
|
81 | } else if (!nonLinear && activeStep > index) {
|
82 | completed = completedProp !== undefined ? completedProp : true;
|
83 | } else if (!nonLinear && activeStep < index) {
|
84 | disabled = disabledProp !== undefined ? disabledProp : true;
|
85 | }
|
86 | const contextValue = React.useMemo(() => ({
|
87 | index,
|
88 | last,
|
89 | expanded,
|
90 | icon: index + 1,
|
91 | active,
|
92 | completed,
|
93 | disabled
|
94 | }), [index, last, expanded, active, completed, disabled]);
|
95 | const ownerState = {
|
96 | ...props,
|
97 | active,
|
98 | orientation,
|
99 | alternativeLabel,
|
100 | completed,
|
101 | disabled,
|
102 | expanded,
|
103 | component
|
104 | };
|
105 | const classes = useUtilityClasses(ownerState);
|
106 | const newChildren = _jsxs(StepRoot, {
|
107 | as: component,
|
108 | className: clsx(classes.root, className),
|
109 | ref: ref,
|
110 | ownerState: ownerState,
|
111 | ...other,
|
112 | children: [connector && alternativeLabel && index !== 0 ? connector : null, children]
|
113 | });
|
114 | return _jsx(StepContext.Provider, {
|
115 | value: contextValue,
|
116 | children: connector && !alternativeLabel && index !== 0 ? _jsxs(React.Fragment, {
|
117 | children: [connector, newChildren]
|
118 | }) : newChildren
|
119 | });
|
120 | });
|
121 | process.env.NODE_ENV !== "production" ? Step.propTypes = {
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | |
127 |
|
128 |
|
129 | active: 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 | completed: PropTypes.bool,
|
146 | |
147 |
|
148 |
|
149 |
|
150 | component: PropTypes.elementType,
|
151 | |
152 |
|
153 |
|
154 |
|
155 | disabled: PropTypes.bool,
|
156 | |
157 |
|
158 |
|
159 |
|
160 | expanded: PropTypes.bool,
|
161 | |
162 |
|
163 |
|
164 |
|
165 | index: integerPropType,
|
166 | |
167 |
|
168 |
|
169 |
|
170 | last: PropTypes.bool,
|
171 | |
172 |
|
173 |
|
174 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
175 | } : void 0;
|
176 | export default Step; |
\ | No newline at end of file |