stepper configurable icons

master
Tudor Stanciu 2020-12-19 01:47:14 +02:00
parent 7724744588
commit 91f6e04a9a
4 changed files with 17 additions and 18 deletions

View File

@ -2,5 +2,6 @@
"trailingComma": "none", "trailingComma": "none",
"tabWidth": 2, "tabWidth": 2,
"semi": true, "semi": true,
"singleQuote": false "singleQuote": false,
"arrowParens": "avoid"
} }

View File

@ -22,20 +22,20 @@ const styles = () => ({
const useStyles = makeStyles(styles); const useStyles = makeStyles(styles);
const ApplicationStepper = () => { const ApplicationStepper = () => {
const firstStep = steps.find((z) => z.id === 0); const firstStep = steps[0];
const [activeStep, setActiveStep] = useState(firstStep); const [activeStep, setActiveStep] = useState(firstStep);
const classes = useStyles(); const classes = useStyles();
const location = useLocation(); const location = useLocation();
const history = useHistory(); const history = useHistory();
useEffect(() => { useEffect(() => {
const step = steps.find((z) => z.route === location.pathname); const step = steps.find(z => z.route === location.pathname);
if (step) { if (step) {
setActiveStep(step); setActiveStep(step);
} }
}, [location.pathname]); }, [location.pathname]);
const handleStepClick = (step) => { const handleStepClick = step => {
if (!step) return; if (!step) return;
setActiveStep(step); setActiveStep(step);
if (location.pathname === step.route) return; if (location.pathname === step.route) return;
@ -49,7 +49,7 @@ const ApplicationStepper = () => {
orientation="horizontal" orientation="horizontal"
connector={<CustomStepConnector />} connector={<CustomStepConnector />}
> >
{steps.map((step) => ( {steps.map(step => (
<Step key={step.id}> <Step key={step.id}>
<StepButton <StepButton
id={"appStepper_" + step.title} id={"appStepper_" + step.title}

View File

@ -2,9 +2,7 @@ import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import clsx from "clsx"; import clsx from "clsx";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import SettingsIcon from "@material-ui/icons/Settings"; import steps from "../../../constants/steps";
import GroupAddIcon from "@material-ui/icons/GroupAdd";
import VideoLabelIcon from "@material-ui/icons/VideoLabel";
const useStepIconStyles = makeStyles({ const useStepIconStyles = makeStyles({
root: { root: {
@ -33,14 +31,9 @@ function StepIcon(props) {
const classes = useStepIconStyles(); const classes = useStepIconStyles();
const { active, completed } = props; const { active, completed } = props;
const icons = { const getIcon = icon => {
1: <SettingsIcon />, const step = steps.find(z => z.id === icon - 1);
2: <GroupAddIcon />, return step.icon;
3: <VideoLabelIcon />
};
const getIcon = (icon) => {
return icons[String(icon)];
}; };
return ( return (

View File

@ -1,15 +1,20 @@
import SettingsIcon from "@material-ui/icons/Settings";
import GroupAddIcon from "@material-ui/icons/GroupAdd";
const steps = [ const steps = [
{ {
id: 0, id: 0,
title: "Login", title: "Login",
route: "/", route: "/",
disabled: false disabled: false,
icon: <SettingsIcon />
}, },
{ {
id: 1, id: 1,
title: "About", title: "About",
route: "/about", route: "/about",
disabled: false disabled: false,
icon: <GroupAddIcon />
} }
]; ];