UNPKG

5.47 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 StepperContext from "../Stepper/StepperContext.js";
9import StepContext from "./StepContext.js";
10import { styled } from "../zero-styled/index.js";
11import { useDefaultProps } from "../DefaultPropsProvider/index.js";
12import { getStepUtilityClass } from "./stepClasses.js";
13import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
14const 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};
26const 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});
54const Step = /*#__PURE__*/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 = /*#__PURE__*/_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 /*#__PURE__*/_jsx(StepContext.Provider, {
115 value: contextValue,
116 children: connector && !alternativeLabel && index !== 0 ? /*#__PURE__*/_jsxs(React.Fragment, {
117 children: [connector, newChildren]
118 }) : newChildren
119 });
120});
121process.env.NODE_ENV !== "production" ? Step.propTypes /* remove-proptypes */ = {
122 // ┌────────────────────────────── Warning ──────────────────────────────┐
123 // │ These PropTypes are generated from the TypeScript type definitions. │
124 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
125 // └─────────────────────────────────────────────────────────────────────┘
126 /**
127 * Sets the step as active. Is passed to child components.
128 */
129 active: PropTypes.bool,
130 /**
131 * Should be `Step` sub-components such as `StepLabel`, `StepContent`.
132 */
133 children: PropTypes.node,
134 /**
135 * Override or extend the styles applied to the component.
136 */
137 classes: PropTypes.object,
138 /**
139 * @ignore
140 */
141 className: PropTypes.string,
142 /**
143 * Mark the step as completed. Is passed to child components.
144 */
145 completed: PropTypes.bool,
146 /**
147 * The component used for the root node.
148 * Either a string to use a HTML element or a component.
149 */
150 component: PropTypes.elementType,
151 /**
152 * If `true`, the step is disabled, will also disable the button if
153 * `StepButton` is a child of `Step`. Is passed to child components.
154 */
155 disabled: PropTypes.bool,
156 /**
157 * Expand the step.
158 * @default false
159 */
160 expanded: PropTypes.bool,
161 /**
162 * The position of the step.
163 * The prop defaults to the value inherited from the parent Stepper component.
164 */
165 index: integerPropType,
166 /**
167 * If `true`, the Step is displayed as rendered last.
168 * The prop defaults to the value inherited from the parent Stepper component.
169 */
170 last: PropTypes.bool,
171 /**
172 * The system prop that allows defining system overrides as well as additional CSS styles.
173 */
174 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
175} : void 0;
176export default Step;
\No newline at end of file