UNPKG

5.61 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import withStyles from '../styles/withStyles';
7import Typography from '../Typography';
8import StepIcon from '../StepIcon';
9export const styles = theme => ({
10 /* Styles applied to the root element. */
11 root: {
12 display: 'flex',
13 alignItems: 'center',
14 '&$alternativeLabel': {
15 flexDirection: 'column'
16 },
17 '&$disabled': {
18 cursor: 'default'
19 }
20 },
21
22 /* Styles applied to the root element if `orientation="horizontal"`. */
23 horizontal: {},
24
25 /* Styles applied to the root element if `orientation="vertical"`. */
26 vertical: {},
27
28 /* Styles applied to the `Typography` component which wraps `children`. */
29 label: {
30 color: theme.palette.text.secondary,
31 '&$active': {
32 color: theme.palette.text.primary,
33 fontWeight: 500
34 },
35 '&$completed': {
36 color: theme.palette.text.primary,
37 fontWeight: 500
38 },
39 '&$alternativeLabel': {
40 textAlign: 'center',
41 marginTop: 16
42 },
43 '&$error': {
44 color: theme.palette.error.main
45 }
46 },
47
48 /* Pseudo-class applied to the `Typography` component if `active={true}`. */
49 active: {},
50
51 /* Pseudo-class applied to the `Typography` component if `completed={true}`. */
52 completed: {},
53
54 /* Pseudo-class applied to the root element and `Typography` component if `error={true}`. */
55 error: {},
56
57 /* Pseudo-class applied to the root element and `Typography` component if `disabled={true}`. */
58 disabled: {},
59
60 /* Styles applied to the `icon` container element. */
61 iconContainer: {
62 flexShrink: 0,
63 // Fix IE 11 issue
64 display: 'flex',
65 paddingRight: 8,
66 '&$alternativeLabel': {
67 paddingRight: 0
68 }
69 },
70
71 /* Pseudo-class applied to the root and icon container and `Typography` if `alternativeLabel={true}`. */
72 alternativeLabel: {},
73
74 /* Styles applied to the container element which wraps `Typography` and `optional`. */
75 labelContainer: {
76 width: '100%'
77 }
78});
79const StepLabel = /*#__PURE__*/React.forwardRef(function StepLabel(props, ref) {
80 const {
81 // eslint-disable-next-line react/prop-types
82 active = false,
83 // eslint-disable-next-line react/prop-types
84 alternativeLabel = false,
85 children,
86 classes,
87 className,
88 // eslint-disable-next-line react/prop-types
89 completed = false,
90 disabled = false,
91 error = false,
92 icon,
93 optional,
94 // eslint-disable-next-line react/prop-types
95 orientation = 'horizontal',
96 StepIconComponent: StepIconComponentProp,
97 StepIconProps
98 } = props,
99 other = _objectWithoutPropertiesLoose(props, ["active", "alternativeLabel", "children", "classes", "className", "completed", "disabled", "error", "expanded", "icon", "last", "optional", "orientation", "StepIconComponent", "StepIconProps"]);
100
101 let StepIconComponent = StepIconComponentProp;
102
103 if (icon && !StepIconComponent) {
104 StepIconComponent = StepIcon;
105 }
106
107 return /*#__PURE__*/React.createElement("span", _extends({
108 className: clsx(classes.root, classes[orientation], className, disabled && classes.disabled, alternativeLabel && classes.alternativeLabel, error && classes.error),
109 ref: ref
110 }, other), icon || StepIconComponent ? /*#__PURE__*/React.createElement("span", {
111 className: clsx(classes.iconContainer, alternativeLabel && classes.alternativeLabel)
112 }, /*#__PURE__*/React.createElement(StepIconComponent, _extends({
113 completed: completed,
114 active: active,
115 error: error,
116 icon: icon
117 }, StepIconProps))) : null, /*#__PURE__*/React.createElement("span", {
118 className: classes.labelContainer
119 }, children ? /*#__PURE__*/React.createElement(Typography, {
120 variant: "body2",
121 component: "span",
122 display: "block",
123 className: clsx(classes.label, alternativeLabel && classes.alternativeLabel, completed && classes.completed, active && classes.active, error && classes.error)
124 }, children) : null, optional));
125});
126process.env.NODE_ENV !== "production" ? StepLabel.propTypes = {
127 // ----------------------------- Warning --------------------------------
128 // | These PropTypes are generated from the TypeScript type definitions |
129 // | To update them edit the d.ts file and run "yarn proptypes" |
130 // ----------------------------------------------------------------------
131
132 /**
133 * In most cases will simply be a string containing a title for the label.
134 */
135 children: PropTypes.node,
136
137 /**
138 * Override or extend the styles applied to the component.
139 * See [CSS API](#css) below for more details.
140 */
141 classes: PropTypes.object,
142
143 /**
144 * @ignore
145 */
146 className: PropTypes.string,
147
148 /**
149 * Mark the step as disabled, will also disable the button if
150 * `StepLabelButton` is a child of `StepLabel`. Is passed to child components.
151 */
152 disabled: PropTypes.bool,
153
154 /**
155 * Mark the step as failed.
156 */
157 error: PropTypes.bool,
158
159 /**
160 * Override the default label of the step icon.
161 */
162 icon: PropTypes.node,
163
164 /**
165 * The optional node to display.
166 */
167 optional: PropTypes.node,
168
169 /**
170 * The component to render in place of the [`StepIcon`](/api/step-icon/).
171 */
172 StepIconComponent: PropTypes.elementType,
173
174 /**
175 * Props applied to the [`StepIcon`](/api/step-icon/) element.
176 */
177 StepIconProps: PropTypes.object
178} : void 0;
179StepLabel.muiName = 'StepLabel';
180export default withStyles(styles, {
181 name: 'MuiStepLabel'
182})(StepLabel);
\No newline at end of file