Where someone is in a wizard or a setup checklist, with complete, current, error and optional steps.
3 rows have no email. Fix them in the file, or skip them.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { Stepper } from "./ui/uicontext/components/Stepper.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ card: { display: "grid", gap: space.xl, inlineSize: "min(100%, 40rem)", padding: space.xl, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.panel, }, body: { margin: 0, minBlockSize: "3em", fontSize: font.base, color: color.muted }, actions: { display: "flex", justifyContent: "space-between", gap: space.md },})const steps = [ { id: "upload", title: "Upload", description: "contacts.csv" }, { id: "map", title: "Match columns" }, { id: "review", title: "Review" }, { id: "invite", title: "Invite", optional: true },]const bodies: Record<string, string> = { upload: "Drop a CSV with a header row. We read up to 50,000 rows.", map: "Match each column to a field: Name, Email, Company.", review: "3 rows have no email. Fix them in the file, or skip them.", invite: "Send an invite to the people you imported, or do it later.",}const Message = UiSchema.TaggedEnum({ ClickedBack: {}, ClickedContinue: {}, PickedStep: { id: Schema.String }, ClickedSkipRows: {} })const order = steps.map((s) => s.id)const at = (step: string) => order.indexOf(step)export const ImportWizard = Html.component({ name: "ImportWizard", // `reached`: the furthest step so far, so going back keeps later steps marked model: Schema.Struct({ step: Schema.String, reached: Schema.Number, skipped: Schema.Boolean }), message: Message,}).make({ init: () => ({ step: "review", reached: 2, skipped: false }), update: { ClickedBack: ($) => $.evolve({ step: order[Math.max(0, at($.model.step) - 1)]! }), ClickedContinue: ($) => { const next = Math.min(order.length - 1, at($.model.step) + 1) return $.evolve({ step: order[next]!, reached: (r) => Math.max(r, next) }) }, PickedStep: ($, { id }) => $.evolve({ step: id }), ClickedSkipRows: ($) => $.evolve({ skipped: true, step: "invite", reached: 3 }), }, view: (h, { step, reached, skipped }) => { const index = at(step) const blocked = step === "review" && !skipped // Review keeps its error once you leave it unfixed const errors = !skipped && step !== "review" && reached >= at("review") ? ["review"] : [] return h.div.attrs(sx(styles.card)).children( Stepper(h, { steps: steps.map((s) => (s.id === "review" && !skipped ? { ...s, description: "3 rows need an email" } : s)), current: step, errors, completed: order.slice(0, reached), onSelect: (id) => Message.PickedStep({ id }), }), h.p.attrs(sx(styles.body)).children(step === "review" && skipped ? "3 rows skipped. 1,281 contacts ready." : bodies[step]), h.div.attrs(sx(styles.actions)).children( Button(h).attrs({ disabled: index === 0 ? "" : undefined }).on("click", Message.ClickedBack()).children("Back"), blocked ? Button(h, { tone: "primary" }).on("click", Message.ClickedSkipRows()).children("Skip 3 rows") : Button(h, { tone: "primary" }).attrs({ disabled: index === order.length - 1 ? "" : undefined }).on("click", Message.ClickedContinue()).children("Continue"), ), ) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/stepperUsage
import { Stepper } from "./ui/uicontext/components/Stepper.ts"const Message = UiSchema.TaggedEnum({ PickedStep: { id: Schema.String } })const steps = [ { id: "account", title: "Account" }, { id: "plan", title: "Plan" }, { id: "payment", title: "Payment" },]export const SignUpSteps = (h: Html.H<typeof Message.Type>, current: string) => Stepper(h, { steps, current, onSelect: (id) => Message.PickedStep({ id }) })Examples
Vertical checklist
The current step opens under its title. Finished steps stay one click away.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { Stepper } from "./ui/uicontext/components/Stepper.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 28rem)" }, content: { display: "grid", gap: 10, justifyItems: "start" },})const steps = [ { id: "workspace", title: "Name your workspace", description: "Northwind Support" }, { id: "invite", title: "Invite your team", description: "Teammates see the same inbox and can take a ticket." }, { id: "channel", title: "Connect an email address", description: "Forward support@ to your inbox address." }, { id: "macros", title: "Write your first macro", optional: true },]const Message = UiSchema.TaggedEnum({ ClickedDone: {}, PickedStep: { id: Schema.String } })const order = steps.map((s) => s.id)// a helpdesk's setup checklist: the current step shows what to do right under its titleexport const SetupChecklist = Html.component({ name: "SetupChecklist", model: Schema.Struct({ step: Schema.String, done: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ step: "invite", done: ["workspace"] }), update: { ClickedDone: ($) => { const done = [...$.model.done, $.model.step] const next = order.find((id) => !done.includes(id)) ?? $.model.step return $.evolve({ done, step: next }) }, PickedStep: ($, { id }) => $.evolve({ step: id }), }, view: (h, { step, done }) => h.div.attrs(sx(styles.wrap)).children( Stepper(h, { steps, current: step, completed: done, orientation: "vertical", label: "Setup", onSelect: (id) => Message.PickedStep({ id }), content: (s) => h.div.attrs(sx(styles.content)).children( done.includes(s.id) ? null : Button(h, { size: "sm", tone: "primary" }).on("click", Message.ClickedDone()).children("Mark done"), ), }), ),})API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
stepsrequired | Step[] | — | — |
currentrequired | string | — | The id of the step someone is on. Steps before it are complete unless errors names them. |
errors | string[] | — | Steps with something to fix: "The CSV has 3 rows without an email". |
completed | string[] | — | Steps finished out of order, such as optional ones after the current step. |
orientation | "horizontal" | "vertical" | horizontal | horizontal for a wizard's header, vertical for a checklist; horizontal by default. |
onSelect | (id: string) => Message | — | Go back to a step already reached (complete, or with an error). Without it the steps are plain text. |
content | (step: Step) => View.Content | — | Vertical only: what the current step shows under its title. |
label | string | "Progress" | Names the list; "Progress" by default. |
style | Style | — | StyleX styles applied after the stepper's own. |