Step Wizard Modal
A multi-step dialog with a progress indicator, per-step validation that blocks Next, Back, a pending state and a success screen. You bring the step content and state.
npx shadcn@latest add https://ui.develop-better-solutions.com/r/step-wizard-modal.jsonDependencies:
lucide-reactUsage
step-wizard-modal-example.tsx
"use client";
import { useState } from "react";
import { StepWizardModal, TextField, useValidatedForm, ruleAll, ruleEmail, ruleRequired } from "@dbs/ui";
const AREAS = ["Weight care", "Daily wellness", "Sleep", "Longevity"];
export default function StepWizardModalExample() {
const [open, setOpen] = useState(false);
const [area, setArea] = useState("");
const form = useValidatedForm({ name: "", email: "" }, { name: ruleRequired("Please enter your name."), email: ruleAll(ruleRequired("Please enter your email."), ruleEmail()) });
return (
<>
<button type="button" onClick={() => setOpen(true)} className="h-11 rounded-full bg-ink px-6 text-sm font-medium text-canvas">Start intake</button>
<StepWizardModal
open={open}
onOpenChange={setOpen}
eyebrow="Clinical intake"
title="Tell us about your goals"
completeLabel="Submit intake"
onComplete={() => undefined}
success={{ title: "Intake received", message: "Thank you. A provider will review your answers and reply within 24 hours.", actionLabel: "Back to site" }}
steps={[
{
id: "area",
label: "Focus area",
heading: "What would you like help with?",
validate: () => (area ? undefined : "Choose one to continue."),
content: (
<div role="radiogroup" aria-label="Focus area" className="grid gap-2">
{AREAS.map((a) => (
<button key={a} type="button" role="radio" aria-checked={area === a} onClick={() => setArea(a)} className={`rounded-xl border p-3 text-left text-sm transition-colors ${area === a ? "border-ink bg-surface font-medium" : "border-line hover:border-ink-subtle"}`}>
{a}
</button>
))}
</div>
),
},
{
id: "contact",
label: "Your details",
heading: "Where should we send the result?",
validate: () => (form.validate() ? undefined : "Please fix the highlighted fields."),
content: (
<div className="grid gap-4">
<TextField id="wz-name" label="Name" required {...form.field("name")} />
<TextField id="wz-email" label="Email" type="email" required {...form.field("email")} />
</div>
),
},
]}
/>
</>
);
}