UNPKG

5.07 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 { styled } from "../zero-styled/index.js";
9import { useDefaultProps } from "../DefaultPropsProvider/index.js";
10import { getStepperUtilityClass } from "./stepperClasses.js";
11import StepConnector from "../StepConnector/index.js";
12import StepperContext from "./StepperContext.js";
13import { jsx as _jsx } from "react/jsx-runtime";
14const useUtilityClasses = ownerState => {
15 const {
16 orientation,
17 nonLinear,
18 alternativeLabel,
19 classes
20 } = ownerState;
21 const slots = {
22 root: ['root', orientation, nonLinear && 'nonLinear', alternativeLabel && 'alternativeLabel']
23 };
24 return composeClasses(slots, getStepperUtilityClass, classes);
25};
26const StepperRoot = styled('div', {
27 name: 'MuiStepper',
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.nonLinear && styles.nonLinear];
34 }
35})({
36 display: 'flex',
37 variants: [{
38 props: {
39 orientation: 'horizontal'
40 },
41 style: {
42 flexDirection: 'row',
43 alignItems: 'center'
44 }
45 }, {
46 props: {
47 orientation: 'vertical'
48 },
49 style: {
50 flexDirection: 'column'
51 }
52 }, {
53 props: {
54 alternativeLabel: true
55 },
56 style: {
57 alignItems: 'flex-start'
58 }
59 }]
60});
61const defaultConnector = /*#__PURE__*/_jsx(StepConnector, {});
62const Stepper = /*#__PURE__*/React.forwardRef(function Stepper(inProps, ref) {
63 const props = useDefaultProps({
64 props: inProps,
65 name: 'MuiStepper'
66 });
67 const {
68 activeStep = 0,
69 alternativeLabel = false,
70 children,
71 className,
72 component = 'div',
73 connector = defaultConnector,
74 nonLinear = false,
75 orientation = 'horizontal',
76 ...other
77 } = props;
78 const ownerState = {
79 ...props,
80 nonLinear,
81 alternativeLabel,
82 orientation,
83 component
84 };
85 const classes = useUtilityClasses(ownerState);
86 const childrenArray = React.Children.toArray(children).filter(Boolean);
87 const steps = childrenArray.map((step, index) => {
88 return /*#__PURE__*/React.cloneElement(step, {
89 index,
90 last: index + 1 === childrenArray.length,
91 ...step.props
92 });
93 });
94 const contextValue = React.useMemo(() => ({
95 activeStep,
96 alternativeLabel,
97 connector,
98 nonLinear,
99 orientation
100 }), [activeStep, alternativeLabel, connector, nonLinear, orientation]);
101 return /*#__PURE__*/_jsx(StepperContext.Provider, {
102 value: contextValue,
103 children: /*#__PURE__*/_jsx(StepperRoot, {
104 as: component,
105 ownerState: ownerState,
106 className: clsx(classes.root, className),
107 ref: ref,
108 ...other,
109 children: steps
110 })
111 });
112});
113process.env.NODE_ENV !== "production" ? Stepper.propTypes /* remove-proptypes */ = {
114 // ┌────────────────────────────── Warning ──────────────────────────────┐
115 // │ These PropTypes are generated from the TypeScript type definitions. │
116 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
117 // └─────────────────────────────────────────────────────────────────────┘
118 /**
119 * Set the active step (zero based index).
120 * Set to -1 to disable all the steps.
121 * @default 0
122 */
123 activeStep: integerPropType,
124 /**
125 * If set to 'true' and orientation is horizontal,
126 * then the step label will be positioned under the icon.
127 * @default false
128 */
129 alternativeLabel: PropTypes.bool,
130 /**
131 * Two or more `<Step />` components.
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 * The component used for the root node.
144 * Either a string to use a HTML element or a component.
145 */
146 component: PropTypes.elementType,
147 /**
148 * An element to be placed between each step.
149 * @default <StepConnector />
150 */
151 connector: PropTypes.element,
152 /**
153 * If set the `Stepper` will not assist in controlling steps for linear flow.
154 * @default false
155 */
156 nonLinear: PropTypes.bool,
157 /**
158 * The component orientation (layout flow direction).
159 * @default 'horizontal'
160 */
161 orientation: PropTypes.oneOf(['horizontal', 'vertical']),
162 /**
163 * The system prop that allows defining system overrides as well as additional CSS styles.
164 */
165 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
166} : void 0;
167export default Stepper;
\No newline at end of file