# Onboarding

> A product tour that dims the page around a cutout springing from target to target, and a get-started checklist built from the same steps. Installed as source with the shadcn CLI.

Source: https://cloudlet.dev/docs/components/onboarding

`Onboarding` walks a person through your app one step at a time: the page dims around a cutout that springs from one element to the next, and a dark pill beside it carries the step's text with Back, Next, Done and Skip. `OnboardingChecklist` turns the same steps into a get-started list in a corner of the screen ([Checklist](#checklist)); `OnboardingIsland` shows them in the Island of your Toaster while the page stays bright ([Island](#island)).

## Preview

Live preview at https://cloudlet.dev/docs/components/onboarding#preview: a small app (a header with New project, a search field and Settings) and a Start tour button; the tour walks its header in three steps and ends on a step without a target, in the centre. Controls set the overlay and how the first step goes on. The code they make:

```tsx
"use client";

import { useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

const steps: OnboardingStep[] = [
  { id: "new-project", target: "#tour-new-project", title: "Create a project", body: "Every project starts here.", advanceOn: "click" },
  { id: "search", target: "#tour-search", title: "Find anything", body: "Search projects, people and settings." },
  { id: "settings", target: "#tour-settings", title: "Make it yours", body: "Theme, notifications and your team." },
  { id: "done", title: "All set", body: "Start the tour again any time." },
];

export function ProductTour() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <button type="button" onClick={() => setOpen(true)}>Start tour</button>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} overlay="none" />
    </>
  );
}
```

- `overlay`: `dim` (the default) darkens the page around the cutout; `none` leaves it bright and pressable, with a ring on the target.
- First step: Next (the default) or `advanceOn: "click"`, where the pill has no Next and a press on New project goes on.

With every default the tour is `<Onboarding steps={steps} open={open} onOpenChange={setOpen} />`.

## Installation

A shadcn registry item: the CLI copies the source into your project, where it is yours to change. Nothing is added to `package.json`.

```sh title="Terminal"
npx shadcn@latest add https://cloudlet.dev/r/onboarding.json
```

| File | What it holds |
| --- | --- |
| `components/ui/onboarding/onboarding.tsx` | `Onboarding`, its props, steps and labels |
| `components/ui/onboarding/engine.ts` | The steps without a face: the current step, its waits, the memory and how the tour finished |
| `components/ui/onboarding/onboarding.css` | The styles, imported by the component itself |
| `components/ui/onboarding/geometry.ts` | The cutout's outline, the pill's placement and finding a step's target |
| `components/ui/onboarding/spring-channel.ts` | The interruptible spring every moving value runs on |
| `components/ui/onboarding/storage.ts` | The `storageKey` record in localStorage |
| `components/ui/onboarding/checklist.tsx` | `OnboardingChecklist`, its props and labels |
| `components/ui/onboarding/checklist.css` | The checklist's styles, imported by it |
| `components/ui/onboarding/onboarding-agent.ts` | `useOnboardingAgent`, the agent bridge for the tour; nothing runs until you import it |
| `components/ui/onboarding/checklist-agent.ts` | `useOnboardingChecklistAgent`, the same for the checklist |
| `lib/spring.ts` | The spring math, shared with the color picker |

## Usage

Describe the steps as data and control `open`. Each step has an `id`, a `title`, an optional `body` and a `target`.

```tsx title="product-tour.tsx"
"use client";

import { useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

const steps: OnboardingStep[] = [
  { id: "new", target: "#new-project", title: "Create a project", body: "Every project starts here." },
  { id: "search", target: "#search", title: "Find anything", placement: "bottom" },
  { id: "done", title: "All set", body: "Start the tour again from Help." },
];

export function ProductTour() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <button type="button" onClick={() => setOpen(true)}>Start tour</button>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} onFinish={({ reason, step }) => console.log(reason, step)} />
    </>
  );
}
```

Done finishes the tour as `completed`, Skip and Esc as `skipped`; `onFinish` and `onOpenChange(false)` hear it. Closing through `open={false}` calls neither: your app already knows.

### Steps without a target

A step without a `target` stands in the centre of the screen.

```tsx title="centered.tsx"
"use client";

import { useRef, useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

export function CenteredSteps() {
  const [open, setOpen] = useState(false);
  const [finish, setFinish] = useState("");
  const chart = useRef<HTMLDivElement>(null);
  const steps: OnboardingStep[] = [
    { id: "intro", title: "What is new", body: "A step without a target stands in the centre of the screen." },
    { id: "chart", target: chart, title: "Weekly chart", body: "Steps with a target point at it.", placement: "bottom" },
    { id: "outro", title: "That is all", body: "Done finishes the tour." },
  ];
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <div ref={chart} className="flex h-16 items-end gap-1.5 rounded-lg border p-2" aria-label="Weekly chart" role="img">
        {[40, 65, 30, 80, 55, 90, 70].map((height, day) => (
          <span key={day} className="w-3 rounded-sm bg-foreground/70" style={{ height: `${height}%` }} />
        ))}
      </div>
      <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setOpen(true)}>
        Start tour
      </button>
      <output className="text-muted-foreground">{finish}</output>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} onFinish={({ reason, step }) => setFinish(`${reason} at ${step}`)} />
    </div>
  );
}
```

### Targets

A `target` takes whichever form your app already has. `{ id }` needs no `#` or escaping, `{ testId }` is found by `data-testid` or the attribute `testIdAttribute` names (`"data-cy"`); a target the page replaces is found again.

```tsx title="targets.ts"
import type { OnboardingStep } from "@/components/ui/onboarding/onboarding";

export const steps: OnboardingStep[] = [
  { id: "selector", target: "#new-project", title: "A CSS selector" },
  { id: "id", target: { id: "new-project" }, title: "An element's id, as it is" },
  { id: "test-id", target: { testId: "search" }, title: "The test id your tests already use" },
  { id: "element", target: document.body, title: "An element you hold" },
  // A ref ({ current }) or a function that returns the element work too.
];
```

### Without dimming

`overlay="none"` leaves the page bright and pressable and rings the target. Press the buttons while the tour is open.

```tsx title="no-overlay.tsx"
"use client";

import { useRef, useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

export function RingTour() {
  const [open, setOpen] = useState(false);
  const [presses, setPresses] = useState(0);
  const format = useRef<HTMLDivElement>(null);
  const share = useRef<HTMLButtonElement>(null);
  const steps: OnboardingStep[] = [
    { id: "format", target: format, title: "Format", body: "The page stays bright and every button keeps working." },
    { id: "share", target: share, title: "Share", body: "Press it while the tour is open." },
  ];
  return (
    <div className="grid justify-items-center gap-3">
      <div className="flex items-center gap-2 rounded-lg border p-1.5 text-sm">
        <div ref={format} className="flex gap-1">
          <button type="button" className="rounded-md px-2.5 py-1 font-bold hover:bg-muted" onClick={() => setPresses((n) => n + 1)}>B</button>
          <button type="button" className="rounded-md px-2.5 py-1 italic hover:bg-muted" onClick={() => setPresses((n) => n + 1)}>I</button>
        </div>
        <button ref={share} type="button" className="rounded-md border px-2.5 py-1" onClick={() => setPresses((n) => n + 1)}>Share</button>
      </div>
      <button type="button" className="rounded-md border px-3 py-1.5 text-sm" onClick={() => setOpen(true)}>Start tour</button>
      <output className="text-sm text-muted-foreground">Presses: {presses}</output>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} overlay="none" />
    </div>
  );
}
```

### Controlled step

`step` and `onStepChange` in your state: the buttons open the tour at any step, and the state follows Next and Back.

```tsx title="controlled.tsx"
"use client";

import { useRef, useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

export function ControlledStep() {
  const [open, setOpen] = useState(false);
  const [step, setStep] = useState("inbox");
  const inbox = useRef<HTMLLIElement>(null);
  const drafts = useRef<HTMLLIElement>(null);
  const sent = useRef<HTMLLIElement>(null);
  const steps: OnboardingStep[] = [
    { id: "inbox", target: inbox, title: "Inbox", body: "New mail lands here.", placement: "right" },
    { id: "drafts", target: drafts, title: "Drafts", body: "Unsent mail waits here.", placement: "right" },
    { id: "sent", target: sent, title: "Sent", body: "Everything you sent.", placement: "right" },
  ];
  const start = (id: string) => {
    setStep(id);
    setOpen(true);
  };
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <ul className="grid w-40 gap-1 rounded-lg border p-1.5">
        <li ref={inbox} className="rounded-md px-2.5 py-1">Inbox</li>
        <li ref={drafts} className="rounded-md px-2.5 py-1">Drafts</li>
        <li ref={sent} className="rounded-md px-2.5 py-1">Sent</li>
      </ul>
      <div className="flex flex-wrap justify-center gap-2">
        {steps.map((item) => (
          <button key={item.id} type="button" className="rounded-md border px-3 py-1.5" onClick={() => start(item.id)}>
            Show {item.title}
          </button>
        ))}
      </div>
      <output className="text-muted-foreground">step: {step}</output>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} step={step} onStepChange={setStep} />
    </div>
  );
}
```

### Acting on the target

`advanceOn` moves the tour on when the person does what the step is about: `"click"` on a press on the target, `{ event, when }` on any other event there. Next still works beside it; `requireAction: true` takes Next away, so only the action goes on.

```tsx title="action-steps.ts"
import type { OnboardingStep } from "@/components/ui/onboarding/onboarding";

export const steps: OnboardingStep[] = [
  // Press New project, or Next.
  { id: "create", target: "#new-project", title: "Create a project", advanceOn: "click" },
  // Only by typing a name: no Next.
  {
    id: "name",
    target: "#project-name",
    title: "Name it",
    advanceOn: { event: "input", when: (event) => (event.target as HTMLInputElement).value.length >= 3 },
    requireAction: true,
  },
  // Your app calls target.dispatchEvent(new CustomEvent("project-created", { bubbles: true })).
  { id: "publish", target: "#publish", title: "Publish it", advanceOn: { event: "project-created" }, requireAction: true },
];
```

### Menu

`before` gets the page ready for a step: here it opens the menu, and the cutout lands on Export once it is on the page. The first step goes on with a press on File, or with Next.

```tsx title="menu.tsx"
"use client";

import { useRef, useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

export function MenuTour() {
  const [open, setOpen] = useState(false);
  const [menu, setMenu] = useState(false);
  const trigger = useRef<HTMLButtonElement>(null);
  const exportItem = useRef<HTMLButtonElement>(null);
  const steps: OnboardingStep[] = [
    {
      id: "file",
      target: trigger,
      title: "The File menu",
      body: "Press File to open it.",
      advanceOn: "click",
      // Back from the next step closes the menu again.
      before: () => setMenu(false),
    },
    {
      id: "export",
      target: exportItem,
      title: "Export",
      body: "Saves the project as a file.",
      placement: "right",
      // However the tour gets here, the menu is open; the step waits until the item is on the page.
      before: () => setMenu(true),
    },
  ];
  const close = (next: boolean) => {
    setOpen(next);
    if (!next) setMenu(false);
  };
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <div className="relative">
        <button
          ref={trigger}
          type="button"
          aria-expanded={menu}
          aria-haspopup="menu"
          className="rounded-md border px-3 py-1.5"
          onClick={() => setMenu((value) => !value)}
        >
          File
        </button>
        {menu ? (
          <div role="menu" className="absolute left-0 top-full z-10 mt-1 grid w-36 gap-0.5 rounded-lg border bg-background p-1 shadow-md">
            <button type="button" role="menuitem" className="rounded-md px-2.5 py-1 text-left" onClick={() => setMenu(false)}>
              New
            </button>
            <button ref={exportItem} type="button" role="menuitem" className="rounded-md px-2.5 py-1 text-left" onClick={() => setMenu(false)}>
              Export
            </button>
            <button type="button" role="menuitem" className="rounded-md px-2.5 py-1 text-left" onClick={() => setMenu(false)}>
              Close
            </button>
          </div>
        ) : null}
      </div>
      <button type="button" className="mt-28 rounded-md border px-3 py-1.5" onClick={() => setOpen(true)}>
        Start tour
      </button>
      <Onboarding steps={steps} open={open} onOpenChange={close} />
    </div>
  );
}
```

### Waiting for a target

A step whose target is not on the page yet waits for it, up to its `timeout` (5 s), then shows in the centre. Here the report appears after 1.5 s; Archive never does. The line under the buttons is `onWaitChange`.

```tsx title="waiting.tsx"
"use client";

import { useRef, useState } from "react";
import { Onboarding, type OnboardingStep, type OnboardingWait } from "@/components/ui/onboarding/onboarding";

export function WaitingTour() {
  const [open, setOpen] = useState(false);
  const [report, setReport] = useState(false);
  const [wait, setWait] = useState<OnboardingWait | null>(null);
  const upload = useRef<HTMLButtonElement>(null);
  const reportCard = useRef<HTMLDivElement>(null);
  const steps: OnboardingStep[] = [
    {
      id: "upload",
      target: upload,
      title: "Upload",
      body: "Add a file to build a report.",
      // Back to this step hides the report, so Next shows the wait again.
      before: () => setReport(false),
    },
    {
      id: "report",
      target: reportCard,
      title: "Your report",
      body: "It appears a moment after the upload.",
      // The report "loads" 1.5 s after the step becomes current; the step waits for it.
      before: ({ signal }) => {
        const timer = setTimeout(() => setReport(true), 1500);
        signal.addEventListener("abort", () => clearTimeout(timer));
      },
    },
    {
      id: "archive",
      target: "#docs-waiting-archive",
      title: "Archive",
      body: "Its target never appears: after 2 s the step shows in the centre, with Next.",
      advanceOn: "click",
      timeout: 2000,
    },
    { id: "done", title: "All set", body: "A step without a target never waits." },
  ];
  const close = (next: boolean) => {
    setOpen(next);
    if (!next) setReport(false);
  };
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <div className="flex flex-wrap items-start justify-center gap-3">
        <button ref={upload} type="button" className="rounded-md border px-3 py-1.5">
          Upload
        </button>
        <div className="grid h-16 w-40 place-items-center rounded-lg border border-dashed text-muted-foreground">
          {report ? (
            <div ref={reportCard} className="rounded-md bg-muted px-3 py-1.5 text-foreground">
              Report · 12 rows
            </div>
          ) : (
            "No report yet"
          )}
        </div>
      </div>
      <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setOpen(true)}>
        Start tour
      </button>
      <output className="text-muted-foreground">
        {wait ? `waiting for ${wait.for} of “${wait.step}”` : "not waiting"}
      </output>
      <Onboarding steps={steps} open={open} onOpenChange={close} onWaitChange={setWait} />
    </div>
  );
}
```

### Drag and drop

`areas` cuts drop zones out of the dimming beside the target and keeps them live, and the cutout follows the card while it is dragged. Drag the card to Done: the board's own `card-dropped` event moves the step on.

```tsx title="drag.tsx"
"use client";

import { useRef, useState, type KeyboardEvent, type PointerEvent } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

const steps: OnboardingStep[] = [
  {
    id: "drag",
    // The card is drawn anew in the column it lands in: `{ id }` finds it wherever it is.
    target: { id: "docs-drag-card" },
    // The drop zone is cut out of the dimming too, and stays live.
    areas: [{ testId: "docs-drag-done" }],
    title: "Drag the card to Done",
    body: "Hold it and move it across: the cutout follows it, and the step goes on when it lands. Next works too.",
    advanceOn: { event: "card-dropped" },
  },
  { id: "landed", target: { testId: "docs-drag-done" }, title: "Done", body: "The step went on by an event of the board, dispatched when the card landed." },
];

type Column = "todo" | "done";

export function DragTour() {
  const [open, setOpen] = useState(false);
  const [column, setColumn] = useState<Column>("todo");
  const [offset, setOffset] = useState<{ x: number; y: number } | null>(null);
  const from = useRef({ x: 0, y: 0 });
  const done = useRef<HTMLDivElement>(null);

  // The drop of the board: the card moves to the column and, landing in Done, tells the tour.
  const land = (to: Column) => {
    setColumn(to);
    if (to === "done") done.current?.dispatchEvent(new CustomEvent("card-dropped", { bubbles: true }));
  };
  const onPointerDown = (event: PointerEvent<HTMLDivElement>) => {
    if (event.button !== 0) return;
    event.currentTarget.setPointerCapture(event.pointerId);
    from.current = { x: event.clientX, y: event.clientY };
    setOffset({ x: 0, y: 0 });
  };
  const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {
    if (offset === null) return;
    setOffset({ x: event.clientX - from.current.x, y: event.clientY - from.current.y });
  };
  const onPointerUp = (event: PointerEvent<HTMLDivElement>) => {
    if (offset === null) return;
    setOffset(null);
    const zone = done.current?.getBoundingClientRect();
    const over = zone !== undefined && event.clientX >= zone.left && event.clientX <= zone.right && event.clientY >= zone.top && event.clientY <= zone.bottom;
    const to: Column = over ? "done" : "todo";
    if (to !== column) land(to);
  };
  // From the keyboard, Enter or Space sends the card to the other column.
  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
    if (event.key !== "Enter" && event.key !== " ") return;
    event.preventDefault();
    land(column === "todo" ? "done" : "todo");
  };

  const card = (
    <div
      id="docs-drag-card"
      role="button"
      tabIndex={0}
      aria-roledescription="draggable"
      aria-label={`Write the docs, in ${column === "todo" ? "To do" : "Done"}. Enter moves it to the other column.`}
      className="cursor-grab touch-none select-none rounded-md border bg-background px-3 py-2 text-left shadow-sm active:cursor-grabbing"
      style={{
        transform: offset ? `translate(${offset.x}px, ${offset.y}px) rotate(2deg)` : undefined,
        transition: offset ? "none" : "transform 200ms ease-out",
        position: "relative",
        zIndex: offset ? 1 : undefined,
      }}
      onPointerDown={onPointerDown}
      onPointerMove={onPointerMove}
      onPointerUp={onPointerUp}
      onPointerCancel={() => setOffset(null)}
      onKeyDown={onKeyDown}
    >
      Write the docs
    </div>
  );

  return (
    <div className="grid w-full max-w-sm justify-items-center gap-3 text-sm">
      <div className="grid w-full grid-cols-2 gap-3">
        <div className="grid min-h-28 content-start gap-2 rounded-lg border p-2">
          <span className="text-xs text-muted-foreground">To do</span>
          {column === "todo" ? card : null}
        </div>
        <div ref={done} data-testid="docs-drag-done" className="grid min-h-28 content-start gap-2 rounded-lg border border-dashed p-2">
          <span className="text-xs text-muted-foreground">Done</span>
          {column === "done" ? card : null}
        </div>
      </div>
      <div className="flex gap-2">
        <button
          type="button"
          className="rounded-md border px-3 py-1.5"
          onClick={() => {
            setColumn("todo");
            setOpen(true);
          }}
        >
          Start tour
        </button>
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setColumn("todo")}>
          Reset
        </button>
      </div>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} />
    </div>
  );
}
```

### Tours across pages

Change the page in a step's `before` with your router; the next step waits for its target there. Mount the tour above the routes, such as in `app/layout.tsx`.

```tsx title="app/tour.tsx"
"use client";

import { useRouter } from "next/navigation";
import { useState, type ReactNode } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

export function Tour({ children }: { children: ReactNode }) {
  const router = useRouter();
  const [open, setOpen] = useState(false);
  const steps: OnboardingStep[] = [
    { id: "projects", target: "#new-project", title: "Your projects", before: () => router.push("/") },
    { id: "billing", target: "#billing", title: "Billing", before: () => router.push("/settings/billing") },
  ];
  return (
    <>
      {children}
      <button type="button" onClick={() => setOpen(true)}>Take the tour</button>
      <Onboarding steps={steps} open={open} onOpenChange={setOpen} />
    </>
  );
}
```

### Show once

With `storageKey`, a `defaultOpen` tour that was completed or skipped stays closed on the next visit; an explicit `open` still shows it. Load the page mounts the tour again; Reset deletes the record.

```tsx title="show-once.tsx"
"use client";

import { useRef, useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

const KEY = "docs-welcome-tour";

function readRecord() {
  try {
    return localStorage.getItem(KEY) ?? "no record";
  } catch {
    return "no storage";
  }
}

function WelcomeTour({ onChange }: { onChange: () => void }) {
  const help = useRef<HTMLButtonElement>(null);
  const steps: OnboardingStep[] = [
    { id: "welcome", title: "Welcome", body: "This tour opens by itself once." },
    { id: "help", target: help, title: "Help", body: "Finish or skip it, then load the page again." },
  ];
  return (
    <>
      <button ref={help} type="button" className="rounded-md border px-3 py-1.5">Help</button>
      <Onboarding steps={steps} defaultOpen storageKey={KEY} onOpenChange={onChange} />
    </>
  );
}

export function ShowOnce() {
  const [visit, setVisit] = useState(0);
  const [record, setRecord] = useState("");
  const reset = () => {
    try {
      localStorage.removeItem(KEY);
    } catch {}
    setRecord(readRecord());
  };
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <div className="flex flex-wrap justify-center gap-2">
        <button
          type="button"
          className="rounded-md border px-3 py-1.5"
          onClick={() => {
            setVisit((n) => n + 1);
            setRecord(readRecord());
          }}
        >
          Load the page
        </button>
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={reset}>
          Reset
        </button>
      </div>
      {visit > 0 ? <WelcomeTour key={visit} onChange={() => setRecord(readRecord())} /> : null}
      <output className="max-w-full break-all text-center font-mono text-xs text-muted-foreground">{record}</output>
    </div>
  );
}
```

### Remind

`remind` brings a `defaultOpen` tour with `storageKey` back every `every` (`'6h'`) for `for` (`'7d'`), never in the middle of typing or over a dialog. After one completion it offers Don't show again. Here +6 h moves the clock forward.

```tsx title="remind.tsx"
"use client";

import { useEffect, useRef, useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";

const KEY = "docs-remind-tour";
const HOUR = 60 * 60 * 1000;
const EVERY = 6 * HOUR;
const FOR = 7 * 24 * HOUR;
const TIMES = ["firstShownAt", "lastShownAt", "finishedAt", "completedAt", "dismissedAt"] as const;

type TourRecord = { [K in (typeof TIMES)[number]]?: number };

function load(): TourRecord | null | undefined {
  try {
    const raw = localStorage.getItem(KEY);
    return raw ? (JSON.parse(raw) as TourRecord) : null;
  } catch {
    return undefined;
  }
}

function inHours(ms: number) {
  const h = Math.ceil(ms / HOUR);
  return h >= 24 ? `${Math.floor(h / 24)} d ${h % 24} h` : `${h} h`;
}

/** The record and when the tour opens on its own next: `every` after the last show, within `for` of the first. */
function describe() {
  const record = load();
  if (record === undefined) return "no storage";
  if (record === null) return "Next show: on the next load\nno record";
  const now = Date.now();
  const first = record.firstShownAt ?? now;
  const next = (record.lastShownAt ?? record.finishedAt ?? first) + EVERY;
  const end = first + FOR;
  const when =
    record.dismissedAt !== undefined
      ? "No more shows: Don’t show again is checked"
      : now >= end || next >= end
        ? "No more shows: the seven days are over"
        : next <= now
          ? "Next show: on the next load"
          : `Next show: in ${inHours(next - now)}`;
  return `${when}\n${JSON.stringify(record)}`;
}

function RemindTour() {
  const help = useRef<HTMLButtonElement>(null);
  const steps: OnboardingStep[] = [
    { id: "welcome", title: "Welcome", body: "This tour comes back every six hours for a week." },
    { id: "help", target: help, title: "Help", body: "Finish it once, and the next shows offer Don’t show again." },
  ];
  return (
    <>
      <button ref={help} type="button" className="rounded-md border px-3 py-1.5">Help</button>
      <Onboarding steps={steps} defaultOpen storageKey={KEY} remind={{ every: "6h", for: "7d" }} />
    </>
  );
}

export function Remind() {
  const [visit, setVisit] = useState(0);
  const [state, setState] = useState("");
  // The tour writes its record as it shows, finishes and as the checkbox changes; read it again often.
  useEffect(() => {
    setState(describe());
    const timer = setInterval(() => setState(describe()), 500);
    return () => clearInterval(timer);
  }, []);
  // Every time in the record six hours earlier: the clock of the example goes forward.
  const forward = () => {
    const record = load();
    if (!record) return;
    const moved: { [key: string]: unknown } = { ...record };
    for (const field of TIMES) {
      const at = record[field];
      if (at !== undefined) moved[field] = at - EVERY;
    }
    try {
      localStorage.setItem(KEY, JSON.stringify(moved));
    } catch {}
    setState(describe());
  };
  const reset = () => {
    try {
      localStorage.removeItem(KEY);
    } catch {}
    setState(describe());
  };
  const [when, record] = state.split("\n");
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <div className="flex flex-wrap justify-center gap-2">
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setVisit((n) => n + 1)}>
          Load the page
        </button>
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={forward}>
          +6 h
        </button>
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={reset}>
          Reset
        </button>
      </div>
      {visit > 0 ? <RemindTour key={visit} /> : null}
      <output className="grid max-w-full justify-items-center gap-1 text-center text-xs text-muted-foreground">
        <span>{when}</span>
        <span className="max-w-full break-all font-mono">{record}</span>
      </output>
    </div>
  );
}
```

## Island

`OnboardingIsland` shows the same steps in the Island of your [Toaster](https://cloudlet.dev/docs/components/toaster) instead of the dark pill. The page stays bright, scrolls and takes presses; a ring stands on the target and a thin thread runs from the Island to it. Start the tour, press Like, send a notification in the second step, then finish: the notification waits in the stack and opens once the tour gives the Island back.

```tsx title="island.tsx"
"use client";

import { useRef, useState } from "react";
import { useOptionalCloudlet } from "@cloudlet/toast";
import { OnboardingIsland, type OnboardingStep } from "@/components/ui/onboarding-island/onboarding-island";

export function IslandTour() {
  // The tour takes the controller of the nearest CloudletProvider: here, the Toaster of this page.
  const cloudlet = useOptionalCloudlet();
  const [open, setOpen] = useState(false);
  const [likes, setLikes] = useState(0);
  const like = useRef<HTMLButtonElement>(null);
  const send = useRef<HTMLButtonElement>(null);
  const steps: OnboardingStep[] = [
    { id: "like", target: like, title: "Like it", body: "The page stays bright: press Like, or scroll, while the tour is open." },
    { id: "send", target: send, title: "Send a notification", body: "It waits in the stack while the tour holds the Island." },
    { id: "done", title: "All set", body: "Done gives the Island back, and the notification opens." },
  ];
  return (
    <div className="grid justify-items-center gap-3">
      <div className="flex items-center gap-2 rounded-lg border p-1.5 text-sm">
        <button ref={like} type="button" className="rounded-md px-2.5 py-1 hover:bg-muted" onClick={() => setLikes((n) => n + 1)}>
          Like · {likes}
        </button>
        <button
          ref={send}
          type="button"
          className="rounded-md border px-2.5 py-1"
          disabled={!cloudlet}
          // Lives longer than the tour: a notification with a timer could run out in the stack first.
          onClick={() => cloudlet?.show({ title: "Sent during the tour", duration: null })}
        >
          Send a notification
        </button>
      </div>
      <button type="button" className="rounded-md border px-3 py-1.5 text-sm" disabled={!cloudlet} onClick={() => setOpen(true)}>
        Start tour
      </button>
      <OnboardingIsland steps={steps} open={open} onOpenChange={setOpen} labels={{ tour: "Island tour" }} />
    </div>
  );
}
```

### Installation

A registry item of its own. It brings the `onboarding` item for the steps, and `@cloudlet/toast` into `package.json`. It needs a mounted `Toaster` of the package: the `toaster` item's or your own.

```sh title="Terminal"
npx shadcn@latest add https://cloudlet.dev/r/onboarding-island.json
```

| File | What it holds |
| --- | --- |
| `components/ui/onboarding-island/onboarding-island.tsx` | `OnboardingIsland`, its props and labels |
| `components/ui/onboarding-island/onboarding-island.css` | The ring and the thread, imported by the component itself |
| `components/ui/onboarding-island/thread.ts` | The thread's path and its bend towards the pointer |
| `components/ui/onboarding-island/onboarding-island-agent.ts` | `useOnboardingIslandAgent`, the agent bridge for this tour; nothing runs until you import it |

### Usage

Render the tour inside the `CloudletProvider` of your Toaster, or pass its `controller`. It takes every prop of `Onboarding` except `overlay`; the steps, their waits, `storageKey` and `remind` work the same.

```tsx title="island-tour.tsx"
"use client";

import { useState } from "react";
import { OnboardingIsland, type OnboardingStep } from "@/components/ui/onboarding-island/onboarding-island";

const steps: OnboardingStep[] = [
  { id: "new", target: "#new-project", title: "Create a project", body: "Every project starts here." },
  { id: "done", title: "All set", body: "Start the tour again from Help." },
];

export function IslandTour() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <button type="button" onClick={() => setOpen(true)}>Start tour</button>
      <OnboardingIsland steps={steps} open={open} onOpenChange={setOpen} labels={{ tour: "Product tour" }} />
    </>
  );
}
```

**Notifications wait.** While the tour holds the Island, notifications still arrive into the stack and its badge counts them, but none opens the Island, even with `attention: 'open'`; their timers run as usual, so one that should outlive the tour takes `duration: null` or an action. Screen readers still hear them.

**Focus.** A tour opened right after a press (a Start tour button) moves focus into the Island, on Next; one that opens on its own (`defaultOpen`, `remind`) or by an agent leaves focus where it is and is announced. The Island is a landmark named by `labels.tour`: Tab and F6 reach it, ← → go back and on and Esc skips while focus is in it, and focus returns where it was when the tour ends.

**The end.** Done says "You're all set" (`labels.complete`) for about 1.3 s, 0.6 s under reduced motion, before the Island folds back; Skip and Esc fold it at once.

**Styling.** The ring and the thread take the Toaster's accent, which the component copies into `--onboarding-island-accent` on their layer, `.onboarding-island`; set `--onboarding-island-ring`, `--onboarding-island-thread` or `--onboarding-island-thread-opacity` (0.6) through `className` to change them. The Island itself follows the Toaster's theme and its own reduced-motion setting.

Your own content in the Island, without a tour, goes through [`@cloudlet/toast/guide`](https://cloudlet.dev/docs/components/toaster/guide).

## Checklist

`OnboardingChecklist` takes the same steps as tasks: a pill in the corner grows into a list, and the person does the tasks in any order. A press on a task shows it with a ring on its target; doing it there marks it done, and the list comes back with the next task ready, so Enter goes on. A step's `task` is its line in the list.

```tsx title="checklist.tsx"
"use client";

import { useEffect, useRef, useState } from "react";
import { OnboardingChecklist } from "@/components/ui/onboarding/checklist";
import type { OnboardingStep } from "@/components/ui/onboarding/onboarding";

const KEY = "docs-get-started";

function readRecord() {
  try {
    return localStorage.getItem(KEY) ?? "no record";
  } catch {
    return "no storage";
  }
}

export function Checklist() {
  const project = useRef<HTMLButtonElement>(null);
  const invite = useRef<HTMLButtonElement>(null);
  const theme = useRef<HTMLButtonElement>(null);
  const [open, setOpen] = useState(false);
  const [mount, setMount] = useState(0);
  const [record, setRecord] = useState("");
  const [projects, setProjects] = useState(0);
  // The checklist writes its record after it renders the change.
  const refresh = () => setTimeout(() => setRecord(readRecord()), 0);
  useEffect(() => setRecord(readRecord()), []);
  const steps: OnboardingStep[] = [
    { id: "project", target: project, task: "Create a project", title: "New project", body: "Press New project." },
    { id: "invite", target: invite, task: "Invite a teammate", title: "Invite", body: "Press Invite." },
    { id: "theme", target: theme, task: "Pick a theme", title: "Theme", body: "Press Theme." },
    { id: "shortcuts", task: "Learn the shortcuts", title: "Shortcuts", body: "Press ? anywhere to see them." },
  ];
  const reset = () => {
    try {
      localStorage.removeItem(KEY);
    } catch {}
    setOpen(false);
    setMount((n) => n + 1);
    setRecord(readRecord());
  };
  return (
    <div className="grid justify-items-center gap-3 text-sm">
      <div className="flex flex-wrap justify-center gap-2">
        <button ref={project} type="button" className="rounded-md border px-3 py-1.5" onClick={() => setProjects((n) => n + 1)}>
          New project{projects > 0 ? ` (${projects})` : ""}
        </button>
        <button ref={invite} type="button" className="rounded-md border px-3 py-1.5">Invite</button>
        <button ref={theme} type="button" className="rounded-md border px-3 py-1.5">Theme</button>
      </div>
      <div className="flex flex-wrap justify-center gap-2">
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setOpen(true)}>
          Get started
        </button>
        <button type="button" className="rounded-md border px-3 py-1.5" onClick={reset}>
          Reset
        </button>
      </div>
      <OnboardingChecklist
        key={mount}
        steps={steps}
        open={open}
        onOpenChange={setOpen}
        // Opened by a press on Get started: the list shows at once.
        defaultExpanded
        onDoneChange={refresh}
        onFinish={refresh}
        storageKey={KEY}
        // On a phone the Toaster of these docs shows its notifications across the bottom: lift the checklist above them.
        className="max-sm:bottom-[calc(6.5rem+env(safe-area-inset-bottom,0px))]!"
      />
      <output className="max-w-full break-all text-center font-mono text-xs text-muted-foreground">{record}</output>
    </div>
  );
}
```

**What marks a task done:** acting on its target during its show (a press, or the step's `advanceOn`), Done on a task without a target or with `requireAction: false`, or your app through a controlled `done`.

**After a task.** `afterTask="list"` (the default) opens the list again when a show ends if it was open as the show started, with the next task marked and focused; `afterTask="pill"` stays folded. The panel folds only for a show or by the person's hand, and with `storageKey` stays as they left it across reloads.

**Memory and finishing.** `storageKey` keeps the tasks done, the panel and how it finished: after All set or Dismiss a `defaultOpen` checklist stays closed, and an explicit `open` brings it back with its progress. Give it its own key, not the tour's.

```json title="localStorage"
{ "version": 1, "done": ["new", "invite"], "expanded": true, "outcome": "completed", "finishedAt": 1764400042000 }
```

**Corner.** `position` picks the corner. It knows nothing about the Toaster: when they share a corner, or on a phone, lift it through a class of yours.

```css title="globals.css"
@media (max-width: 639px) {
  .onboarding-checklist.get-started[data-position^="bottom"] {
    bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
  }
}
```

## Styling

The pill and the checklist are dark in both themes and read `--onboarding-*` variables on `.onboarding` (the tour's layer) and `.onboarding-checklist`: `background`, `foreground`, `muted`, `outline`, `button`, `primary`, `primary-foreground`, `focus`, `radius`, `max-width`, `shadow`, `dim`, `edge`, `ring`, `area-edge`, `area-ring`, `z-index`, `font-family`, `mono`; the checklist adds `--onboarding-checklist-track`, `accent`, `next`, `offset`, `width`, `radius` and `z-index`.

```css title="globals.css"
.onboarding {
  --onboarding-radius: 1.25rem;
  --onboarding-dim: rgb(0 0 0 / 0.6);
}
```

The tour's layer is in the browser's top layer (`popover="manual"`), above any `z-index`; it carries `data-pending` while a step waits and `data-dragging` during a drag. A tour over your app's own modal `<dialog>` is not supported yet.

## Reduced motion

Under `prefers-reduced-motion: reduce`, `reducedMotion`, or `data-reduced-motion` on `<body>` or `<html>`, steps and the checklist appear in place with a short fade instead of flying and growing.

## Agent

`onboarding-agent.ts` connects the tour to the [agent bridge](https://cloudlet.dev/docs/agents), experimental for now. `useOnboardingAgent(agent, props, options)` takes the tour's props and returns them wrapped:

```tsx title="tour-agent.tsx"
"use client";

import { createAgent } from "@cloudlet/agent";
import { useState } from "react";
import { Onboarding, type OnboardingStep } from "@/components/ui/onboarding/onboarding";
import { useOnboardingAgent } from "@/components/ui/onboarding/onboarding-agent";

const agent = createAgent();

const steps: OnboardingStep[] = [
  { id: "new", target: "#new-project", title: "Create a project", body: "Press New project to go on.", advanceOn: "click", requireAction: true },
  { id: "search", target: "#search", title: "Find anything" },
];

export function TourAgent() {
  const [open, setOpen] = useState(false);
  const tour = useOnboardingAgent(agent, { steps, open, onOpenChange: setOpen, storageKey: "tour" }, { label: "Product tour" });
  return <Onboarding {...tour} />;
}
```

The tour is one `OnboardingEntry` in the snapshot — `ref`, `component: 'onboarding'`, `label`, `open`, `step`, `steps` (each an `OnboardingEntryStep` with `id`, `title`, `body` and `waitsForPerson`), `waiting` and `remind` — readable while the tour is closed. Its verbs, an `OnboardingAction`, are `start [id?]`, `next`, `back`, `go [id]` and `close`; each answers with `{ open, step }`.

- **The person's steps stay theirs.** `waitsForPerson` is true for a step with `requireAction` and a target; no verb moves past it.
- **Waiting.** `waiting` is an `OnboardingEntryWaiting` (`step`, `for`, `target` as it reads: `id "billing"`, `test id "billing" ([data-testid])`) while the step waits; `next` is refused meanwhile.
- **Changes** reach `agent.subscribe` under `open` and `step` with their author: `user`, `agent`, `app`, or `system` for a reminder. Closing carries `completed` or `skipped`.
- **Reminders.** `remind` is `null` or an `OnboardingEntryRemind` (`nextAt`, `endsAt`, `dismissed`); `close` only puts the tour off, and only the person checks Don't show again.

### Checklist and the agent

`useOnboardingChecklistAgent(agent, props, options)` from `checklist-agent.ts` does the same for the checklist:

```tsx title="get-started-agent.tsx"
"use client";

import { createAgent } from "@cloudlet/agent";
import { OnboardingChecklist } from "@/components/ui/onboarding/checklist";
import { useOnboardingChecklistAgent } from "@/components/ui/onboarding/checklist-agent";
import type { OnboardingStep } from "@/components/ui/onboarding/onboarding";

const agent = createAgent();

const steps: OnboardingStep[] = [
  { id: "new", target: "#new-project", task: "Create a project", title: "New project" },
  { id: "shortcuts", task: "Learn the shortcuts", title: "Shortcuts", body: "Press ? anywhere to see them." },
];

export function GetStartedAgent() {
  const checklist = useOnboardingChecklistAgent(agent, { steps, defaultOpen: true, storageKey: "get-started" }, { label: "Get started" });
  return <OnboardingChecklist {...checklist} />;
}
```

The checklist is one `OnboardingChecklistEntry` — `ref`, `component: 'onboarding-checklist'`, `label`, `open`, `expanded`, `active`, `done`, `total` and `tasks` (each an `OnboardingChecklistEntryTask` with `id`, `task`, `title`, `body` and `done`). Its verbs, an `OnboardingChecklistAction`, are `expand`, `collapse`, `show [id]` and `hide`; each answers with `{ expanded, active, done }`. No verb marks a task done, opens or dismisses the checklist: an agent can lead the person to a task, not do it for them. Changes carry their author as in the tour; the list opened again after a show goes with whoever ended it.

### Island and the agent

`useOnboardingIslandAgent(agent, props, options)` from `onboarding-island-agent.ts` connects an `OnboardingIsland` the same way: the same `OnboardingEntry`, verbs and rules, its `label` taken from `labels.tour` unless `options.label` names it.

```tsx title="island-tour-agent.tsx"
"use client";

import { createAgent } from "@cloudlet/agent";
import { useState } from "react";
import { OnboardingIsland, type OnboardingStep } from "@/components/ui/onboarding-island/onboarding-island";
import { useOnboardingIslandAgent } from "@/components/ui/onboarding-island/onboarding-island-agent";

const agent = createAgent();

const steps: OnboardingStep[] = [
  { id: "new", target: "#new-project", title: "Create a project" },
  { id: "search", target: "#search", title: "Find anything" },
];

export function IslandTourAgent() {
  const [open, setOpen] = useState(false);
  const tour = useOnboardingIslandAgent(agent, { steps, open, onOpenChange: setOpen });
  return <OnboardingIsland {...tour} />;
}
```

**The Island is taken.** Only the tour's record describes the step. With `toasterAgent` of the same controller on the agent, the Toaster's record says just that the Island is held, `guest: { ref }` with the tour's `ref` (the adapter passes it as `guestRef`; the Island keeps `labels.tour` as its name for screen readers), and its `open` and `show` are refused with "A tour is in progress in the Island" until the tour ends.

`OnboardingAgentOptions` and `OnboardingChecklistAgentOptions` take `name` (default `onboarding` and `checklist`) and `label` (default `Tour` and `Checklist`); `ONBOARDING_VERBS` and `ONBOARDING_CHECKLIST_VERBS` are the verbs' text for a model.

The adapters carry copies of the bridge's protocol types, so they need no `@cloudlet/agent` import: `AgentEntryShape`, `AgentSignalShape`, `AgentValueShape`, `AgentPermissionShape`, `AgentStepCallShape`, `AgentStepNamesShape`, `AgentStepCheckShape`, `AgentRunContextShape`, `AgentRunOutcomeShape`, `AgentSummonOutcomeShape`, `AgentChangeShape`, `AgentVerbsShape`, `AgentComponentShape` and `AgentConnectorShape`. The tour's and the checklist's adapters share the author of a change through `commitNow`, `useChangeAuthor` with `ChangeAuthor` and `ChangeSourceShape`, and `useAgentPort` with `AgentPortMethods`, which you do not need to call.

## API Reference

### Props

`OnboardingProps`; only `steps` is required.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `steps` | `readonly OnboardingStep[]` | — | The steps in order; every `id` unique. |
| `open` | `boolean` | — | Whether the tour is shown (controlled); always shows it, whatever the record of `storageKey` says. |
| `defaultOpen` | `boolean` | `false` | Opens the tour by itself after mount when it owns `open`, unless `storageKey` says it was finished; with `remind`, when a reminder is due. |
| `onOpenChange` | `(open: boolean) => void` | — | Called when the person closes the tour (Done, Skip, Esc), and with `true` when a reminder opens it after mount; not when your app closes it through `open`. |
| `step` | `string` | — | Id of the current step (controlled). |
| `defaultStep` | `string` | the first step | The step an uncontrolled tour starts on, and returns to when it opens again. |
| `onStepChange` | `(id: string) => void` | — | Called with the new step's id on Next, Back, the keys or a press on an `advanceOn` target. |
| `onWaitChange` | `(wait: OnboardingWait \| null) => void` | — | The current step starts or stops waiting: `{ step, for: "before" \| "target" }` when it begins and when `for` changes, `null` once it shows or the tour closes; not on unmount. |
| `onFinish` | `(finish: OnboardingFinish) => void` | — | How the person closed the tour: `{ reason: "completed" \| "skipped", step }`. |
| `storageKey` | `string` | — | The localStorage key of the tour's record ([Show once](#show-once), [Remind](#remind)). |
| `remind` | `OnboardingRemind` | — | `{ every?, for? }`: a `defaultOpen` tour with `storageKey` opens on its own again ([Remind schedule](#remind-schedule)). |
| `overlay` | `"dim" \| "none"` | `"dim"` | `dim` darkens the page around the cutout and catches presses beside the target; `none` rings the target and leaves the page pressable. |
| `exit` | `"collapse" \| "complete"` | `"collapse"` | How the tour leaves when your app closes it through `open`: `collapse` folds it back into the element it opened from, like Skip; `complete` opens the cutout past the screen, like Done. |
| `labels` | `Partial<OnboardingLabels>` | `DEFAULT_LABELS` | Button texts and announcements; anything left out keeps its English default. |
| `reducedMotion` | `boolean` | `false` | Moves without flight, as under the system's reduced motion. |
| `testIdAttribute` | `string` | `"data-testid"` | The attribute a `{ testId }` target is found by, such as `"data-cy"` or `"data-test"`. |
| `className` | `string` | — | Added to the tour's layer; set `--onboarding-*` variables through it. |

The tour renders nothing on the server and decides after mount. A tour of one step has no count and no Back. In development the console warns about a target that can never point at anything, a step whose target was not found, a `remind` it cannot read or without `storageKey`, and a `before` or `when` that throws.

### Steps

`OnboardingStep`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | Unique in the list; `step`, `defaultStep` and `onStepChange` speak in ids. |
| `target` | `OnboardingTarget` | `string` (a selector), `{ id: string }` (by `getElementById`), `{ testId: string }` (by `testIdAttribute`, escaped for you), an `Element`, `RefObject<Element \| null>` or `() => Element \| null`. Without one the pill stands in the centre. A target the page replaces is found again by the same `target`. |
| `title` | `string` | The pill's heading and the dialog's name. |
| `body` | `string` | The step's text and the dialog's description. |
| `placement` | `OnboardingPlacement` | `"auto"` (default), `"top"`, `"bottom"`, `"left"` or `"right"`: the side of the target for the pill; it flips when that side has no room. |
| `advanceOn` | `"click" \| OnboardingAdvance` | The step also goes on when the person presses its target, or on `{ event, when? }`: when `event` happens on the target or one of its `areas`, or bubbles up to it, and `when`, if given, returns `true`. It goes on after your own handlers have run; a `stopPropagation()` inside the target hides the event. Next and → still go on, unless the step has `requireAction`. |
| `requireAction` | `boolean` | The step goes on only by the person's action on its target: no Next, → does nothing, the agent's `next` is refused. Without `advanceOn` a press on the target goes on. A step without a target, or with one that never shows, keeps Next. Default `false` in the tour, `true` for a task with a target in the checklist. |
| `areas` | `readonly OnboardingTarget[]` | More elements cut out of the dimming and kept live beside the target, such as drop zones; followed as they move, in the Tab round, and listened on by `advanceOn`. With `overlay="dim"` the rest of the page stays blocked. |
| `timeout` | `number` | How long, in ms from the moment the step became current, it waits for `before` and its target: `5000` by default, `0` not to wait, `Infinity` as long as it is current. Past it the step shows in the centre and a step with `requireAction` gets Next back; a target that shows up later is still taken at the next press, key or transition on the page. |
| `task` | `string` | The step's short line in a checklist; without it the checklist shows `title`. The tour does not read it. |
| `before` | `(context: OnboardingBeforeContext) => void \| Promise<void>` | Gets the page ready each time the step becomes current, however it got there; a returned promise is waited for within `timeout`. `context.signal` aborts when the step stops being current, the tour closes or unmounts, or `timeout` runs out. A step that should close a menu again closes it in the `before` of the step before it. |

During a drag — a pointer pressed and moved, an HTML drag, or a library such as dnd-kit — the tour follows the target every frame, the pill holds still and lets drops through, and Esc and the arrows belong to the drag.

### Remind schedule

`OnboardingRemind` is `{ every?: OnboardingDuration; for?: OnboardingDuration }`, `'6h'` and `'7d'` by default; `for` counts from the first show, `every` from the last. `OnboardingDuration` is ``number | `${number}${"s" | "m" | "h" | "d" | "w"}` ``: milliseconds, or a number and a unit (`'90s'`, `'1.5d'`).

- It checks at mount and when the person comes back to the tab, never on a timer; while focus is in a field or a modal dialog is open, it waits until they leave it.
- Skip and Esc put it off until `every` has passed again; completing it does not stop the reminders, only Don't show again and the end of `for` do.
- With a controlled `open`, `remind` only offers the checkbox and keeps the record. Opening on its own after mount calls `onOpenChange(true)`.
- `useOnboardingReminder({ enabled, storageKey, remind, onDue })` is the hook the tour runs itself; `OnboardingReminderOptions` take `enabled` and `onDue({ initial })`.

The record stays version 1 when a reminder writes it:

```json title="localStorage"
{ "version": 1, "firstShownAt": 1764400000000, "lastShownAt": 1764421600000, "outcome": "skipped", "finishedAt": 1764421610000, "completedAt": 1764400042000, "dismissedAt": 1764421605000 }
```

`completedAt` is the first completion, `dismissedAt` is set while Don't show again is checked. To start everyone over, put a version in the key: `storageKey="welcome-v2"`.

### Keyboard and screen readers

Opening moves focus into the pill, from the element that had it, and closing returns focus there. → and ← go to the next and the previous step, → on the last step finishes the tour, and Esc skips it. The keys are left alone while focus is in a field, a widget that takes arrows or something draggable, during a drag, or when your page has handled the key. Tab goes round the pill's buttons, the target and the step's areas.

The pill is a non-modal `role="dialog"` named by the step's title and described by its text. A live region speaks each step a moment after it shows, "Step 2 of 5. Create a project. Every project starts here."; while a step waits the pill is `aria-busy="true"` and the region says "Loading…".

The checklist's pill is a button with `aria-expanded`, named by its progress, "Get started, 2 of 5 done"; Enter opens the panel, a region with the tasks, Collapse and Dismiss. A done task stays with `aria-disabled`. Esc and Collapse fold the panel and return focus to the pill; after a task's show focus lands on the next task, or on the pill with `afterTask="pill"`. A live region speaks "Create a project: done. 2 of 5." and "All set".

### Labels

`OnboardingLabels`; `{n}` is the step's place and `{total}` the number of steps.

| Key | Default | Where |
| --- | --- | --- |
| `next` | `Next` | the button to the next step |
| `done` | `Done` | the button on the last step, instead of Next |
| `back` | `Back` | the button to the previous step, disabled on the first |
| `skip` | `Skip` | the button that closes the tour as skipped |
| `counter` | `{n}/{total}` | the count in the pill |
| `position` | `Step {n} of {total}` | spoken before the step's title and text |
| `waiting` | `Loading…` | spoken in place of the step's text while the step waits |
| `dontShowAgain` | `Don't show again` | the checkbox of a `remind` tour after its first completion |

### Island props

`OnboardingIslandProps`: every prop of `OnboardingProps` except `overlay`, with these differences; only `steps` is required.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `controller` | `ReactCloudletController \| null` | the nearest `CloudletProvider`'s | The controller whose `Toaster` carries the tour. Without one, or without a mounted Toaster, the tour shows nothing until they come, and development says so. |
| `exit` | `"collapse" \| "complete"` | `"collapse"` | How the tour leaves when your app closes it through `open`: `collapse` folds the Island back at once, like Skip; `complete` says "You're all set" first, like Done. |
| `labels` | `Partial<OnboardingIslandLabels>` | `ISLAND_LABELS` | The tour's labels plus `tour` and `complete`. |
| `guestRef` | `string` | `labels.tour` | The name agents read for the tour in the Toaster's record, `guest: { ref }`. `useOnboardingIslandAgent` sets it to the tour record's `ref`; screen readers keep naming the Island by `labels.tour`. |
| `reducedMotion` | `boolean` | `false` | The ring and the thread move without flight or bend. The Island follows the Toaster's own setting. |
| `className` | `string` | — | Added to the layer of the ring and the thread; set `--onboarding-island-*` through it. |

`OnboardingIsland` re-exports the step types, `OnboardingStep`, `OnboardingTarget`, `OnboardingPlacement`, `OnboardingAdvance`, `OnboardingBeforeContext`, `OnboardingWait` and `OnboardingFinish`, so a tour in the Island imports nothing from `onboarding.tsx`. In the Island, Don't show again is a quiet button rather than a checkbox: it finishes the tour as skipped and stops the reminders.

### Island labels

`OnboardingIslandLabels`: the keys of `OnboardingLabels` and two of its own.

| Key | Default | Where |
| --- | --- | --- |
| `tour` | `Product tour` | the Island's name for screen readers while the tour holds it, and the tour's name for agents |
| `complete` | `You're all set` | what the Island says for a moment after Done |

### Checklist props

`OnboardingChecklistProps`; only `steps` is required. `open`, `expanded`, `active` and `done` are each controlled or not.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `steps` | `readonly OnboardingStep[]` | — | The tasks: the tour's steps, shown by `task` (else `title`). |
| `open` | `boolean` | — | Whether the checklist is on the screen (controlled); shows it even when it finished. |
| `defaultOpen` | `boolean` | `false` | Shows it after mount when it owns `open`, unless `storageKey` says it finished. |
| `onOpenChange` | `(open: boolean) => void` | — | Called with `false` when it leaves on its own: Dismiss, or every task done; not when your app closes it. |
| `expanded` | `boolean` | — | Whether the panel with the list is open rather than the pill (controlled). |
| `defaultExpanded` | `boolean` | `false` | Whether the panel starts open; each new show starts so. With `storageKey`, the way the person last left it wins. |
| `onExpandedChange` | `(expanded: boolean) => void` | — | The person opened or folded the panel (the pill, Collapse, Esc), a task's show folded it or `afterTask` opened it again, or the All set beat did. |
| `afterTask` | `OnboardingChecklistAfterTask` | `"list"` | When a task's show ends: `"list"` opens the panel again if it was open as the show started, with the next task marked and focused; `"pill"` stays folded. |
| `active` | `string \| null` | — | Id of the task shown now (controlled); a task that is done or not in the list does not show. |
| `onActiveChange` | `(active: string \| null) => void` | — | The id when the person presses a task that is not done; `null` when its show ends. |
| `done` | `readonly string[]` | — | Ids of the tasks done (controlled); ids the list does not have are not counted. |
| `defaultDone` | `readonly string[]` | `[]` | Tasks done at first when it owns `done`; the `storageKey` record wins when there is one. |
| `onDoneChange` | `(done: readonly string[]) => void` | — | The new list when a task gets done in its show. |
| `onFinish` | `(finish: OnboardingChecklistFinish) => void` | — | `{ reason: "completed" \| "dismissed" }` after the All set beat or Dismiss; not when your app closes it. |
| `storageKey` | `string` | — | The localStorage key of the checklist's own record, not the tour's. |
| `position` | `OnboardingChecklistPosition` | `"bottom-right"` | `"bottom-right"`, `"bottom-left"`, `"top-right"` or `"top-left"`, `--onboarding-checklist-offset` (12px) from the edges plus the safe area. |
| `overlay` | `"dim" \| "none"` | `"none"` | How a task's show points at its target: `none` rings it, `dim` darkens the page around it. |
| `labels` | `Partial<OnboardingChecklistLabels>` | `DEFAULT_CHECKLIST_LABELS` | Texts and announcements; anything left out keeps its English default. |
| `reducedMotion` | `boolean` | `false` | Moves without growth, as under the system's reduced motion. |
| `testIdAttribute` | `string` | `"data-testid"` | The attribute a `{ testId }` target is found by, as in the tour. |
| `className` | `string` | — | Added to the checklist's layer and to its task's show; set `--onboarding-*` and `--onboarding-checklist-*` through it. A Tailwind utility here needs `!`. |

A task's show is the tour's `Onboarding` of that one step, so its `placement`, `before` and `timeout` work as in the tour; Close, Esc and a press on the pill end it without marking the task. A task whose target was not found shows in the centre with Close alone and is not marked, and acting on a target while its task is not shown marks nothing.

`OnboardingChecklistFinish` is `{ reason: OnboardingChecklistOutcome }`, where `OnboardingChecklistOutcome` is `"completed" | "dismissed"`, the same word the record keeps as `outcome`. The record is `{ version: 1, done: string[], expanded?, outcome?, finishedAt? }`; ids the steps no longer have are ignored and new tasks start not done. The checklist reuses helpers that `onboarding.tsx` exports and you do not need to call: `MOTION`, `useControllable`, `prefersStill`, `snapshot`, `useTargetWarnings` and the `OnboardingTargetFound` context.

### Checklist labels

`OnboardingChecklistLabels`; `{n}` is the number of tasks done, `{total}` the number of tasks and `{task}` a task's line.

| Key | Default | Where |
| --- | --- | --- |
| `title` | `Get started` | the pill's caption and the panel's heading |
| `counter` | `{n}/{total}` | the count in the pill |
| `progress` | `{n} of {total}` | the count beside the heading, and in the pill's name |
| `collapse` | `Collapse` | the button that folds the panel |
| `dismiss` | `Dismiss` | the button that puts the checklist away |
| `allSet` | `All set` | the pill's caption once every task is done, also spoken |
| `done` | `done` | spoken after a done task's name, and in the pill's name |
| `close` | `Close` | the button that ends a task's show without marking it |
| `taskDone` | `{task}: done. {n} of {total}.` | spoken when a task gets done |
