UNPKG

6.08 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _extends from "@babel/runtime/helpers/esm/extends";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import { integerPropType } from '@mui/utils';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import StepperContext from '../Stepper/StepperContext';
9import StepContext from './StepContext';
10import useThemeProps from '../styles/useThemeProps';
11import styled from '../styles/styled';
12import { getStepUtilityClass } from './stepClasses';
13import { jsxs as _jsxs } from "react/jsx-runtime";
14import { jsx as _jsx } from "react/jsx-runtime";
15
16var useUtilityClasses = function useUtilityClasses(ownerState) {
17 var classes = ownerState.classes,
18 orientation = ownerState.orientation,
19 alternativeLabel = ownerState.alternativeLabel,
20 completed = ownerState.completed;
21 var slots = {
22 root: ['root', orientation, alternativeLabel && 'alternativeLabel', completed && 'completed']
23 };
24 return composeClasses(slots, getStepUtilityClass, classes);
25};
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 = useThemeProps({
46 props: inProps,
47 name: 'MuiStep'
48 });
49
50 var activeProp = props.active,
51 children = props.children,
52 className = props.className,
53 completedProp = props.completed,
54 disabledProp = props.disabled,
55 _props$expanded = props.expanded,
56 expanded = _props$expanded === void 0 ? false : _props$expanded,
57 index = props.index,
58 last = props.last,
59 other = _objectWithoutProperties(props, ["active", "children", "className", "completed", "disabled", "expanded", "index", "last"]);
60
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
68 var _activeProp = activeProp,
69 active = _activeProp === void 0 ? false : _activeProp,
70 _completedProp = completedProp,
71 completed = _completedProp === void 0 ? false : _completedProp,
72 _disabledProp = disabledProp,
73 disabled = _disabledProp === void 0 ? false : _disabledProp;
74
75 if (activeStep === index) {
76 active = activeProp !== undefined ? activeProp : true;
77 } else if (!nonLinear && activeStep > index) {
78 completed = completedProp !== undefined ? completedProp : true;
79 } else if (!nonLinear && activeStep < index) {
80 disabled = disabledProp !== undefined ? disabledProp : true;
81 }
82
83 var contextValue = React.useMemo(function () {
84 return {
85 index: index,
86 last: last,
87 expanded: expanded,
88 icon: index + 1,
89 active: active,
90 completed: completed,
91 disabled: disabled
92 };
93 }, [index, last, expanded, active, completed, disabled]);
94
95 var ownerState = _extends({}, props, {
96 active: active,
97 orientation: orientation,
98 alternativeLabel: alternativeLabel,
99 completed: completed,
100 disabled: disabled,
101 expanded: expanded
102 });
103
104 var classes = useUtilityClasses(ownerState);
105
106 var newChildren = /*#__PURE__*/_jsxs(StepRoot, _extends({
107 className: clsx(classes.root, className),
108 ref: ref,
109 ownerState: ownerState
110 }, other, {
111 children: [connector && alternativeLabel && index !== 0 ? connector : null, children]
112 }));
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
122/* remove-proptypes */
123= {
124 // ----------------------------- Warning --------------------------------
125 // | These PropTypes are generated from the TypeScript type definitions |
126 // | To update them edit the d.ts file and run "yarn proptypes" |
127 // ----------------------------------------------------------------------
128
129 /**
130 * Sets the step as active. Is passed to child components.
131 */
132 active: PropTypes.bool,
133
134 /**
135 * Should be `Step` sub-components such as `StepLabel`, `StepContent`.
136 */
137 children: PropTypes.node,
138
139 /**
140 * Override or extend the styles applied to the component.
141 */
142 classes: PropTypes.object,
143
144 /**
145 * @ignore
146 */
147 className: PropTypes.string,
148
149 /**
150 * Mark the step as completed. Is passed to child components.
151 */
152 completed: PropTypes.bool,
153
154 /**
155 * If `true`, the step is disabled, will also disable the button if
156 * `StepButton` is a child of `Step`. Is passed to child components.
157 */
158 disabled: PropTypes.bool,
159
160 /**
161 * Expand the step.
162 * @default false
163 */
164 expanded: PropTypes.bool,
165
166 /**
167 * The position of the step.
168 * The prop defaults to the value inherited from the parent Stepper component.
169 */
170 index: integerPropType,
171
172 /**
173 * If `true`, the Step is displayed as rendered last.
174 * The prop defaults to the value inherited from the parent Stepper component.
175 */
176 last: PropTypes.bool,
177
178 /**
179 * The system prop that allows defining system overrides as well as additional CSS styles.
180 */
181 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
182} : void 0;
183export default Step;
\No newline at end of file