1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15 |
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
19 |
|
20 | var _clsx = _interopRequireDefault(require("clsx"));
|
21 |
|
22 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
23 |
|
24 | var _Paper = _interopRequireDefault(require("../Paper"));
|
25 |
|
26 | var _StepConnector = _interopRequireDefault(require("../StepConnector"));
|
27 |
|
28 | var styles = {
|
29 |
|
30 | root: {
|
31 | display: 'flex',
|
32 | padding: 24
|
33 | },
|
34 |
|
35 |
|
36 | horizontal: {
|
37 | flexDirection: 'row',
|
38 | alignItems: 'center'
|
39 | },
|
40 |
|
41 |
|
42 | vertical: {
|
43 | flexDirection: 'column'
|
44 | },
|
45 |
|
46 |
|
47 | alternativeLabel: {
|
48 | alignItems: 'flex-start'
|
49 | }
|
50 | };
|
51 | exports.styles = styles;
|
52 | var defaultConnector = React.createElement(_StepConnector.default, null);
|
53 | var Stepper = 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 = React.isValidElement(connectorProp) ? 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 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 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 | });
|
102 | process.env.NODE_ENV !== "production" ? Stepper.propTypes = {
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | |
109 |
|
110 |
|
111 |
|
112 | activeStep: _propTypes.default.number,
|
113 |
|
114 | |
115 |
|
116 |
|
117 |
|
118 | alternativeLabel: _propTypes.default.bool,
|
119 |
|
120 | |
121 |
|
122 |
|
123 | children: _propTypes.default.node,
|
124 |
|
125 | |
126 |
|
127 |
|
128 |
|
129 | classes: _propTypes.default.object,
|
130 |
|
131 | |
132 |
|
133 |
|
134 | className: _propTypes.default.string,
|
135 |
|
136 | |
137 |
|
138 |
|
139 | connector: _propTypes.default.element,
|
140 |
|
141 | |
142 |
|
143 |
|
144 | nonLinear: _propTypes.default.bool,
|
145 |
|
146 | |
147 |
|
148 |
|
149 | orientation: _propTypes.default.oneOf(['horizontal', 'vertical'])
|
150 | } : void 0;
|
151 |
|
152 | var _default = (0, _withStyles.default)(styles, {
|
153 | name: 'MuiStepper'
|
154 | })(Stepper);
|
155 |
|
156 | exports.default = _default; |
\ | No newline at end of file |