materialuiupgraded
Version:
Material-UI's workspace package
156 lines (144 loc) • 4.13 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Stepper from '@material-ui/core/Stepper';
import Step from '@material-ui/core/Step';
import StepLabel from '@material-ui/core/StepLabel';
import StepConnector from '@material-ui/core/StepConnector';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
const styles = theme => ({
root: {
width: '90%',
},
button: {
marginRight: theme.spacing.unit,
},
instructions: {
marginTop: theme.spacing.unit,
marginBottom: theme.spacing.unit,
},
connectorActive: {
'& $connectorLine': {
borderColor: theme.palette.secondary.main,
},
},
connectorCompleted: {
'& $connectorLine': {
borderColor: theme.palette.primary.main,
},
},
connectorDisabled: {
'& $connectorLine': {
borderColor: theme.palette.grey[100],
},
},
connectorLine: {
transition: theme.transitions.create('border-color'),
},
});
function getSteps() {
return ['Select campaign settings', 'Create an ad group', 'Create an ad'];
}
function getStepContent(step) {
switch (step) {
case 0:
return 'Select campaign settings...';
case 1:
return 'What is an ad group anyways?';
case 2:
return 'This is the bit I really care about!';
default:
return 'Unknown step';
}
}
class CustomizedStepper extends React.Component {
state = {
activeStep: 0,
};
handleNext = () => {
this.setState(state => ({
activeStep: state.activeStep + 1,
}));
};
handleBack = () => {
this.setState(state => ({
activeStep: state.activeStep - 1,
}));
};
handleReset = () => {
this.setState({
activeStep: 0,
});
};
render() {
const { classes } = this.props;
const { activeStep } = this.state;
const steps = getSteps();
const connector = (
<StepConnector
classes={{
active: classes.connectorActive,
completed: classes.connectorCompleted,
disabled: classes.connectorDisabled,
line: classes.connectorLine,
}}
/>
);
return (
<div className={classes.root}>
<Stepper activeStep={activeStep} connector={connector}>
{steps.map(label => (
<Step key={label}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
<Stepper alternativeLabel activeStep={activeStep} connector={connector}>
{steps.map(label => (
<Step key={label}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
<div>
{activeStep === steps.length ? (
<div>
<Typography className={classes.instructions}>
All steps completed - you"re finished
</Typography>
<Button onClick={this.handleReset} className={classes.button}>
Reset
</Button>
</div>
) : (
<div>
<Typography className={classes.instructions}>{getStepContent(activeStep)}</Typography>
<div>
<Button
disabled={activeStep === 0}
onClick={this.handleBack}
className={classes.button}
>
Back
</Button>
<Button
variant="contained"
color="primary"
onClick={this.handleNext}
className={classes.button}
>
{activeStep === steps.length - 1 ? 'Finish' : 'Next'}
</Button>
</div>
</div>
)}
</div>
</div>
);
}
}
CustomizedStepper.propTypes = {
classes: PropTypes.object,
};
export default withStyles(styles)(CustomizedStepper);