UNPKG

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