Sample Code
"use client";
import * as React from 'react';
import {
Box,
Stepper,
Step,
StepLabel,
Button,
Typography,
FormControlLabel,
Alert,
} from '@mui/material';
import { styled } from '@mui/material/styles';
import { TextField } from '@mui/material';
import Checkbox, { CheckboxProps } from '@mui/material/Checkbox';
import { Typography } from '@mui/material';
import { Stack } from '@mui/system';
const steps = ['Account', 'Profile', 'Finish'];
const CustomTextField = styled((props) => <TextField {...props} />)(({ theme }) => ({
'& .MuiOutlinedInput-input::-webkit-input-placeholder': {
color: theme.palette.text.secondary,
opacity: '0.8',
},
'& .MuiOutlinedInput-input.Mui-disabled::-webkit-input-placeholder': {
color: theme.palette.text.secondary,
opacity: '1',
},
'& .Mui-disabled .MuiOutlinedInput-notchedOutline': {
borderColor: theme.palette.grey[200],
},
}));
const BpIcon = styled('span')(({ theme }) => ({
borderRadius: 3,
width: 19,
height: 19,
marginLeft: '4px',
boxShadow:
theme.palette.mode === 'dark'
? '0 0 0 1px {theme.palette.grey[200]}'
: 'inset 0 0 0 1px {theme.palette.grey[300]}',
backgroundColor: 'transparent',
'.Mui-focusVisible &': {
outline:
theme.palette.mode === 'dark'
? '0px auto {theme.palette.grey[200]}'
: '0px auto {theme.palette.grey[300]}',
outlineOffset: 2,
},
'input:hover ~ &': {
backgroundColor: theme.palette.mode === 'dark' ? theme.palette.primary : theme.palette.primary,
},
'input:disabled ~ &': {
boxShadow: 'none',
background: theme.palette.grey[100],
},
}));
const BpCheckedIcon = styled(BpIcon)({
boxShadow: 'none',
width: 19,
height: 19,
'&:before': {
display: 'block',
width: 19,
height: 19,
backgroundImage:
"url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" +
" fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " +
"1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E")",
content: '""',
},
});
function CustomCheckbox(props: CheckboxProps) {
return (
<Checkbox
disableRipple
color={props.color ? props.color : 'default'}
checkedIcon={
<BpCheckedIcon
sx={{
backgroundColor: props.color ? '{props.color}.main' : 'primary.main',
}}
/>
}
icon={<BpIcon />}
inputProps={{ 'aria-label': 'Checkbox demo' }}
{...props}
/>
);
}
const CustomFormLabel = styled((props) => (
<Typography
variant="subtitle1"
fontWeight={600}
{...props}
component="label"
htmlFor={props.htmlFor}
/>
))(() => ({
marginBottom: '5px',
marginTop: '25px',
display: 'block',
}));
const [activeStep, setActiveStep] = React.useState(0);
const [skipped, setSkipped] = React.useState(new Set());
const isStepOptional = (step:any) => step === 1;
const isStepSkipped = (step:any) => skipped.has(step);
const handleNext = () => {
let newSkipped = skipped;
if (isStepSkipped(activeStep)) {
newSkipped = new Set(newSkipped.values());
newSkipped.delete(activeStep);
}
setActiveStep((prevActiveStep) => prevActiveStep + 1);
setSkipped(newSkipped);
};
const handleBack = () => {
setActiveStep((prevActiveStep) => prevActiveStep - 1);
};
const handleSkip = () => {
if (!isStepOptional(activeStep)) {
// You probably want to guard against something like this,
// it should never occur unless someone's actively trying to break something.
throw new Error("You can't skip a step that isn't optional.");
}
setActiveStep((prevActiveStep) => prevActiveStep + 1);
setSkipped((prevSkipped) => {
const newSkipped = new Set(prevSkipped.values());
newSkipped.add(activeStep);
return newSkipped;
});
};
// eslint-disable-next-line consistent-return
const handleSteps = (step) => {
switch (step) {
case 0:
return (
<Box>
<CustomFormLabel htmlFor="Name">Name</CustomFormLabel>
<CustomTextField id="Name" variant="outlined" fullWidth />
<CustomFormLabel htmlFor="Email">Email</CustomFormLabel>
<CustomTextField id="Email" type="email" variant="outlined" fullWidth />
<CustomFormLabel htmlFor="Password">Password</CustomFormLabel>
<CustomTextField id="Password" type="password" variant="outlined" fullWidth />
</Box>
);
case 1:
return (
<Box>
<CustomFormLabel htmlFor="Fname">First Name</CustomFormLabel>
<CustomTextField id="Fname" variant="outlined" fullWidth />
<CustomFormLabel htmlFor="Lname">Last Name</CustomFormLabel>
<CustomTextField id="Lname" type="text" variant="outlined" fullWidth />
<CustomFormLabel htmlFor="Address">Address</CustomFormLabel>
<CustomTextField id="Address" multiline rows={4} variant="outlined" fullWidth />
</Box>
);
case 2:
return (
<Box pt={3}>
<Typography variant="h5">Terms and condition</Typography>
<Typography variant="body2" sx={{ mt: 1 }}>
Sard about this site or you have been to it, but you cannot figure out what it is or
what it can do. MTA web directory isSard about this site or you have been to it, but
you cannot figure out what it is or what it can do. MTA web directory is
</Typography>
<FormControlLabel
control={<CustomCheckbox defaultChecked />}
label="Agree with terms?"
/>
</Box>
);
default:
break;
}
};
const handleReset = () => {
setActiveStep(0);
};
<Box width="100%">
<Stepper activeStep={activeStep}>
{steps.map((label, index) => {
const stepProps: { completed?: boolean } = {};
const labelProps: {
optional?: React.ReactNode;
} = {};
if (isStepOptional(index)) {
labelProps.optional = <Typography variant="caption">Optional</Typography>;
}
if (isStepSkipped(index)) {
stepProps.completed = false;
}
return (
<Step key={label} {...stepProps}>
<StepLabel {...labelProps}>{label}</StepLabel>
</Step>
);
})}
</Stepper>
{activeStep === steps.length ? (
<>
<Stack spacing={2} mt={3}>
<Alert severity="success">
All steps completed - you're finished
</Alert>
<Box textAlign="right">
<Button onClick={handleReset} variant="contained" color="error">
Reset
</Button>
</Box>
</Stack>
</>
) : (
<>
<Box>{handleSteps(activeStep)}</Box>
<Box display="flex" flexDirection="row" mt={3}>
<Button
color="inherit"
variant="contained"
disabled={activeStep === 0}
onClick={handleBack}
sx={{ mr: 1 }}
>
Back
</Button>
<Box flex="1 1 auto" />
{isStepOptional(activeStep) && (
<Button color="inherit" onClick={handleSkip} sx={{ mr: 1 }}>
Skip
</Button>
)}
<Button
onClick={handleNext}
variant="contained"
color={activeStep === steps.length - 1 ? 'success' : 'secondary'}
>
{activeStep === steps.length - 1 ? 'Finish' : 'Next'}
</Button>
</Box>
</>
)}
</Box>