-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add most Stepper Typescript demos (#15223)
- Loading branch information
Showing
14 changed files
with
1,230 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
93 changes: 93 additions & 0 deletions
93
docs/src/pages/demos/steppers/HorizontalLinearAlternativeLabelStepper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.