UNPKG

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