<!-- generated by scripts/gen-docs.mjs from docs/system/steps.md. Edit the source and rerun. -->
# Steps

## Description
Shows the steps of a setup or a form in parts, in order, and where each one stands: done, current, still to come, being checked or failed.

`import { Step, Steps, type StepStatus } from "@/components/cobalt/ui/steps"`, source `registry/cobalt/ui/steps.tsx`, status `ready-with-gaps`.
`import { StepSwap } from "@/components/cobalt/ui/step-swap"`, source `registry/cobalt/ui/step-swap.tsx`, status `ready-with-gaps`.
Foundation: `hand-rolled (the marks' spinner on Spinner, cut titles on TruncatedText; StepSwap on motion/react AnimatePresence)`. Traps checked: `trap/color-only-status`, `trap/current-unmarked`, `trap/weight-shift`, `trap/text-measure`, `trap/link-as-button`, `trap/motion-layout-property`, `trap/motion-exit-slower`, `trap/reduced-motion-ignored`, `trap/loading-layout-shift`, `trap/illustration-announced`.

`trap/color-only-status` is answered by the marks' shapes, a number, a check, a cross and a spinner, and by the state read after each title (States). `trap/current-unmarked` by `aria-current="step"` and the ink mark. `trap/weight-shift` by one weight for every title, so a step that becomes current never widens. `trap/text-measure` by titles cut at 192px across the top, whole in the tooltip (Limits). `trap/link-as-button` by steps that are links when they have an address. `trap/motion-layout-property` is StepSwap's one exception: the box's height follows the step on the layout spring, so what is under the flow moves once, smoothly, instead of jumping. `trap/motion-exit-slower` by StepSwap's 150ms leave before a 220ms arrive. `trap/reduced-motion-ignored` by StepSwap's fade only and its height at once. `trap/loading-layout-shift` by the pending mark, a spinner in the mark's own 24px box. `trap/illustration-announced` by marks hidden from a screen reader, which hears the words instead.

### Overview
`Steps` lists the steps and `Step` is one of them, down a card as a checklist or across the top of a flow. `StepSwap` changes the flow's body from one step to the next, from the side the next step lies on.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Not applicable: hand-rolled. An `ol` and its `li`s | `Steps` in two orientations; marks of 24px on a 6px corner, the step's number, a check in the accent's soft fill once done, the ink for the current step, a cross on the red wash when failed, a spinner while checked; the state in words after each title; a title with `href` as a link to do the step; across the top a 2px track to the next step that fills in the accent, and in a box under 32rem only the current title shows |
| `Spinner` from `registry/cobalt/ui/spinner.tsx`, `TruncatedText` from `registry/cobalt/lib/truncated-text.tsx` | The pending mark and the cut title with its tooltip |
| `AnimatePresence` from motion/react, in `popLayout` mode | `StepSwap`: the last step fades out in 150ms, the next fades in from 8px on the side it lies on once it has gone, and the box follows the next step's height, growing at once and shrinking only after the last step has gone, clipped only above and below |

## Examples
A setup checklist in a rail card beside its progress bar, and a three-part setup whose parts swap in from the side they lie on, checking the firm with the server before the next part opens.

Real uses, 0 call sites (`rg -n "<Steps\b" app registry --glob '!registry/cobalt/ui/*'`): the part is new. The setup checklist in a rail card is drawn once, on Steps (`docs/system/examples/steps/default.tsx`); the Page layout page points here for it instead of a second checklist made of checkboxes. StepSwap follows TSA's (`~/tsaglobal-superapp-live/apps/web/app/components/motion/step-swap.tsx`) on Cobalt's motion tokens.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/steps/default.tsx` | default | A setup checklist in a rail card: open steps are links, done steps show their check, and the bar counts them |
| `docs/system/examples/steps/setup-flow.tsx` | orientation=horizontal | Three parts across the top of a setup, only the current title shown in the card's width |
| `docs/system/examples/steps/default.tsx` | orientation=vertical | The checklist down a rail card |
| `docs/system/examples/steps/setup-flow.tsx` | state:pending | The firm's step shows a spinner while the server checks it |
| `docs/system/examples/steps/setup-flow.tsx` | state:failed | Offline, the firm's step shows a cross and the field says it could not be checked |
| `docs/system/examples/steps/setup-flow.tsx` | composition:StepSwap | Each part swaps in from the side it lies on, the card following its height |
| `docs/system/examples/steps/default.tsx` | composition:RailCard | The checklist in a rail card under its progress bar |

Example: A setup checklist in a rail card: open steps are links, done steps show their check, and the bar counts them (`docs/system/examples/steps/default.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Progress, ProgressLabel, ProgressValue } from "@/components/cobalt/ui/progress";
import { RailCard } from "@/components/cobalt/ui/rail-card";
import { Step, Steps } from "@/components/cobalt/ui/steps";

const setup = [
  { id: "photo", title: "Add a photo", href: "#photo" },
  { id: "firm", title: "Confirm your firm", href: "#firm" },
  { id: "follow", title: "Follow three funds", href: "#follow" },
  { id: "alerts", title: "Choose your filing alerts", href: "#alerts" },
  { id: "invite", title: "Invite a colleague", href: "#invite" },
];

export default function Example() {
  // Each step is done in its own place; this list only reports it. The first one not done is current.
  const [done, setDone] = useState<string[]>(["photo", "firm"]);
  const count = done.length;
  const current = setup.find((step) => !done.includes(step.id))?.id;
  const words = count === setup.length ? "All done" : `${count} of ${setup.length} done`;
  return (
    <div className="flex w-full max-w-xs flex-col">
      <RailCard id="example-steps-setup" heading="Your setup">
        <Progress value={count} max={setup.length} getAriaValueText={() => words}>
          <ProgressLabel className="sr-only">Setup</ProgressLabel>
          <ProgressValue className="ms-0">{() => words}</ProgressValue>
        </Progress>
        <Steps label="Setup">
          {setup.map((step) => (
            <Step
              key={step.id}
              title={step.title}
              status={done.includes(step.id) ? "done" : step.id === current ? "current" : "upcoming"}
              {...(done.includes(step.id) ? {} : { href: step.href })}
            />
          ))}
        </Steps>
      </RailCard>
      {/* Docs control: stands in for doing the current step in its own place. */}
      <div className="mt-4 flex flex-wrap items-center gap-2 border-t border-dashed pt-3">
        <Button variant="ghost" size="sm" onClick={() => setDone((was) => (current ? [...was, current] : []))}>
          {current ? "Finish the current step" : "Start over"}
        </Button>
      </div>
    </div>
  );
}
```

Example: Each part swaps in from the side it lies on, the card following its height (`docs/system/examples/steps/setup-flow.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Card, CardContent } from "@/components/cobalt/ui/card";
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/cobalt/ui/field";
import { Input } from "@/components/cobalt/ui/input";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { StepSwap } from "@/components/cobalt/ui/step-swap";
import { Step, Steps, type StepStatus } from "@/components/cobalt/ui/steps";
import { Switch } from "@/components/cobalt/ui/switch";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

const parts = [
  { id: "name", title: "Profile" },
  { id: "firm", title: "Firm" },
  { id: "alerts", title: "Alerts" },
];

export default function Example() {
  const [at, setAt] = useState(0);
  const [direction, setDirection] = useState<"forward" | "backward">("forward");
  const [name, setName] = useState("Priya Raman");
  const [firm, setFirm] = useState("Northwind Research");
  const [digest, setDigest] = useState(true);
  const check = useAction(async () => {
    await request();
    go(2);
  });
  const finish = useAction(async () => {
    await request();
    go(parts.length);
  });
  const go = (next: number) => {
    setDirection(next > at ? "forward" : "backward");
    setAt(next);
  };
  const statusOf = (i: number): StepStatus =>
    i < at ? "done" : i > at ? "upcoming" : i === 1 && check.status === "pending" ? "pending" : i === 1 && check.status === "failure" ? "failed" : "current";
  const finished = at === parts.length;
  const partId = finished ? "finished" : parts[at]!.id;
  return (
    <Card className="w-full max-w-md">
      <CardContent className="flex flex-col gap-6">
        <Steps label="Setup" orientation="horizontal">
          {parts.map((p, i) => (
            <Step key={p.id} title={p.title} status={statusOf(i)} />
          ))}
        </Steps>
        <StepSwap id={partId} direction={direction}>
          <div className="flex flex-col gap-4">
            {partId === "name" && (
              <Field>
                <FieldLabel>Your name</FieldLabel>
                <Input value={name} autoComplete="name" onChange={(e) => setName(e.target.value)} />
                <FieldDescription>Shown to your team beside your notes.</FieldDescription>
              </Field>
            )}
            {partId === "firm" && (
              <Field>
                <FieldLabel>Your firm</FieldLabel>
                <Input value={firm} autoComplete="organization" onChange={(e) => setFirm(e.target.value)} />
                <FieldDescription>We check it against the advisers we hold.</FieldDescription>
                <FieldError reserve>
                  {check.status === "failure" ? "We could not check your firm. Try again." : ""}
                </FieldError>
              </Field>
            )}
            {partId === "alerts" && (
              <label className="flex items-center justify-between gap-4 text-sm">
                <span className="flex flex-col gap-0.5">
                  <span className="font-medium">A daily digest</span>
                  <span className="text-muted-foreground">One email a day with the funds you follow.</span>
                </span>
                <Switch checked={digest} onCheckedChange={setDigest} />
              </label>
            )}
            {finished && (
              <div className="flex flex-col gap-1 text-sm">
                <p className="font-medium">You are set up</p>
                <p className="text-muted-foreground">Your digest starts tomorrow morning.</p>
              </div>
            )}
          </div>
        </StepSwap>
        <div className="flex items-center justify-between gap-3">
          {at > 0 && !finished ? (
            <Button variant="ghost" onClick={() => go(at - 1)}>
              Back
            </Button>
          ) : (
            <span />
          )}
          {at === 2 ? (
            <StateButton
              status={finish.status}
              pendingLabel="Saving"
              successLabel="Saved"
              failureLabel="Not saved"
              onClick={() => void finish.run()}
            >
              Finish
            </StateButton>
          ) : at === 1 ? (
            <StateButton
              status={check.status}
              pendingLabel="Checking"
              successLabel="Checked"
              failureLabel="Not checked"
              onClick={() => void check.run()}
            >
              Continue
            </StateButton>
          ) : (
            <Button onClick={() => go(finished ? 0 : at + 1)}>{finished ? "Start again" : "Continue"}</Button>
          )}
        </div>
      </CardContent>
    </Card>
  );
}
```

Example: The checklist in a rail card under its progress bar (`docs/system/examples/steps/default.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Progress, ProgressLabel, ProgressValue } from "@/components/cobalt/ui/progress";
import { RailCard } from "@/components/cobalt/ui/rail-card";
import { Step, Steps } from "@/components/cobalt/ui/steps";

const setup = [
  { id: "photo", title: "Add a photo", href: "#photo" },
  { id: "firm", title: "Confirm your firm", href: "#firm" },
  { id: "follow", title: "Follow three funds", href: "#follow" },
  { id: "alerts", title: "Choose your filing alerts", href: "#alerts" },
  { id: "invite", title: "Invite a colleague", href: "#invite" },
];

export default function Example() {
  // Each step is done in its own place; this list only reports it. The first one not done is current.
  const [done, setDone] = useState<string[]>(["photo", "firm"]);
  const count = done.length;
  const current = setup.find((step) => !done.includes(step.id))?.id;
  const words = count === setup.length ? "All done" : `${count} of ${setup.length} done`;
  return (
    <div className="flex w-full max-w-xs flex-col">
      <RailCard id="example-steps-setup" heading="Your setup">
        <Progress value={count} max={setup.length} getAriaValueText={() => words}>
          <ProgressLabel className="sr-only">Setup</ProgressLabel>
          <ProgressValue className="ms-0">{() => words}</ProgressValue>
        </Progress>
        <Steps label="Setup">
          {setup.map((step) => (
            <Step
              key={step.id}
              title={step.title}
              status={done.includes(step.id) ? "done" : step.id === current ? "current" : "upcoming"}
              {...(done.includes(step.id) ? {} : { href: step.href })}
            />
          ))}
        </Steps>
      </RailCard>
      {/* Docs control: stands in for doing the current step in its own place. */}
      <div className="mt-4 flex flex-wrap items-center gap-2 border-t border-dashed pt-3">
        <Button variant="ghost" size="sm" onClick={() => setDone((was) => (current ? [...was, current] : []))}>
          {current ? "Finish the current step" : "Start over"}
        </Button>
      </div>
    </div>
  );
}
```

## Variants

### orientation
- `vertical`: a checklist down a card or a rail, with descriptions, such as "Your setup". Used in `docs/system/examples/steps/default.tsx`.
- `horizontal`: the marks across the top of a flow in parts, joined by a track. Used in `docs/system/examples/steps/setup-flow.tsx`.

Example: Three parts across the top of a setup, only the current title shown in the card's width (`docs/system/examples/steps/setup-flow.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Card, CardContent } from "@/components/cobalt/ui/card";
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/cobalt/ui/field";
import { Input } from "@/components/cobalt/ui/input";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { StepSwap } from "@/components/cobalt/ui/step-swap";
import { Step, Steps, type StepStatus } from "@/components/cobalt/ui/steps";
import { Switch } from "@/components/cobalt/ui/switch";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

const parts = [
  { id: "name", title: "Profile" },
  { id: "firm", title: "Firm" },
  { id: "alerts", title: "Alerts" },
];

export default function Example() {
  const [at, setAt] = useState(0);
  const [direction, setDirection] = useState<"forward" | "backward">("forward");
  const [name, setName] = useState("Priya Raman");
  const [firm, setFirm] = useState("Northwind Research");
  const [digest, setDigest] = useState(true);
  const check = useAction(async () => {
    await request();
    go(2);
  });
  const finish = useAction(async () => {
    await request();
    go(parts.length);
  });
  const go = (next: number) => {
    setDirection(next > at ? "forward" : "backward");
    setAt(next);
  };
  const statusOf = (i: number): StepStatus =>
    i < at ? "done" : i > at ? "upcoming" : i === 1 && check.status === "pending" ? "pending" : i === 1 && check.status === "failure" ? "failed" : "current";
  const finished = at === parts.length;
  const partId = finished ? "finished" : parts[at]!.id;
  return (
    <Card className="w-full max-w-md">
      <CardContent className="flex flex-col gap-6">
        <Steps label="Setup" orientation="horizontal">
          {parts.map((p, i) => (
            <Step key={p.id} title={p.title} status={statusOf(i)} />
          ))}
        </Steps>
        <StepSwap id={partId} direction={direction}>
          <div className="flex flex-col gap-4">
            {partId === "name" && (
              <Field>
                <FieldLabel>Your name</FieldLabel>
                <Input value={name} autoComplete="name" onChange={(e) => setName(e.target.value)} />
                <FieldDescription>Shown to your team beside your notes.</FieldDescription>
              </Field>
            )}
            {partId === "firm" && (
              <Field>
                <FieldLabel>Your firm</FieldLabel>
                <Input value={firm} autoComplete="organization" onChange={(e) => setFirm(e.target.value)} />
                <FieldDescription>We check it against the advisers we hold.</FieldDescription>
                <FieldError reserve>
                  {check.status === "failure" ? "We could not check your firm. Try again." : ""}
                </FieldError>
              </Field>
            )}
            {partId === "alerts" && (
              <label className="flex items-center justify-between gap-4 text-sm">
                <span className="flex flex-col gap-0.5">
                  <span className="font-medium">A daily digest</span>
                  <span className="text-muted-foreground">One email a day with the funds you follow.</span>
                </span>
                <Switch checked={digest} onCheckedChange={setDigest} />
              </label>
            )}
            {finished && (
              <div className="flex flex-col gap-1 text-sm">
                <p className="font-medium">You are set up</p>
                <p className="text-muted-foreground">Your digest starts tomorrow morning.</p>
              </div>
            )}
          </div>
        </StepSwap>
        <div className="flex items-center justify-between gap-3">
          {at > 0 && !finished ? (
            <Button variant="ghost" onClick={() => go(at - 1)}>
              Back
            </Button>
          ) : (
            <span />
          )}
          {at === 2 ? (
            <StateButton
              status={finish.status}
              pendingLabel="Saving"
              successLabel="Saved"
              failureLabel="Not saved"
              onClick={() => void finish.run()}
            >
              Finish
            </StateButton>
          ) : at === 1 ? (
            <StateButton
              status={check.status}
              pendingLabel="Checking"
              successLabel="Checked"
              failureLabel="Not checked"
              onClick={() => void check.run()}
            >
              Continue
            </StateButton>
          ) : (
            <Button onClick={() => go(finished ? 0 : at + 1)}>{finished ? "Start again" : "Continue"}</Button>
          )}
        </div>
      </CardContent>
    </Card>
  );
}
```

Example: The checklist down a rail card (`docs/system/examples/steps/default.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Progress, ProgressLabel, ProgressValue } from "@/components/cobalt/ui/progress";
import { RailCard } from "@/components/cobalt/ui/rail-card";
import { Step, Steps } from "@/components/cobalt/ui/steps";

const setup = [
  { id: "photo", title: "Add a photo", href: "#photo" },
  { id: "firm", title: "Confirm your firm", href: "#firm" },
  { id: "follow", title: "Follow three funds", href: "#follow" },
  { id: "alerts", title: "Choose your filing alerts", href: "#alerts" },
  { id: "invite", title: "Invite a colleague", href: "#invite" },
];

export default function Example() {
  // Each step is done in its own place; this list only reports it. The first one not done is current.
  const [done, setDone] = useState<string[]>(["photo", "firm"]);
  const count = done.length;
  const current = setup.find((step) => !done.includes(step.id))?.id;
  const words = count === setup.length ? "All done" : `${count} of ${setup.length} done`;
  return (
    <div className="flex w-full max-w-xs flex-col">
      <RailCard id="example-steps-setup" heading="Your setup">
        <Progress value={count} max={setup.length} getAriaValueText={() => words}>
          <ProgressLabel className="sr-only">Setup</ProgressLabel>
          <ProgressValue className="ms-0">{() => words}</ProgressValue>
        </Progress>
        <Steps label="Setup">
          {setup.map((step) => (
            <Step
              key={step.id}
              title={step.title}
              status={done.includes(step.id) ? "done" : step.id === current ? "current" : "upcoming"}
              {...(done.includes(step.id) ? {} : { href: step.href })}
            />
          ))}
        </Steps>
      </RailCard>
      {/* Docs control: stands in for doing the current step in its own place. */}
      <div className="mt-4 flex flex-wrap items-center gap-2 border-t border-dashed pt-3">
        <Button variant="ghost" size="sm" onClick={() => setDone((was) => (current ? [...was, current] : []))}>
          {current ? "Finish the current step" : "Start over"}
        </Button>
      </div>
    </div>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| done | `status="done"` | open it again when it has `href` | a check in the mark; ", Done" read after the title; the track to the next step filled | test |
| current | `status="current"` | do it, through its link or the flow's body | the step's number on the ink mark; `aria-current="step"`; across a narrow box, the only title shown | test |
| upcoming | `status="upcoming"` | read what comes | the number on a grey mark; the title muted; ", Not started" | test |
| pending | `status="pending"` | wait | a spinner in the mark; ", Checking" | test |
| failed | `status="failed"` | read why in the description and do it again | a cross on the red wash; the description in red; ", Failed" | test |
| swapping | StepSwap's `id` changes | read the next step as it arrives | the last step fades out, the next fades in from its side | by hand |

Example: The firm's step shows a spinner while the server checks it (`docs/system/examples/steps/setup-flow.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Card, CardContent } from "@/components/cobalt/ui/card";
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/cobalt/ui/field";
import { Input } from "@/components/cobalt/ui/input";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { StepSwap } from "@/components/cobalt/ui/step-swap";
import { Step, Steps, type StepStatus } from "@/components/cobalt/ui/steps";
import { Switch } from "@/components/cobalt/ui/switch";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

const parts = [
  { id: "name", title: "Profile" },
  { id: "firm", title: "Firm" },
  { id: "alerts", title: "Alerts" },
];

export default function Example() {
  const [at, setAt] = useState(0);
  const [direction, setDirection] = useState<"forward" | "backward">("forward");
  const [name, setName] = useState("Priya Raman");
  const [firm, setFirm] = useState("Northwind Research");
  const [digest, setDigest] = useState(true);
  const check = useAction(async () => {
    await request();
    go(2);
  });
  const finish = useAction(async () => {
    await request();
    go(parts.length);
  });
  const go = (next: number) => {
    setDirection(next > at ? "forward" : "backward");
    setAt(next);
  };
  const statusOf = (i: number): StepStatus =>
    i < at ? "done" : i > at ? "upcoming" : i === 1 && check.status === "pending" ? "pending" : i === 1 && check.status === "failure" ? "failed" : "current";
  const finished = at === parts.length;
  const partId = finished ? "finished" : parts[at]!.id;
  return (
    <Card className="w-full max-w-md">
      <CardContent className="flex flex-col gap-6">
        <Steps label="Setup" orientation="horizontal">
          {parts.map((p, i) => (
            <Step key={p.id} title={p.title} status={statusOf(i)} />
          ))}
        </Steps>
        <StepSwap id={partId} direction={direction}>
          <div className="flex flex-col gap-4">
            {partId === "name" && (
              <Field>
                <FieldLabel>Your name</FieldLabel>
                <Input value={name} autoComplete="name" onChange={(e) => setName(e.target.value)} />
                <FieldDescription>Shown to your team beside your notes.</FieldDescription>
              </Field>
            )}
            {partId === "firm" && (
              <Field>
                <FieldLabel>Your firm</FieldLabel>
                <Input value={firm} autoComplete="organization" onChange={(e) => setFirm(e.target.value)} />
                <FieldDescription>We check it against the advisers we hold.</FieldDescription>
                <FieldError reserve>
                  {check.status === "failure" ? "We could not check your firm. Try again." : ""}
                </FieldError>
              </Field>
            )}
            {partId === "alerts" && (
              <label className="flex items-center justify-between gap-4 text-sm">
                <span className="flex flex-col gap-0.5">
                  <span className="font-medium">A daily digest</span>
                  <span className="text-muted-foreground">One email a day with the funds you follow.</span>
                </span>
                <Switch checked={digest} onCheckedChange={setDigest} />
              </label>
            )}
            {finished && (
              <div className="flex flex-col gap-1 text-sm">
                <p className="font-medium">You are set up</p>
                <p className="text-muted-foreground">Your digest starts tomorrow morning.</p>
              </div>
            )}
          </div>
        </StepSwap>
        <div className="flex items-center justify-between gap-3">
          {at > 0 && !finished ? (
            <Button variant="ghost" onClick={() => go(at - 1)}>
              Back
            </Button>
          ) : (
            <span />
          )}
          {at === 2 ? (
            <StateButton
              status={finish.status}
              pendingLabel="Saving"
              successLabel="Saved"
              failureLabel="Not saved"
              onClick={() => void finish.run()}
            >
              Finish
            </StateButton>
          ) : at === 1 ? (
            <StateButton
              status={check.status}
              pendingLabel="Checking"
              successLabel="Checked"
              failureLabel="Not checked"
              onClick={() => void check.run()}
            >
              Continue
            </StateButton>
          ) : (
            <Button onClick={() => go(finished ? 0 : at + 1)}>{finished ? "Start again" : "Continue"}</Button>
          )}
        </div>
      </CardContent>
    </Card>
  );
}
```

Example: Offline, the firm's step shows a cross and the field says it could not be checked (`docs/system/examples/steps/setup-flow.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Card, CardContent } from "@/components/cobalt/ui/card";
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/cobalt/ui/field";
import { Input } from "@/components/cobalt/ui/input";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { StepSwap } from "@/components/cobalt/ui/step-swap";
import { Step, Steps, type StepStatus } from "@/components/cobalt/ui/steps";
import { Switch } from "@/components/cobalt/ui/switch";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

const parts = [
  { id: "name", title: "Profile" },
  { id: "firm", title: "Firm" },
  { id: "alerts", title: "Alerts" },
];

export default function Example() {
  const [at, setAt] = useState(0);
  const [direction, setDirection] = useState<"forward" | "backward">("forward");
  const [name, setName] = useState("Priya Raman");
  const [firm, setFirm] = useState("Northwind Research");
  const [digest, setDigest] = useState(true);
  const check = useAction(async () => {
    await request();
    go(2);
  });
  const finish = useAction(async () => {
    await request();
    go(parts.length);
  });
  const go = (next: number) => {
    setDirection(next > at ? "forward" : "backward");
    setAt(next);
  };
  const statusOf = (i: number): StepStatus =>
    i < at ? "done" : i > at ? "upcoming" : i === 1 && check.status === "pending" ? "pending" : i === 1 && check.status === "failure" ? "failed" : "current";
  const finished = at === parts.length;
  const partId = finished ? "finished" : parts[at]!.id;
  return (
    <Card className="w-full max-w-md">
      <CardContent className="flex flex-col gap-6">
        <Steps label="Setup" orientation="horizontal">
          {parts.map((p, i) => (
            <Step key={p.id} title={p.title} status={statusOf(i)} />
          ))}
        </Steps>
        <StepSwap id={partId} direction={direction}>
          <div className="flex flex-col gap-4">
            {partId === "name" && (
              <Field>
                <FieldLabel>Your name</FieldLabel>
                <Input value={name} autoComplete="name" onChange={(e) => setName(e.target.value)} />
                <FieldDescription>Shown to your team beside your notes.</FieldDescription>
              </Field>
            )}
            {partId === "firm" && (
              <Field>
                <FieldLabel>Your firm</FieldLabel>
                <Input value={firm} autoComplete="organization" onChange={(e) => setFirm(e.target.value)} />
                <FieldDescription>We check it against the advisers we hold.</FieldDescription>
                <FieldError reserve>
                  {check.status === "failure" ? "We could not check your firm. Try again." : ""}
                </FieldError>
              </Field>
            )}
            {partId === "alerts" && (
              <label className="flex items-center justify-between gap-4 text-sm">
                <span className="flex flex-col gap-0.5">
                  <span className="font-medium">A daily digest</span>
                  <span className="text-muted-foreground">One email a day with the funds you follow.</span>
                </span>
                <Switch checked={digest} onCheckedChange={setDigest} />
              </label>
            )}
            {finished && (
              <div className="flex flex-col gap-1 text-sm">
                <p className="font-medium">You are set up</p>
                <p className="text-muted-foreground">Your digest starts tomorrow morning.</p>
              </div>
            )}
          </div>
        </StepSwap>
        <div className="flex items-center justify-between gap-3">
          {at > 0 && !finished ? (
            <Button variant="ghost" onClick={() => go(at - 1)}>
              Back
            </Button>
          ) : (
            <span />
          )}
          {at === 2 ? (
            <StateButton
              status={finish.status}
              pendingLabel="Saving"
              successLabel="Saved"
              failureLabel="Not saved"
              onClick={() => void finish.run()}
            >
              Finish
            </StateButton>
          ) : at === 1 ? (
            <StateButton
              status={check.status}
              pendingLabel="Checking"
              successLabel="Checked"
              failureLabel="Not checked"
              onClick={() => void check.run()}
            >
              Continue
            </StateButton>
          ) : (
            <Button onClick={() => go(finished ? 0 : at + 1)}>{finished ? "Start again" : "Continue"}</Button>
          )}
        </div>
      </CardContent>
    </Card>
  );
}
```

### State precedence
- Done, current, upcoming, pending and failed: Not applicable: a step has one status.
- Pending and current: pending wins for the step being checked; the flow keeps its button's own pending state.
- Swapping and a press inside the leaving step: the arriving step wins. The leaving one takes no press.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| a step's status changes | announce | `--t-press` on `--curve` for the colours, `--t-settle` for the track | background-color, color | the same colour change |
| StepSwap's step leaves | input | `times.fade` (150ms) on `curves.inOut` | opacity, 8px translate toward the side it goes | opacity only |
| StepSwap's step arrives | input | the settle spring, the fade on `times.arrive` (220ms), both after 150ms | opacity, 8px translate from its side | opacity only |
| StepSwap's box changes height | input | the layout spring (`springs.layout`) | height | at once |

## Props

<!-- Props generated from registry/cobalt/ui/steps.tsx, registry/cobalt/ui/step-swap.tsx with TypeScript by scripts/props-table.mjs -->
### Steps

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  | The `Step`s, in order. |
| `label` | `string` |  | The list's accessible name, such as "Setup". |
| `className?` | `string` |  |  |
| `labels?` | `Partial<Record<StepStatus, string>>` | `{}` |  |
| `orientation?` | `"vertical" \| "horizontal"` | `"vertical"` | `vertical` a checklist down a card or a rail; `horizontal` the marks across the top of a flow in parts. |
| `renderLink?` | `RenderLink` | `defaultLink` | Swaps the steps' anchors for a router's links. |

### Step

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `status` | `StepStatus` |  |  |
| `title` | `string` |  |  |
| `className?` | `string` |  |  |
| `description?` | `ReactNode` |  | One line under the title, in a vertical list: what the step asks, or why it failed. |
| `href?` | `string` |  |  |

### StepSwap

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  |  |
| `id` | `string` |  |  |
| `className?` | `string` |  |  |
| `direction?` | `"forward" \| "backward"` | `"forward"` |  |

`Steps` takes `label`, `orientation`, `labels` (the words read for each status) and `renderLink`. `Step` takes `status`, `title`, `description` and `href`. `StepSwap` takes `id`, `direction` (`forward` or `backward`) and the step's content as children.

## Usage

### When to use
- A setup a person finishes over several visits, as a checklist with a bar.
- A form in two to six parts that each depend on the last, with Back and Continue.

### When not to use
- A record's history. Use Timeline instead.
- Progress through one measured task, such as an upload. Use Progress instead.
- Views of one thing a person moves between freely. Use Tabs instead.

### Rules
- `rule/steps-one-current`: When rendering the steps, give exactly 1 step `status="current"`, the first one not done, instead of none or several, because the current step is the one `aria-current="step"` names and the one a narrow box keeps its title for. Evidence: principle wcag: 1.3.1 info and relationships; single use docs/system/examples/steps/default.tsx:36. Check: test `steps.test.tsx` counts one `aria-current`.
  - Don't: `<Step status="upcoming" title="Confirm your firm" />` for every open step
  - Do: `<Step status={id === firstOpen ? "current" : "upcoming"} title="Confirm your firm" />`
- `rule/steps-checked-is-pending`: When a step waits on the server, such as a firm being checked, show `status="pending"` on it while the request runs and `failed` with a `description` if it fails, instead of marking it done on the press, because a check that has not answered is not done. Evidence: person D39; single use docs/system/examples/steps/setup-flow.tsx:51. Check: review.
  - Don't: `onClick={() => { setStatus("done"); void verify(); }}`
  - Do: `<Step status={check.status === "pending" ? "pending" : "current"} title="Firm" />`
- `rule/steps-swap-direction`: When the person goes back a step, pass `direction="backward"` to `StepSwap`, instead of leaving it forward, because the step then comes in from the side it lies on and the flow reads as moving back. Evidence: principle heuristic: match between system and the real world; single use docs/system/examples/steps/setup-flow.tsx:62. Check: review.
  - Don't: `<StepSwap id={step}>` on Back
  - Do: `<StepSwap id={step} direction={next < at ? "backward" : "forward"}>`

### Content
- `rule/steps-title-is-task`: When writing a step's `title`, name the task as a verb and its object, such as "Confirm your firm", in at most 26 characters, instead of a noun such as "Firm", because the list is read as what is left to do and a title across the top is cut at 192px. Evidence: measured 192px for a title across the top and 7.39px a character of `text-sm`, `.design-system/evidence/steps/geometry-1440.json`. Check: review.
  - Don't: `<Step title="Firm" />`
  - Do: `<Step title="Confirm your firm" />`

### Anti-slop
- `rule/steps-no-checkbox-look`: When a step is done, pass `status="done"` and let its mark draw the check on the accent's soft fill, instead of a `Checkbox`, because a step is done in its own place and a box beside it invites a press that does not do the step. Evidence: principle heuristic: match between system and the real world; person D46. Check: review.
  - Don't: `<Checkbox checked={done} aria-label="Add a photo, done" />`
  - Do: `<Step status="done" title="Add a photo" />`

### Limits
- `rule/steps-count`: When a flow has more than 6 steps, group them into parts of at most 6, instead of a longer row, because across a 400px card only the current step keeps its title and seven or more marks are a row of numbers to count. Evidence: measured a 400px row across the setup card showing 1 title of 3, `.design-system/evidence/steps/geometry-1440.json`. Check: probe docs/system/stress/steps.tsx with 12 steps.
  - Don't: 12 steps across the top of one card
  - Do: 3 parts of 4 steps, each part a step across the top

## Accessibility
Rests on an `ol` named by `label`, `aria-current="step"`, marks hidden from assistive technology and the state in words after each title.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | the steps | moves to each step that is a link | the next link | by hand |
| Enter | a step's link | opens the place to do it | the host's focus after a route change | by hand |
| Tab | a StepSwap step | moves through the step's controls; a leaving step takes no focus | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| Steps | list | `label` | none | "Setup, list, 5 items" | test |
| Step | listitem | its title and its state in words | `aria-current="step"` when current | "Confirm your firm, Current step, current step" | test |
| mark | none, `aria-hidden` | none | none | nothing | test |
| title with `href` | link | the title and its state | none | "Follow three funds, Current step, link" | test |
| StepSwap | none | none | none | the arriving step's content, as the host's focus reaches it | by hand |

## Tokens
| Part | State | Token |
|---|---|---|
| mark | all | `--r-sm` |
| mark | done | `--primary-soft`, `--primary-ink` |
| mark | current | `--foreground`, `--background` |
| mark | upcoming, pending | `--muted`, `--muted-foreground` |
| mark | failed | `--destructive` |
| track | done, else | `--primary`, `--muted` |
| title | upcoming, else | `--muted-foreground`, `--foreground` |
| StepSwap | all | `times.fade`, `times.arrive`, `springs.settle`, `springs.layout`, `distances.settle` |

## Related
- Progress: the bar that counts the steps done.
- Timeline: what happened to a record, in order.
- FirstUse: the empty state a checklist often sits beside on a first visit.
- Content changes: Swap, the general form of a change with a direction, which StepSwap specialises for steps of different heights.
