import type { Meta, StoryObj } from '@storybook/react'; import { Stepper, Step } from './stepper'; import { useStepper } from './use-stepper'; import { Button } from '../button'; import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '../card'; import React, { useState } from 'react'; import { Check } from 'lucide-react'; import { cn } from '../../shared/utils'; const meta: Meta = { title: 'UI/Stepper', component: Stepper, render: args => , }; export default meta; type Story = StoryObj; export const Default: Story = { render: args => { const [currentStep, setCurrentStep] = useState(1); const totalSteps = 4; return ( Onboarding Process
{currentStep === 1 && 'Profile Setup Content'} {currentStep === 2 && 'Plan Selection Content'} {currentStep === 3 && 'Billing Information Content'} {currentStep === 4 && 'Confirmation Content'}
); }, }; /** * ## useStepper — Headless Hook * * Use `useStepper` when you need step navigation logic (next/prev/goTo, * async validation guard, first/last flags) but want to render a completely * custom step indicator UI — or when the step controls live far away from * the `` visual component. * * The `onBeforeNext` guard lets you run async form validation before the * step advances. Return `false` to block the transition. * * ```tsx * import { useStepper } from '@xertica/ui/stepper'; * * const { currentStep, totalSteps, next, prev, isFirstStep, isLastStep } = * useStepper({ totalSteps: 3, onBeforeNext: () => form.trigger() }); * ``` */ export const HeadlessHook: Story = { name: 'useStepper (headless)', render: () => { const steps = [ { id: 1, label: 'Personal Info', content: 'Fill in your name and email.' }, { id: 2, label: 'Address', content: 'Enter your shipping address.' }, { id: 3, label: 'Review', content: 'Confirm your details before submitting.' }, ]; const { currentStep, totalSteps, next, prev, goTo, isFirstStep, isLastStep, canGoPrev } = useStepper({ totalSteps: steps.length, // Simulate async validation — always passes in this demo onBeforeNext: async step => { console.log(`Validating step ${step}…`); await new Promise(r => setTimeout(r, 300)); return true; }, }); return (
{/* Custom step indicator — pill style */} {/* Step content */}

{steps[currentStep - 1].label}

{steps[currentStep - 1].content}

Step {currentStep} of {totalSteps} — form fields go here
{/* Navigation controls */}
{isFirstStep && (

Step navigation is driven entirely by useStepper — no{' '} <Stepper> component used.

)}
); }, };