"use client" import * as React from "react" import { cn } from "../utils/cn" interface StepsProps extends React.HTMLAttributes { currentStep: number } const StepsComponent = React.forwardRef( ({ currentStep, className, children, ...props }, ref) => { // Count the number of step children const steps = React.Children.toArray(children).filter((child) => React.isValidElement(child)) return (
{React.Children.map(children, (child, index) => { if (!React.isValidElement(child) || child.type !== Step) { return child } // Clone the child with additional props return React.cloneElement(child as React.ReactElement, { stepNumber: index + 1, isActive: currentStep === index + 1, isCompleted: currentStep > index + 1, isLast: index === steps.length - 1, }) })}
) }, ) StepsComponent.displayName = "Steps" interface StepProps extends React.HTMLAttributes { title: string description?: string stepNumber?: number isActive?: boolean isCompleted?: boolean isLast?: boolean } const Step = React.forwardRef( ({ title, description, stepNumber, isActive, isCompleted, isLast, className, ...props }, ref) => { return (
{/* Line connecting steps */} {!isLast &&
} {/* Step indicator */}
{isCompleted ? ( ) : ( {stepNumber} )}
{/* Step content */}

{title}

{description && (

{description}

)}
) }, ) Step.displayName = "Step" export { Step } export { StepsComponent as Steps }