UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

132 lines (119 loc) 4.22 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import withStyles from '../styles/withStyles'; import Paper from '../Paper'; import StepConnector from '../StepConnector'; export var styles = { /* Styles applied to the root element. */ root: { display: 'flex', padding: 24 }, /* Styles applied to the root element if `orientation="horizontal"`. */ horizontal: { flexDirection: 'row', alignItems: 'center' }, /* Styles applied to the root element if `orientation="vertical"`. */ vertical: { flexDirection: 'column' }, /* Styles applied to the root element if `alternativeLabel={true}`. */ alternativeLabel: { alignItems: 'flex-start' } }; var defaultConnector = React.createElement(StepConnector, null); var Stepper = React.forwardRef(function Stepper(props, ref) { var _props$activeStep = props.activeStep, activeStep = _props$activeStep === void 0 ? 0 : _props$activeStep, _props$alternativeLab = props.alternativeLabel, alternativeLabel = _props$alternativeLab === void 0 ? false : _props$alternativeLab, children = props.children, classes = props.classes, classNameProp = props.className, _props$connector = props.connector, connectorProp = _props$connector === void 0 ? defaultConnector : _props$connector, _props$nonLinear = props.nonLinear, nonLinear = _props$nonLinear === void 0 ? false : _props$nonLinear, _props$orientation = props.orientation, orientation = _props$orientation === void 0 ? 'horizontal' : _props$orientation, other = _objectWithoutProperties(props, ["activeStep", "alternativeLabel", "children", "classes", "className", "connector", "nonLinear", "orientation"]); var className = clsx(classes.root, classes[orientation], classNameProp, alternativeLabel && classes.alternativeLabel); var connector = React.isValidElement(connectorProp) ? React.cloneElement(connectorProp, { orientation: orientation }) : null; var childrenArray = React.Children.toArray(children); var steps = childrenArray.map(function (step, index) { var controlProps = { alternativeLabel: alternativeLabel, connector: connectorProp, last: index + 1 === childrenArray.length, orientation: orientation }; var state = { index: index, active: false, completed: false, disabled: false }; if (activeStep === index) { state.active = true; } else if (!nonLinear && activeStep > index) { state.completed = true; } else if (!nonLinear && activeStep < index) { state.disabled = true; } return [!alternativeLabel && connector && index !== 0 && React.cloneElement(connector, _extends({ key: index }, state)), React.cloneElement(step, _extends({}, controlProps, {}, state, {}, step.props))]; }); return React.createElement(Paper, _extends({ square: true, elevation: 0, className: className, ref: ref }, other), steps); }); process.env.NODE_ENV !== "production" ? Stepper.propTypes = { /** * Set the active step (zero based index). */ activeStep: PropTypes.number, /** * If set to 'true' and orientation is horizontal, * then the step label will be positioned under the icon. */ alternativeLabel: PropTypes.bool, /** * Two or more `<Step />` components. */ children: PropTypes.node.isRequired, /** * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ classes: PropTypes.object.isRequired, /** * @ignore */ className: PropTypes.string, /** * An element to be placed between each step. */ connector: PropTypes.element, /** * If set the `Stepper` will not assist in controlling steps for linear flow. */ nonLinear: PropTypes.bool, /** * The stepper orientation (layout flow direction). */ orientation: PropTypes.oneOf(['horizontal', 'vertical']) } : void 0; export default withStyles(styles, { name: 'MuiStepper' })(Stepper);