UNPKG

6.25 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _clsx = _interopRequireDefault(require("clsx"));
13var _integerPropType = _interopRequireDefault(require("@mui/utils/integerPropType"));
14var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
15var _StepperContext = _interopRequireDefault(require("../Stepper/StepperContext"));
16var _StepContext = _interopRequireDefault(require("./StepContext"));
17var _zeroStyled = require("../zero-styled");
18var _DefaultPropsProvider = require("../DefaultPropsProvider");
19var _stepClasses = require("./stepClasses");
20var _jsxRuntime = require("react/jsx-runtime");
21const useUtilityClasses = ownerState => {
22 const {
23 classes,
24 orientation,
25 alternativeLabel,
26 completed
27 } = ownerState;
28 const slots = {
29 root: ['root', orientation, alternativeLabel && 'alternativeLabel', completed && 'completed']
30 };
31 return (0, _composeClasses.default)(slots, _stepClasses.getStepUtilityClass, classes);
32};
33const StepRoot = (0, _zeroStyled.styled)('div', {
34 name: 'MuiStep',
35 slot: 'Root',
36 overridesResolver: (props, styles) => {
37 const {
38 ownerState
39 } = props;
40 return [styles.root, styles[ownerState.orientation], ownerState.alternativeLabel && styles.alternativeLabel, ownerState.completed && styles.completed];
41 }
42})({
43 variants: [{
44 props: {
45 orientation: 'horizontal'
46 },
47 style: {
48 paddingLeft: 8,
49 paddingRight: 8
50 }
51 }, {
52 props: {
53 alternativeLabel: true
54 },
55 style: {
56 flex: 1,
57 position: 'relative'
58 }
59 }]
60});
61const Step = /*#__PURE__*/React.forwardRef(function Step(inProps, ref) {
62 const props = (0, _DefaultPropsProvider.useDefaultProps)({
63 props: inProps,
64 name: 'MuiStep'
65 });
66 const {
67 active: activeProp,
68 children,
69 className,
70 component = 'div',
71 completed: completedProp,
72 disabled: disabledProp,
73 expanded = false,
74 index,
75 last,
76 ...other
77 } = props;
78 const {
79 activeStep,
80 connector,
81 alternativeLabel,
82 orientation,
83 nonLinear
84 } = React.useContext(_StepperContext.default);
85 let [active = false, completed = false, disabled = false] = [activeProp, completedProp, disabledProp];
86 if (activeStep === index) {
87 active = activeProp !== undefined ? activeProp : true;
88 } else if (!nonLinear && activeStep > index) {
89 completed = completedProp !== undefined ? completedProp : true;
90 } else if (!nonLinear && activeStep < index) {
91 disabled = disabledProp !== undefined ? disabledProp : true;
92 }
93 const contextValue = React.useMemo(() => ({
94 index,
95 last,
96 expanded,
97 icon: index + 1,
98 active,
99 completed,
100 disabled
101 }), [index, last, expanded, active, completed, disabled]);
102 const ownerState = {
103 ...props,
104 active,
105 orientation,
106 alternativeLabel,
107 completed,
108 disabled,
109 expanded,
110 component
111 };
112 const classes = useUtilityClasses(ownerState);
113 const newChildren = /*#__PURE__*/(0, _jsxRuntime.jsxs)(StepRoot, {
114 as: component,
115 className: (0, _clsx.default)(classes.root, className),
116 ref: ref,
117 ownerState: ownerState,
118 ...other,
119 children: [connector && alternativeLabel && index !== 0 ? connector : null, children]
120 });
121 return /*#__PURE__*/(0, _jsxRuntime.jsx)(_StepContext.default.Provider, {
122 value: contextValue,
123 children: connector && !alternativeLabel && index !== 0 ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
124 children: [connector, newChildren]
125 }) : newChildren
126 });
127});
128process.env.NODE_ENV !== "production" ? Step.propTypes /* remove-proptypes */ = {
129 // ┌────────────────────────────── Warning ──────────────────────────────┐
130 // │ These PropTypes are generated from the TypeScript type definitions. │
131 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
132 // └─────────────────────────────────────────────────────────────────────┘
133 /**
134 * Sets the step as active. Is passed to child components.
135 */
136 active: _propTypes.default.bool,
137 /**
138 * Should be `Step` sub-components such as `StepLabel`, `StepContent`.
139 */
140 children: _propTypes.default.node,
141 /**
142 * Override or extend the styles applied to the component.
143 */
144 classes: _propTypes.default.object,
145 /**
146 * @ignore
147 */
148 className: _propTypes.default.string,
149 /**
150 * Mark the step as completed. Is passed to child components.
151 */
152 completed: _propTypes.default.bool,
153 /**
154 * The component used for the root node.
155 * Either a string to use a HTML element or a component.
156 */
157 component: _propTypes.default.elementType,
158 /**
159 * If `true`, the step is disabled, will also disable the button if
160 * `StepButton` is a child of `Step`. Is passed to child components.
161 */
162 disabled: _propTypes.default.bool,
163 /**
164 * Expand the step.
165 * @default false
166 */
167 expanded: _propTypes.default.bool,
168 /**
169 * The position of the step.
170 * The prop defaults to the value inherited from the parent Stepper component.
171 */
172 index: _integerPropType.default,
173 /**
174 * If `true`, the Step is displayed as rendered last.
175 * The prop defaults to the value inherited from the parent Stepper component.
176 */
177 last: _propTypes.default.bool,
178 /**
179 * The system prop that allows defining system overrides as well as additional CSS styles.
180 */
181 sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
182} : void 0;
183var _default = exports.default = Step;
\No newline at end of file