UNPKG

5.14 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
23
24var _Paper = _interopRequireDefault(require("../Paper"));
25
26var _StepConnector = _interopRequireDefault(require("../StepConnector"));
27
28var styles = {
29 /* Styles applied to the root element. */
30 root: {
31 display: 'flex',
32 padding: 24
33 },
34
35 /* Styles applied to the root element if `orientation="horizontal"`. */
36 horizontal: {
37 flexDirection: 'row',
38 alignItems: 'center'
39 },
40
41 /* Styles applied to the root element if `orientation="vertical"`. */
42 vertical: {
43 flexDirection: 'column'
44 },
45
46 /* Styles applied to the root element if `alternativeLabel={true}`. */
47 alternativeLabel: {
48 alignItems: 'flex-start'
49 }
50};
51exports.styles = styles;
52var defaultConnector = /*#__PURE__*/React.createElement(_StepConnector.default, null);
53var Stepper = /*#__PURE__*/React.forwardRef(function Stepper(props, ref) {
54 var _props$activeStep = props.activeStep,
55 activeStep = _props$activeStep === void 0 ? 0 : _props$activeStep,
56 _props$alternativeLab = props.alternativeLabel,
57 alternativeLabel = _props$alternativeLab === void 0 ? false : _props$alternativeLab,
58 children = props.children,
59 classes = props.classes,
60 className = props.className,
61 _props$connector = props.connector,
62 connectorProp = _props$connector === void 0 ? defaultConnector : _props$connector,
63 _props$nonLinear = props.nonLinear,
64 nonLinear = _props$nonLinear === void 0 ? false : _props$nonLinear,
65 _props$orientation = props.orientation,
66 orientation = _props$orientation === void 0 ? 'horizontal' : _props$orientation,
67 other = (0, _objectWithoutProperties2.default)(props, ["activeStep", "alternativeLabel", "children", "classes", "className", "connector", "nonLinear", "orientation"]);
68 var connector = /*#__PURE__*/React.isValidElement(connectorProp) ? /*#__PURE__*/React.cloneElement(connectorProp, {
69 orientation: orientation
70 }) : null;
71 var childrenArray = React.Children.toArray(children);
72 var steps = childrenArray.map(function (step, index) {
73 var state = {
74 index: index,
75 active: false,
76 completed: false,
77 disabled: false
78 };
79
80 if (activeStep === index) {
81 state.active = true;
82 } else if (!nonLinear && activeStep > index) {
83 state.completed = true;
84 } else if (!nonLinear && activeStep < index) {
85 state.disabled = true;
86 }
87
88 return /*#__PURE__*/React.cloneElement(step, (0, _extends2.default)({
89 alternativeLabel: alternativeLabel,
90 connector: connector,
91 last: index + 1 === childrenArray.length,
92 orientation: orientation
93 }, state, step.props));
94 });
95 return /*#__PURE__*/React.createElement(_Paper.default, (0, _extends2.default)({
96 square: true,
97 elevation: 0,
98 className: (0, _clsx.default)(classes.root, classes[orientation], className, alternativeLabel && classes.alternativeLabel),
99 ref: ref
100 }, other), steps);
101});
102process.env.NODE_ENV !== "production" ? Stepper.propTypes = {
103 // ----------------------------- Warning --------------------------------
104 // | These PropTypes are generated from the TypeScript type definitions |
105 // | To update them edit the d.ts file and run "yarn proptypes" |
106 // ----------------------------------------------------------------------
107
108 /**
109 * Set the active step (zero based index).
110 * Set to -1 to disable all the steps.
111 */
112 activeStep: _propTypes.default.number,
113
114 /**
115 * If set to 'true' and orientation is horizontal,
116 * then the step label will be positioned under the icon.
117 */
118 alternativeLabel: _propTypes.default.bool,
119
120 /**
121 * Two or more `<Step />` components.
122 */
123 children: _propTypes.default.node,
124
125 /**
126 * Override or extend the styles applied to the component.
127 * See [CSS API](#css) below for more details.
128 */
129 classes: _propTypes.default.object,
130
131 /**
132 * @ignore
133 */
134 className: _propTypes.default.string,
135
136 /**
137 * An element to be placed between each step.
138 */
139 connector: _propTypes.default.element,
140
141 /**
142 * If set the `Stepper` will not assist in controlling steps for linear flow.
143 */
144 nonLinear: _propTypes.default.bool,
145
146 /**
147 * The stepper orientation (layout flow direction).
148 */
149 orientation: _propTypes.default.oneOf(['horizontal', 'vertical'])
150} : void 0;
151
152var _default = (0, _withStyles.default)(styles, {
153 name: 'MuiStepper'
154})(Stepper);
155
156exports.default = _default;
\No newline at end of file