1 | 'use client';
|
2 |
|
3 | import composeClasses from '@mui/utils/composeClasses';
|
4 | import clsx from 'clsx';
|
5 | import PropTypes from 'prop-types';
|
6 | import * as React from 'react';
|
7 | import StepContext from "../Step/StepContext.js";
|
8 | import StepIcon from "../StepIcon/index.js";
|
9 | import StepperContext from "../Stepper/StepperContext.js";
|
10 | import { styled } from "../zero-styled/index.js";
|
11 | import memoTheme from "../utils/memoTheme.js";
|
12 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
13 | import stepLabelClasses, { getStepLabelUtilityClass } from "./stepLabelClasses.js";
|
14 | import useSlot from "../utils/useSlot.js";
|
15 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
16 | const useUtilityClasses = ownerState => {
|
17 | const {
|
18 | classes,
|
19 | orientation,
|
20 | active,
|
21 | completed,
|
22 | error,
|
23 | disabled,
|
24 | alternativeLabel
|
25 | } = ownerState;
|
26 | const slots = {
|
27 | root: ['root', orientation, error && 'error', disabled && 'disabled', alternativeLabel && 'alternativeLabel'],
|
28 | label: ['label', active && 'active', completed && 'completed', error && 'error', disabled && 'disabled', alternativeLabel && 'alternativeLabel'],
|
29 | iconContainer: ['iconContainer', active && 'active', completed && 'completed', error && 'error', disabled && 'disabled', alternativeLabel && 'alternativeLabel'],
|
30 | labelContainer: ['labelContainer', alternativeLabel && 'alternativeLabel']
|
31 | };
|
32 | return composeClasses(slots, getStepLabelUtilityClass, classes);
|
33 | };
|
34 | const StepLabelRoot = styled('span', {
|
35 | name: 'MuiStepLabel',
|
36 | slot: 'Root',
|
37 | overridesResolver: (props, styles) => {
|
38 | const {
|
39 | ownerState
|
40 | } = props;
|
41 | return [styles.root, styles[ownerState.orientation]];
|
42 | }
|
43 | })({
|
44 | display: 'flex',
|
45 | alignItems: 'center',
|
46 | [`&.${stepLabelClasses.alternativeLabel}`]: {
|
47 | flexDirection: 'column'
|
48 | },
|
49 | [`&.${stepLabelClasses.disabled}`]: {
|
50 | cursor: 'default'
|
51 | },
|
52 | variants: [{
|
53 | props: {
|
54 | orientation: 'vertical'
|
55 | },
|
56 | style: {
|
57 | textAlign: 'left',
|
58 | padding: '8px 0'
|
59 | }
|
60 | }]
|
61 | });
|
62 | const StepLabelLabel = styled('span', {
|
63 | name: 'MuiStepLabel',
|
64 | slot: 'Label',
|
65 | overridesResolver: (props, styles) => styles.label
|
66 | })(memoTheme(({
|
67 | theme
|
68 | }) => ({
|
69 | ...theme.typography.body2,
|
70 | display: 'block',
|
71 | transition: theme.transitions.create('color', {
|
72 | duration: theme.transitions.duration.shortest
|
73 | }),
|
74 | [`&.${stepLabelClasses.active}`]: {
|
75 | color: (theme.vars || theme).palette.text.primary,
|
76 | fontWeight: 500
|
77 | },
|
78 | [`&.${stepLabelClasses.completed}`]: {
|
79 | color: (theme.vars || theme).palette.text.primary,
|
80 | fontWeight: 500
|
81 | },
|
82 | [`&.${stepLabelClasses.alternativeLabel}`]: {
|
83 | marginTop: 16
|
84 | },
|
85 | [`&.${stepLabelClasses.error}`]: {
|
86 | color: (theme.vars || theme).palette.error.main
|
87 | }
|
88 | })));
|
89 | const StepLabelIconContainer = styled('span', {
|
90 | name: 'MuiStepLabel',
|
91 | slot: 'IconContainer',
|
92 | overridesResolver: (props, styles) => styles.iconContainer
|
93 | })({
|
94 | flexShrink: 0,
|
95 | display: 'flex',
|
96 | paddingRight: 8,
|
97 | [`&.${stepLabelClasses.alternativeLabel}`]: {
|
98 | paddingRight: 0
|
99 | }
|
100 | });
|
101 | const StepLabelLabelContainer = styled('span', {
|
102 | name: 'MuiStepLabel',
|
103 | slot: 'LabelContainer',
|
104 | overridesResolver: (props, styles) => styles.labelContainer
|
105 | })(memoTheme(({
|
106 | theme
|
107 | }) => ({
|
108 | width: '100%',
|
109 | color: (theme.vars || theme).palette.text.secondary,
|
110 | [`&.${stepLabelClasses.alternativeLabel}`]: {
|
111 | textAlign: 'center'
|
112 | }
|
113 | })));
|
114 | const StepLabel = React.forwardRef(function StepLabel(inProps, ref) {
|
115 | const props = useDefaultProps({
|
116 | props: inProps,
|
117 | name: 'MuiStepLabel'
|
118 | });
|
119 | const {
|
120 | children,
|
121 | className,
|
122 | componentsProps = {},
|
123 | error = false,
|
124 | icon: iconProp,
|
125 | optional,
|
126 | slots = {},
|
127 | slotProps = {},
|
128 | StepIconComponent: StepIconComponentProp,
|
129 | StepIconProps,
|
130 | ...other
|
131 | } = props;
|
132 | const {
|
133 | alternativeLabel,
|
134 | orientation
|
135 | } = React.useContext(StepperContext);
|
136 | const {
|
137 | active,
|
138 | disabled,
|
139 | completed,
|
140 | icon: iconContext
|
141 | } = React.useContext(StepContext);
|
142 | const icon = iconProp || iconContext;
|
143 | let StepIconComponent = StepIconComponentProp;
|
144 | if (icon && !StepIconComponent) {
|
145 | StepIconComponent = StepIcon;
|
146 | }
|
147 | const ownerState = {
|
148 | ...props,
|
149 | active,
|
150 | alternativeLabel,
|
151 | completed,
|
152 | disabled,
|
153 | error,
|
154 | orientation
|
155 | };
|
156 | const classes = useUtilityClasses(ownerState);
|
157 | const externalForwardedProps = {
|
158 | slots,
|
159 | slotProps: {
|
160 | stepIcon: StepIconProps,
|
161 | ...componentsProps,
|
162 | ...slotProps
|
163 | }
|
164 | };
|
165 | const [LabelSlot, labelProps] = useSlot('label', {
|
166 | elementType: StepLabelLabel,
|
167 | externalForwardedProps,
|
168 | ownerState
|
169 | });
|
170 | const [StepIconSlot, stepIconProps] = useSlot('stepIcon', {
|
171 | elementType: StepIconComponent,
|
172 | externalForwardedProps,
|
173 | ownerState
|
174 | });
|
175 | return _jsxs(StepLabelRoot, {
|
176 | className: clsx(classes.root, className),
|
177 | ref: ref,
|
178 | ownerState: ownerState,
|
179 | ...other,
|
180 | children: [icon || StepIconSlot ? _jsx(StepLabelIconContainer, {
|
181 | className: classes.iconContainer,
|
182 | ownerState: ownerState,
|
183 | children: _jsx(StepIconSlot, {
|
184 | completed: completed,
|
185 | active: active,
|
186 | error: error,
|
187 | icon: icon,
|
188 | ...stepIconProps
|
189 | })
|
190 | }) : null, _jsxs(StepLabelLabelContainer, {
|
191 | className: classes.labelContainer,
|
192 | ownerState: ownerState,
|
193 | children: [children ? _jsx(LabelSlot, {
|
194 | ...labelProps,
|
195 | className: clsx(classes.label, labelProps?.className),
|
196 | children: children
|
197 | }) : null, optional]
|
198 | })]
|
199 | });
|
200 | });
|
201 | process.env.NODE_ENV !== "production" ? StepLabel.propTypes = {
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | |
207 |
|
208 |
|
209 | children: PropTypes.node,
|
210 | |
211 |
|
212 |
|
213 | classes: PropTypes.object,
|
214 | |
215 |
|
216 |
|
217 | className: PropTypes.string,
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 | componentsProps: PropTypes.shape({
|
224 | label: PropTypes.object
|
225 | }),
|
226 | |
227 |
|
228 |
|
229 |
|
230 | error: PropTypes.bool,
|
231 | |
232 |
|
233 |
|
234 | icon: PropTypes.node,
|
235 | |
236 |
|
237 |
|
238 | optional: PropTypes.node,
|
239 | |
240 |
|
241 |
|
242 |
|
243 | slotProps: PropTypes.shape({
|
244 | label: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
245 | stepIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
246 | }),
|
247 | |
248 |
|
249 |
|
250 |
|
251 | slots: PropTypes.shape({
|
252 | label: PropTypes.elementType,
|
253 | stepIcon: PropTypes.elementType
|
254 | }),
|
255 | |
256 |
|
257 |
|
258 | StepIconComponent: PropTypes.elementType,
|
259 | |
260 |
|
261 |
|
262 | StepIconProps: PropTypes.object,
|
263 | |
264 |
|
265 |
|
266 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
267 | } : void 0;
|
268 | if (StepLabel) {
|
269 | StepLabel.muiName = 'StepLabel';
|
270 | }
|
271 | export default StepLabel; |
\ | No newline at end of file |