blob: 9870f03468a2fe27ebb64356428e3e99b7ffc66b [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import React from 'react';
6import {createTheme} from '@material-ui/core/styles';
7import {makeStyles} from '@material-ui/styles';
8import MobileStepper from '@material-ui/core/MobileStepper';
9import Button from '@material-ui/core/Button';
10import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft';
11import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';
12
13const theme: Theme = createTheme();
14
15const useStyles = makeStyles({
16 root: {
17 width: '100%',
18 flexGrow: 1,
19 },
20}, {defaultTheme: theme});
21
22/**
23 * `<DotMobileStepper />`
24 *
25 * React component for rendering the linear dot stepper of the issue wizard.
26 *
27 * @return ReactElement.
28 */
29export default function DotsMobileStepper({nextEnabled, activeStep, setActiveStep} : {nextEnabled: boolean, activeStep: number, setActiveStep: Function}) : React.ReactElement {
30 const classes = useStyles();
31
32 const handleNext = () => {
33 setActiveStep((prevActiveStep: number) => prevActiveStep + 1);
34 };
35
36 const handleBack = () => {
37 setActiveStep((prevActiveStep: number) => prevActiveStep - 1);
38 };
39
40 let label;
41 let icon;
42
43 if (activeStep === 2){
44 label = 'Submit';
45 icon = '';
46 } else {
47 label = 'Next';
48 icon = <KeyboardArrowRight />;
49 }
50 return (
51 <MobileStepper
52 id="mobile-stepper"
53 variant="dots"
54 steps={3}
55 position="static"
56 activeStep={activeStep}
57 className={classes.root}
58 nextButton={
59 <Button aria-label="nextButton" size="medium" onClick={handleNext} disabled={activeStep === 2 || !nextEnabled}>
60 {label}
61 {icon}
62 </Button>
63 }
64 backButton={
65 <Button aria-label="backButton" size="medium" onClick={handleBack} disabled={activeStep === 0}>
66 <KeyboardArrowLeft />
67 Back
68 </Button>
69 }
70 />
71 );
72}