({
children,
initialStep = 1,
onStepChange = () => {},
onFinalStepCompleted = () => {},
stepCircleContainerClassName = '',
stepContainerClassName = '',
contentClassName = '',
footerClassName = '',
backButtonProps = {},
nextButtonProps = {},
backButtonText = 'Back',
nextButtonText = 'Continue',
disableStepIndicators = false,
renderStepIndicator,
...rest
}: StepperProps)
| 23 | } |
| 24 | |
| 25 | export default function Stepper({ |
| 26 | children, |
| 27 | initialStep = 1, |
| 28 | onStepChange = () => {}, |
| 29 | onFinalStepCompleted = () => {}, |
| 30 | stepCircleContainerClassName = '', |
| 31 | stepContainerClassName = '', |
| 32 | contentClassName = '', |
| 33 | footerClassName = '', |
| 34 | backButtonProps = {}, |
| 35 | nextButtonProps = {}, |
| 36 | backButtonText = 'Back', |
| 37 | nextButtonText = 'Continue', |
| 38 | disableStepIndicators = false, |
| 39 | renderStepIndicator, |
| 40 | ...rest |
| 41 | }: StepperProps) { |
| 42 | const [currentStep, setCurrentStep] = useState<number>(initialStep); |
| 43 | const [direction, setDirection] = useState<number>(0); |
| 44 | const stepsArray = Children.toArray(children); |
| 45 | const totalSteps = stepsArray.length; |
| 46 | const isCompleted = currentStep > totalSteps; |
| 47 | const isLastStep = currentStep === totalSteps; |
| 48 | |
| 49 | const updateStep = (newStep: number) => { |
| 50 | setCurrentStep(newStep); |
| 51 | if (newStep > totalSteps) { |
| 52 | onFinalStepCompleted(); |
| 53 | } else { |
| 54 | onStepChange(newStep); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | const handleBack = () => { |
| 59 | if (currentStep > 1) { |
| 60 | setDirection(-1); |
| 61 | updateStep(currentStep - 1); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | const handleNext = () => { |
| 66 | if (!isLastStep) { |
| 67 | setDirection(1); |
| 68 | updateStep(currentStep + 1); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | const handleComplete = () => { |
| 73 | setDirection(1); |
| 74 | updateStep(totalSteps + 1); |
| 75 | }; |
| 76 | |
| 77 | return ( |
| 78 | <div |
| 79 | className="flex min-h-full flex-1 flex-col items-center justify-center p-4 sm:aspect-[4/3] md:aspect-[2/1]" |
| 80 | {...rest} |
| 81 | > |
| 82 | <div |
nothing calls this directly
no test coverage detected