UNPKG

8.23 kBJavaScriptView Raw
1'use client';
2
3import composeClasses from '@mui/utils/composeClasses';
4import clsx from 'clsx';
5import PropTypes from 'prop-types';
6import * as React from 'react';
7import StepContext from "../Step/StepContext.js";
8import StepIcon from "../StepIcon/index.js";
9import StepperContext from "../Stepper/StepperContext.js";
10import { styled } from "../zero-styled/index.js";
11import memoTheme from "../utils/memoTheme.js";
12import { useDefaultProps } from "../DefaultPropsProvider/index.js";
13import stepLabelClasses, { getStepLabelUtilityClass } from "./stepLabelClasses.js";
14import useSlot from "../utils/useSlot.js";
15import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16const 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};
34const 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});
62const 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})));
89const 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});
101const 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})));
114const StepLabel = /*#__PURE__*/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 /*#__PURE__*/_jsxs(StepLabelRoot, {
176 className: clsx(classes.root, className),
177 ref: ref,
178 ownerState: ownerState,
179 ...other,
180 children: [icon || StepIconSlot ? /*#__PURE__*/_jsx(StepLabelIconContainer, {
181 className: classes.iconContainer,
182 ownerState: ownerState,
183 children: /*#__PURE__*/_jsx(StepIconSlot, {
184 completed: completed,
185 active: active,
186 error: error,
187 icon: icon,
188 ...stepIconProps
189 })
190 }) : null, /*#__PURE__*/_jsxs(StepLabelLabelContainer, {
191 className: classes.labelContainer,
192 ownerState: ownerState,
193 children: [children ? /*#__PURE__*/_jsx(LabelSlot, {
194 ...labelProps,
195 className: clsx(classes.label, labelProps?.className),
196 children: children
197 }) : null, optional]
198 })]
199 });
200});
201process.env.NODE_ENV !== "production" ? StepLabel.propTypes /* remove-proptypes */ = {
202 // ┌────────────────────────────── Warning ──────────────────────────────┐
203 // │ These PropTypes are generated from the TypeScript type definitions. │
204 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
205 // └─────────────────────────────────────────────────────────────────────┘
206 /**
207 * In most cases will simply be a string containing a title for the label.
208 */
209 children: PropTypes.node,
210 /**
211 * Override or extend the styles applied to the component.
212 */
213 classes: PropTypes.object,
214 /**
215 * @ignore
216 */
217 className: PropTypes.string,
218 /**
219 * The props used for each slot inside.
220 * @default {}
221 * @deprecated use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
222 */
223 componentsProps: PropTypes.shape({
224 label: PropTypes.object
225 }),
226 /**
227 * If `true`, the step is marked as failed.
228 * @default false
229 */
230 error: PropTypes.bool,
231 /**
232 * Override the default label of the step icon.
233 */
234 icon: PropTypes.node,
235 /**
236 * The optional node to display.
237 */
238 optional: PropTypes.node,
239 /**
240 * The props used for each slot inside.
241 * @default {}
242 */
243 slotProps: PropTypes.shape({
244 label: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
245 stepIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
246 }),
247 /**
248 * The components used for each slot inside.
249 * @default {}
250 */
251 slots: PropTypes.shape({
252 label: PropTypes.elementType,
253 stepIcon: PropTypes.elementType
254 }),
255 /**
256 * The component to render in place of the [`StepIcon`](https://mui.com/material-ui/api/step-icon/).
257 */
258 StepIconComponent: PropTypes.elementType,
259 /**
260 * Props applied to the [`StepIcon`](https://mui.com/material-ui/api/step-icon/) element.
261 */
262 StepIconProps: PropTypes.object,
263 /**
264 * The system prop that allows defining system overrides as well as additional CSS styles.
265 */
266 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
267} : void 0;
268if (StepLabel) {
269 StepLabel.muiName = 'StepLabel';
270}
271export default StepLabel;
\No newline at end of file