UNPKG

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