Skip to content

Commit

Permalink
[docs] Add most Stepper Typescript demos (#15223)
Browse files Browse the repository at this point in the history
  • Loading branch information
sperry94 authored and eps1lon committed Apr 8, 2019
1 parent f3684fe commit eee69e5
Show file tree
Hide file tree
Showing 14 changed files with 1,230 additions and 18 deletions.
135 changes: 135 additions & 0 deletions docs/src/pages/demos/steppers/CustomizedStepper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import React from 'react';
import { makeStyles, Theme } 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 useStyles = makeStyles((theme: Theme) => ({
root: {
width: '90%',
},
button: {
marginRight: theme.spacing(1),
},
instructions: {
marginTop: theme.spacing(1),
marginBottom: theme.spacing(1),
},
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: number) {
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';
}
}

function CustomizedStepper() {
const classes = useStyles();
const [activeStep, setActiveStep] = React.useState(0);
const steps = getSteps();

function handleNext() {
setActiveStep(prevActiveStep => prevActiveStep + 1);
}

function handleBack() {
setActiveStep(prevActiveStep => prevActiveStep - 1);
}

function handleReset() {
setActiveStep(0);
}

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&apos;re finished
</Typography>
<Button onClick={handleReset} className={classes.button}>
Reset
</Button>
</div>
) : (
<div>
<Typography className={classes.instructions}>{getStepContent(activeStep)}</Typography>
<div>
<Button disabled={activeStep === 0} onClick={handleBack} className={classes.button}>
Back
</Button>
<Button
variant="contained"
color="primary"
onClick={handleNext}
className={classes.button}
>
{activeStep === steps.length - 1 ? 'Finish' : 'Next'}
</Button>
</div>
</div>
)}
</div>
</div>
);
}

export default CustomizedStepper;
51 changes: 51 additions & 0 deletions docs/src/pages/demos/steppers/DotsMobileStepper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import { makeStyles, useTheme } from '@material-ui/core/styles';
import MobileStepper from '@material-ui/core/MobileStepper';
import Button from '@material-ui/core/Button';
import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft';
import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';

const useStyles = makeStyles({
root: {
maxWidth: 400,
flexGrow: 1,
},
});

function DotsMobileStepper() {
const classes = useStyles();
const theme = useTheme();
const [activeStep, setActiveStep] = React.useState(0);

function handleNext() {
setActiveStep(prevActiveStep => prevActiveStep + 1);
}

function handleBack() {
setActiveStep(prevActiveStep => prevActiveStep - 1);
}

return (
<MobileStepper
variant="dots"
steps={6}
position="static"
activeStep={activeStep}
className={classes.root}
nextButton={
<Button size="small" onClick={handleNext} disabled={activeStep === 5}>
Next
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</Button>
}
backButton={
<Button size="small" onClick={handleBack} disabled={activeStep === 0}>
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
Back
</Button>
}
/>
);
}

export default DotsMobileStepper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from 'react';
import { makeStyles, Theme } 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 Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';

const useStyles = makeStyles((theme: Theme) => ({
root: {
width: '90%',
},
backButton: {
marginRight: theme.spacing(1),
},
instructions: {
marginTop: theme.spacing(1),
marginBottom: theme.spacing(1),
},
}));

function getSteps() {
return ['Select master blaster campaign settings', 'Create an ad group', 'Create an ad'];
}

function getStepContent(stepIndex: number) {
switch (stepIndex) {
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 'Uknown stepIndex';
}
}

function HorizontalLabelPositionBelowStepper() {
const classes = useStyles();
const [activeStep, setActiveStep] = React.useState(0);
const steps = getSteps();

function handleNext() {
setActiveStep(prevActiveStep => prevActiveStep + 1);
}

function handleBack() {
setActiveStep(prevActiveStep => prevActiveStep - 1);
}

function handleReset() {
setActiveStep(0);
}

return (
<div className={classes.root}>
<Stepper activeStep={activeStep} alternativeLabel>
{steps.map(label => (
<Step key={label}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
<div>
{activeStep === steps.length ? (
<div>
<Typography className={classes.instructions}>All steps completed</Typography>
<Button onClick={handleReset}>Reset</Button>
</div>
) : (
<div>
<Typography className={classes.instructions}>{getStepContent(activeStep)}</Typography>
<div>
<Button
disabled={activeStep === 0}
onClick={handleBack}
className={classes.backButton}
>
Back
</Button>
<Button variant="contained" color="primary" onClick={handleNext}>
{activeStep === steps.length - 1 ? 'Finish' : 'Next'}
</Button>
</div>
</div>
)}
</div>
</div>
);
}

export default HorizontalLabelPositionBelowStepper;
1 change: 1 addition & 0 deletions docs/src/pages/demos/steppers/HorizontalLinearStepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function HorizontalLinearStepper() {
Skip
</Button>
)}

<Button
variant="contained"
color="primary"
Expand Down
Loading

0 comments on commit eee69e5

Please sign in to comment.