UNPKG

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