UNPKG

5.14 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import withStyles from '../styles/withStyles';
8import Paper from '../Paper';
9import capitalize from '../utils/capitalize';
10import LinearProgress from '../LinearProgress';
11export var styles = function styles(theme) {
12 return {
13 /* Styles applied to the root element. */
14 root: {
15 display: 'flex',
16 flexDirection: 'row',
17 justifyContent: 'space-between',
18 alignItems: 'center',
19 background: theme.palette.background.default,
20 padding: 8
21 },
22
23 /* Styles applied to the root element if `position="bottom"`. */
24 positionBottom: {
25 position: 'fixed',
26 bottom: 0,
27 left: 0,
28 right: 0,
29 zIndex: theme.zIndex.mobileStepper
30 },
31
32 /* Styles applied to the root element if `position="top"`. */
33 positionTop: {
34 position: 'fixed',
35 top: 0,
36 left: 0,
37 right: 0,
38 zIndex: theme.zIndex.mobileStepper
39 },
40
41 /* Styles applied to the root element if `position="static"`. */
42 positionStatic: {},
43
44 /* Styles applied to the dots container if `variant="dots"`. */
45 dots: {
46 display: 'flex',
47 flexDirection: 'row'
48 },
49
50 /* Styles applied to each dot if `variant="dots"`. */
51 dot: {
52 backgroundColor: theme.palette.action.disabled,
53 borderRadius: '50%',
54 width: 8,
55 height: 8,
56 margin: '0 2px'
57 },
58
59 /* Styles applied to a dot if `variant="dots"` and this is the active step. */
60 dotActive: {
61 backgroundColor: theme.palette.primary.main
62 },
63
64 /* Styles applied to the Linear Progress component if `variant="progress"`. */
65 progress: {
66 width: '50%'
67 }
68 };
69};
70var MobileStepper = /*#__PURE__*/React.forwardRef(function MobileStepper(props, ref) {
71 var _props$activeStep = props.activeStep,
72 activeStep = _props$activeStep === void 0 ? 0 : _props$activeStep,
73 backButton = props.backButton,
74 classes = props.classes,
75 className = props.className,
76 LinearProgressProps = props.LinearProgressProps,
77 nextButton = props.nextButton,
78 _props$position = props.position,
79 position = _props$position === void 0 ? 'bottom' : _props$position,
80 steps = props.steps,
81 _props$variant = props.variant,
82 variant = _props$variant === void 0 ? 'dots' : _props$variant,
83 other = _objectWithoutProperties(props, ["activeStep", "backButton", "classes", "className", "LinearProgressProps", "nextButton", "position", "steps", "variant"]);
84
85 return /*#__PURE__*/React.createElement(Paper, _extends({
86 square: true,
87 elevation: 0,
88 className: clsx(classes.root, classes["position".concat(capitalize(position))], className),
89 ref: ref
90 }, other), backButton, variant === 'text' && /*#__PURE__*/React.createElement(React.Fragment, null, activeStep + 1, " / ", steps), variant === 'dots' && /*#__PURE__*/React.createElement("div", {
91 className: classes.dots
92 }, _toConsumableArray(new Array(steps)).map(function (_, index) {
93 return /*#__PURE__*/React.createElement("div", {
94 key: index,
95 className: clsx(classes.dot, index === activeStep && classes.dotActive)
96 });
97 })), variant === 'progress' && /*#__PURE__*/React.createElement(LinearProgress, _extends({
98 className: classes.progress,
99 variant: "determinate",
100 value: Math.ceil(activeStep / (steps - 1) * 100)
101 }, LinearProgressProps)), nextButton);
102});
103process.env.NODE_ENV !== "production" ? MobileStepper.propTypes = {
104 // ----------------------------- Warning --------------------------------
105 // | These PropTypes are generated from the TypeScript type definitions |
106 // | To update them edit the d.ts file and run "yarn proptypes" |
107 // ----------------------------------------------------------------------
108
109 /**
110 * Set the active step (zero based index).
111 * Defines which dot is highlighted when the variant is 'dots'.
112 */
113 activeStep: PropTypes.number,
114
115 /**
116 * A back button element. For instance, it can be a `Button` or an `IconButton`.
117 */
118 backButton: PropTypes.node,
119
120 /**
121 * Override or extend the styles applied to the component.
122 * See [CSS API](#css) below for more details.
123 */
124 classes: PropTypes.object,
125
126 /**
127 * @ignore
128 */
129 className: PropTypes.string,
130
131 /**
132 * Props applied to the `LinearProgress` element.
133 */
134 LinearProgressProps: PropTypes.object,
135
136 /**
137 * A next button element. For instance, it can be a `Button` or an `IconButton`.
138 */
139 nextButton: PropTypes.node,
140
141 /**
142 * Set the positioning type.
143 */
144 position: PropTypes.oneOf(['bottom', 'static', 'top']),
145
146 /**
147 * The total steps.
148 */
149 steps: PropTypes.number.isRequired,
150
151 /**
152 * The variant to use.
153 */
154 variant: PropTypes.oneOf(['dots', 'progress', 'text'])
155} : void 0;
156export default withStyles(styles, {
157 name: 'MuiMobileStepper'
158})(MobileStepper);
\No newline at end of file