'use client'; import React, { useEffect, useRef, useId } from 'react'; import MdIconCheck from '../icons-material/MdIconCheck'; export interface MdStepperProps { activeStep: number; scrollToActiveStep?: boolean; children: React.ReactElement[]; } export const MdStepper: React.FunctionComponent = ({ activeStep, children, scrollToActiveStep = false, }: MdStepperProps) => { const stepperId = `stepper_${useId()}`; const firstUpdate = useRef(true); useEffect(() => { if (!firstUpdate.current && scrollToActiveStep) { const elem = document.getElementById(`${stepperId}_${activeStep}`); if (elem) { elem.scrollIntoView({ behavior: 'smooth' }); } } firstUpdate.current = false; }, [activeStep, stepperId, scrollToActiveStep]); return (
{React.Children.map(children, (item, index) => { return (
{item}
); })}
); }; export default MdStepper; interface StepTitleProps { title: string; index: number; activeStep: number; } const StepTitle = ({ title, index, activeStep }: StepTitleProps) => { if (index === activeStep) { // Step selected return (
{index + 1}

{title}

); } else if (index < activeStep) { // Step completed return (

{title}

); } else { // Step not reached yet return (
{index + 1}
{' '}

{title}

); } }; interface StepContentProps { index: number; activeStep: number; completedContent?: React.ReactNode; children: React.ReactNode; } const StepContent = ({ index, activeStep, completedContent, children }: StepContentProps) => { if (index === activeStep) { return (
{children}
); } else if (index < activeStep) { // Step completed return (
{completedContent ? completedContent : children}
); } else { // Step not reached yet return (
); } };