Loading component…
Loading component…
A multi-step flow for onboarding and setup – steps that fill and check off, sliding steps, a card that morphs to each step, inline validation and a success state
To reuse this local React demo, copy all files from the Code tab into the same folder, then import StepperForm from ./stepper-form.
import { StepperForm, StepperField, StepperInput, StepperTags, StepperChoices, StepperReview, type Step } from "@/components/ui/stepper-form";
type Values = { name: string; slug: string; invites: string[]; plan: string };
const steps: Step<Values>[] = [
{
id: "workspace",
title: "Workspace",
heading: "Name your workspace",
render: ({ values, setValues }) => (
<>
<StepperField name="name" label="Workspace name">
<StepperInput value={values.name} onChange={(e) => setValues({ name: e.target.value, slug: slugify(e.target.value) })} />
</StepperField>
<StepperField name="slug" label="Workspace URL">
<StepperInput prefix="acme.app/" value={values.slug} onChange={(e) => setValues({ slug: e.target.value })} />
</StepperField>
</>
),
validate: (v) => ({ name: v.name.trim() ? undefined : "Give your workspace a name" }),
},
{
id: "team",
title: "Team",
render: ({ values, setValues }) => (
<StepperField name="invites" label="Email addresses" optional>
<StepperTags value={values.invites} onChange={(invites) => setValues({ invites })} />
</StepperField>
),
},
{
id: "plan",
title: "Plan",
render: ({ values, setValues }) => (
<StepperChoices label="Plan" value={values.plan} options={plans} onChange={(plan) => setValues({ plan })} />
),
},
{
id: "review",
title: "Review",
render: ({ values, goTo }) => (
<StepperReview
onEdit={goTo}
rows={[
{ label: "Workspace", value: values.name, step: "workspace" },
{ label: "Plan", value: values.plan, step: "plan" },
]}
/>
),
},
];
export function Onboarding() {
return (
<StepperForm<Values>
steps={steps}
initialValues={{ name: "", slug: "", invites: [], plan: "pro" }}
submitLabel="Create workspace"
onComplete={(values) => api.createWorkspace(values)}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| steps | Step<V>[] | { id, title, heading?, description?, render(ctx), validate?(values) } – render gets values, setValues, errors, goTo and next; validate returns messages by field name | |
| initialValues | V | Values shared by all steps, so Back and Edit keep what was entered | |
| onComplete | (values: V) => void \| Promise<void> | Runs on the last step; a promise shows the submitting label until it settles, a thrown error is shown next to the button | |
| initialStep | number | 0 | Index of the first step shown |
| step | number | Controlled step index; pair with onStepChange | |
| onStepChange | (step: number) => void | Called whenever the step changes | |
| submitLabel | string | "Finish" | Label of the button on the last step |
| submittingLabel | string | "Creating…" | Label while onComplete runs |
| success | (values: V, reset: () => void) => ReactNode | Replaces the steps once done – StepperSuccess gives the popping check, a heading and a line | |
| className | string | Extra class on the root | |
| StepperField | { name, label, hint?, optional?, children } | Label, control and inline message for the field name in validate; the control shakes when Continue finds a problem | |
| StepperInput | InputHTMLAttributes & { prefix? } | A text field wired to its StepperField; prefix shows fixed text like "acme.app/" | |
| StepperTags | { value, onChange, validate?, max?, placeholder? } | Entries as chips – emails by default; Enter, comma or a pasted list add, × or Backspace remove | |
| StepperChoices | { value, onChange, options, label } | Selectable cards { value, title, aside?, description?, badge? } as a radio group with a gliding ring | |
| StepperReview | { rows, onEdit? } | A summary { label, value, step? } – rows with a step get an Edit link (pass goTo) |
Fills its container up to 520px and works down to 320px
Below 420px the steps collapse to "Step 2 of 4 · Team", plan cards stack and review rows wrap
Touch screens get 16px fields (no zoom on iOS) and buttons of at least 40px; the footer sticks to the bottom in long pages
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"