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

Function Stepper

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

Source from the content-addressed store, hash-verified

2import { motion, AnimatePresence } from 'motion/react';
3
4export default function Stepper({
5 children,
6 initialStep = 1,
7 onStepChange = () => {},
8 onFinalStepCompleted = () => {},
9 stepCircleContainerClassName = '',
10 stepContainerClassName = '',
11 contentClassName = '',
12 footerClassName = '',
13 backButtonProps = {},
14 nextButtonProps = {},
15 backButtonText = 'Back',
16 nextButtonText = 'Continue',
17 disableStepIndicators = false,
18 renderStepIndicator,
19 ...rest
20}) {
21 const [currentStep, setCurrentStep] = useState(initialStep);
22 const [direction, setDirection] = useState(0);
23 const stepsArray = Children.toArray(children);
24 const totalSteps = stepsArray.length;
25 const isCompleted = currentStep > totalSteps;
26 const isLastStep = currentStep === totalSteps;
27
28 const updateStep = newStep => {
29 setCurrentStep(newStep);
30 if (newStep > totalSteps) onFinalStepCompleted();
31 else onStepChange(newStep);
32 };
33
34 const handleBack = () => {
35 if (currentStep > 1) {
36 setDirection(-1);
37 updateStep(currentStep - 1);
38 }
39 };
40
41 const handleNext = () => {
42 if (!isLastStep) {
43 setDirection(1);
44 updateStep(currentStep + 1);
45 }
46 };
47
48 const handleComplete = () => {
49 setDirection(1);
50 updateStep(totalSteps + 1);
51 };
52
53 return (
54 <div
55 className="flex min-h-full flex-1 flex-col items-center justify-center p-4 sm:aspect-[4/3] md:aspect-[2/1]"
56 {...rest}
57 >
58 <div
59 className={`mx-auto w-full max-w-md rounded-4xl shadow-xl ${stepCircleContainerClassName}`}
60 style={{ border: '1px solid #222' }}
61 >

Callers

nothing calls this directly

Calls 1

updateStepFunction · 0.70

Tested by

no test coverage detected