UNPKG

8.35 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _extends from "@babel/runtime/helpers/esm/extends";
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import styled from '../styles/styled';
9import useThemeProps from '../styles/useThemeProps';
10import StepIcon from '../StepIcon';
11import StepperContext from '../Stepper/StepperContext';
12import StepContext from '../Step/StepContext';
13import stepLabelClasses, { getStepLabelUtilityClass } from './stepLabelClasses';
14import { jsx as _jsx } from "react/jsx-runtime";
15import { jsxs as _jsxs } from "react/jsx-runtime";
16
17var useUtilityClasses = function useUtilityClasses(ownerState) {
18 var classes = ownerState.classes,
19 orientation = ownerState.orientation,
20 active = ownerState.active,
21 completed = ownerState.completed,
22 error = ownerState.error,
23 disabled = ownerState.disabled,
24 alternativeLabel = ownerState.alternativeLabel;
25 var slots = {
26 root: ['root', orientation, error && 'error', disabled && 'disabled', alternativeLabel && 'alternativeLabel'],
27 label: ['label', active && 'active', completed && 'completed', error && 'error', disabled && 'disabled', alternativeLabel && 'alternativeLabel'],
28 iconContainer: ['iconContainer', active && 'active', completed && 'completed', error && 'error', disabled && 'disabled', alternativeLabel && 'alternativeLabel'],
29 labelContainer: ['labelContainer']
30 };
31 return composeClasses(slots, getStepLabelUtilityClass, classes);
32};
33
34var StepLabelRoot = styled('span', {
35 name: 'MuiStepLabel',
36 slot: 'Root',
37 overridesResolver: function overridesResolver(props, styles) {
38 var ownerState = props.ownerState;
39 return [styles.root, styles[ownerState.orientation]];
40 }
41})(function (_ref) {
42 var _extends2;
43
44 var ownerState = _ref.ownerState;
45 return _extends((_extends2 = {
46 display: 'flex',
47 alignItems: 'center'
48 }, _defineProperty(_extends2, "&.".concat(stepLabelClasses.alternativeLabel), {
49 flexDirection: 'column'
50 }), _defineProperty(_extends2, "&.".concat(stepLabelClasses.disabled), {
51 cursor: 'default'
52 }), _extends2), ownerState.orientation === 'vertical' && {
53 textAlign: 'left',
54 padding: '8px 0'
55 });
56});
57var StepLabelLabel = styled('span', {
58 name: 'MuiStepLabel',
59 slot: 'Label',
60 overridesResolver: function overridesResolver(props, styles) {
61 return styles.label;
62 }
63})(function (_ref2) {
64 var _extends3;
65
66 var theme = _ref2.theme;
67 return _extends({}, theme.typography.body2, (_extends3 = {
68 display: 'block',
69 transition: theme.transitions.create('color', {
70 duration: theme.transitions.duration.shortest
71 })
72 }, _defineProperty(_extends3, "&.".concat(stepLabelClasses.active), {
73 color: (theme.vars || theme).palette.text.primary,
74 fontWeight: 500
75 }), _defineProperty(_extends3, "&.".concat(stepLabelClasses.completed), {
76 color: (theme.vars || theme).palette.text.primary,
77 fontWeight: 500
78 }), _defineProperty(_extends3, "&.".concat(stepLabelClasses.alternativeLabel), {
79 textAlign: 'center',
80 marginTop: 16
81 }), _defineProperty(_extends3, "&.".concat(stepLabelClasses.error), {
82 color: (theme.vars || theme).palette.error.main
83 }), _extends3));
84});
85var StepLabelIconContainer = styled('span', {
86 name: 'MuiStepLabel',
87 slot: 'IconContainer',
88 overridesResolver: function overridesResolver(props, styles) {
89 return styles.iconContainer;
90 }
91})(function () {
92 return _defineProperty({
93 flexShrink: 0,
94 // Fix IE11 issue
95 display: 'flex',
96 paddingRight: 8
97 }, "&.".concat(stepLabelClasses.alternativeLabel), {
98 paddingRight: 0
99 });
100});
101var StepLabelLabelContainer = styled('span', {
102 name: 'MuiStepLabel',
103 slot: 'LabelContainer',
104 overridesResolver: function overridesResolver(props, styles) {
105 return styles.labelContainer;
106 }
107})(function (_ref4) {
108 var theme = _ref4.theme;
109 return {
110 width: '100%',
111 color: (theme.vars || theme).palette.text.secondary
112 };
113});
114var StepLabel = /*#__PURE__*/React.forwardRef(function StepLabel(inProps, ref) {
115 var props = useThemeProps({
116 props: inProps,
117 name: 'MuiStepLabel'
118 });
119
120 var children = props.children,
121 className = props.className,
122 _props$componentsProp = props.componentsProps,
123 componentsProps = _props$componentsProp === void 0 ? {} : _props$componentsProp,
124 _props$error = props.error,
125 error = _props$error === void 0 ? false : _props$error,
126 iconProp = props.icon,
127 optional = props.optional,
128 StepIconComponentProp = props.StepIconComponent,
129 StepIconProps = props.StepIconProps,
130 other = _objectWithoutProperties(props, ["children", "className", "componentsProps", "error", "icon", "optional", "StepIconComponent", "StepIconProps"]);
131
132 var _React$useContext = React.useContext(StepperContext),
133 alternativeLabel = _React$useContext.alternativeLabel,
134 orientation = _React$useContext.orientation;
135
136 var _React$useContext2 = React.useContext(StepContext),
137 active = _React$useContext2.active,
138 disabled = _React$useContext2.disabled,
139 completed = _React$useContext2.completed,
140 iconContext = _React$useContext2.icon;
141
142 var icon = iconProp || iconContext;
143 var StepIconComponent = StepIconComponentProp;
144
145 if (icon && !StepIconComponent) {
146 StepIconComponent = StepIcon;
147 }
148
149 var ownerState = _extends({}, props, {
150 active: active,
151 alternativeLabel: alternativeLabel,
152 completed: completed,
153 disabled: disabled,
154 error: error,
155 orientation: orientation
156 });
157
158 var classes = useUtilityClasses(ownerState);
159 return /*#__PURE__*/_jsxs(StepLabelRoot, _extends({
160 className: clsx(classes.root, className),
161 ref: ref,
162 ownerState: ownerState
163 }, other, {
164 children: [icon || StepIconComponent ? /*#__PURE__*/_jsx(StepLabelIconContainer, {
165 className: classes.iconContainer,
166 ownerState: ownerState,
167 children: /*#__PURE__*/_jsx(StepIconComponent, _extends({
168 completed: completed,
169 active: active,
170 error: error,
171 icon: icon
172 }, StepIconProps))
173 }) : null, /*#__PURE__*/_jsxs(StepLabelLabelContainer, {
174 className: classes.labelContainer,
175 ownerState: ownerState,
176 children: [children ? /*#__PURE__*/_jsx(StepLabelLabel, _extends({
177 className: classes.label,
178 ownerState: ownerState
179 }, componentsProps.label, {
180 children: children
181 })) : null, optional]
182 })]
183 }));
184});
185process.env.NODE_ENV !== "production" ? StepLabel.propTypes
186/* remove-proptypes */
187= {
188 // ----------------------------- Warning --------------------------------
189 // | These PropTypes are generated from the TypeScript type definitions |
190 // | To update them edit the d.ts file and run "yarn proptypes" |
191 // ----------------------------------------------------------------------
192
193 /**
194 * In most cases will simply be a string containing a title for the label.
195 */
196 children: PropTypes.node,
197
198 /**
199 * Override or extend the styles applied to the component.
200 */
201 classes: PropTypes.object,
202
203 /**
204 * @ignore
205 */
206 className: PropTypes.string,
207
208 /**
209 * The props used for each slot inside.
210 * @default {}
211 */
212 componentsProps: PropTypes.shape({
213 label: PropTypes.object
214 }),
215
216 /**
217 * If `true`, the step is marked as failed.
218 * @default false
219 */
220 error: PropTypes.bool,
221
222 /**
223 * Override the default label of the step icon.
224 */
225 icon: PropTypes.node,
226
227 /**
228 * The optional node to display.
229 */
230 optional: PropTypes.node,
231
232 /**
233 * The component to render in place of the [`StepIcon`](/material-ui/api/step-icon/).
234 */
235 StepIconComponent: PropTypes.elementType,
236
237 /**
238 * Props applied to the [`StepIcon`](/material-ui/api/step-icon/) element.
239 */
240 StepIconProps: PropTypes.object,
241
242 /**
243 * The system prop that allows defining system overrides as well as additional CSS styles.
244 */
245 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
246} : void 0;
247StepLabel.muiName = 'StepLabel';
248export default StepLabel;
\No newline at end of file