MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / Stepper

Function Stepper

src/ts-tailwind/Components/Stepper/Stepper.tsx:25–156  ·  view source on GitHub ↗
({
  children,
  initialStep = 1,
  onStepChange = () => {},
  onFinalStepCompleted = () => {},
  stepCircleContainerClassName = '',
  stepContainerClassName = '',
  contentClassName = '',
  footerClassName = '',
  backButtonProps = {},
  nextButtonProps = {},
  backButtonText = 'Back',
  nextButtonText = 'Continue',
  disableStepIndicators = false,
  renderStepIndicator,
  ...rest
}: StepperProps)

Source from the content-addressed store, hash-verified

23}
24
25export 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

Callers

nothing calls this directly

Calls 1

updateStepFunction · 0.70

Tested by

no test coverage detected