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

## Description
Lays out a settings page: the list of sections beside the one that is open on a wide screen, and on a phone the list as a page of its own that each section replaces, with a link back.

`import { SettingsLayout, SettingsPanel, SettingsGroup, SettingsRow, type SettingsSection } from "@/components/cobalt/ui/settings-layout"`, source `registry/cobalt/ui/settings-layout.tsx`, status `ready`.
`import { useUndoable, pendingCommit, UNDO_WINDOW_MS } from "@/lib/cobalt/use-undoable"`, source `registry/cobalt/lib/use-undoable.ts`.
Foundation: `hand-rolled`. Traps checked: `trap/current-unmarked`, `trap/narrow-hidden-nav`, `trap/link-as-button`, `trap/focus-ring-shape`, `trap/text-measure`, `trap/touch-hover-flash`, `trap/weight-shift`, `trap/loading-layout-shift`, `trap/label-unbound`, `trap/toast-timer`.

`trap/current-unmarked` is answered by `aria-current="page"` on the open section's link, drawn as the pill that slides to it (ARIA, Motion). `trap/narrow-hidden-nav` by the phone list, which is the page at the list's address, so a section is never out of reach (Rules). `trap/link-as-button` by real links with `href` through `renderLink`, so Back and a shared link work (Rules). `trap/focus-ring-shape` by the shared outline on each row's 12px corner (States). `trap/text-measure` by section names that wrap and hints cut at two lines (Limits). `trap/touch-hover-flash` by Tailwind's `(hover: hover)` guard on the row's fill and ink (States). `trap/weight-shift` by one weight for every row, so the open one changes ink under the pill, never weight (States). `trap/loading-layout-shift` by every section kept mounted in one cell, so the layout is the tallest section's height from the first frame, and by the row's save line, which keeps its height as saves go (States). `trap/label-unbound` by SettingsRow, a `Field` whose name labels the control inside (ARIA). `trap/toast-timer` by `useUndoable`, whose window is its own, held while the toast is pointed at or focused and while the tab is hidden, with the toast going before the commit (Rules).

### Foundation
Not applicable: hand-rolled.

| Given by the foundation | Added by the team |
|---|---|
| Not applicable: hand-rolled, with `BackLink` from `registry/cobalt/ui/back-link.tsx` and links through `renderLink` (D19) | From 1024px up, a 16rem list beside the section, held in view under a 96px top bar inside `AppShellMain`, the page's own scroller (`sticky`, `--page-top` from the top, 96px unless a host sets it, as PageColumns' rail does), or wherever the host passes `sticky`, and scrolling with the section anywhere else, so a preview inside a longer page never has it drift down through its frame; each row a muted link in ink when open, over one `aria-hidden` pill measured from the open row through `registry/cobalt/lib/use-indicator.ts` and slid on `duration-settle ease-settle`, the `--thumb` fill and the only fill a row takes there (D18, D43); below 1024px the list on a card with 4px around 12px rows (D38), each with its hint and a chevron, and an open section that replaces it with a back link at its top; `index` for the list's own address, where a wide screen shows the first section; the page's h1 names the nav; `SettingsPanel`, one per section, all kept mounted in one grid cell with the hidden ones `invisible` and `inert` from 1024px up and `hidden` below it, as Tabs' panels are, so from 1024px up the layout is the tallest section's height from the first frame and a switch moves nothing, while a phone gives each section only its own height; `keepMounted={false}` for a heavy section; `SettingsGroup`, a quiet h3 over one card of rows 4px in (D38), split by padding (D11), with an `action` at the heading's end; `SettingsRow`, a `Field` with the name, a description, and the control at the end that drops under the words when narrow, a `status` that turns the description's line into a SaveLine of the same height, or with `href` one link with its `value` before a chevron; `useUndoable`, an Undo that commits late, after Tag's pending delete: the change shows at once, the window of 10 seconds stops while the toast is pointed at or focused and while the tab is hidden, and when it runs out the toast goes and then the server hears of it, as it does when the toast is closed or the person leaves, never after Undo, and a failed commit puts it back with a toast that stays and offers Retry |

## Examples
A settings page built from groups and rows: switches and pickers save on the press and say so in the row, the profile saves as you type, and a device signs out at once with Undo. On a phone the section has the page to itself, with a link back to the list.

Real uses, 0 call sites (`rg -n "<SettingsLayout\b" app registry --glob '!registry/cobalt/ui/*'`): the part is new. The first source app draws the same frame for its settings (`docs/research/2026-10-17-bespoke-sources.md`, section 2.4); the settings scene in `docs/system/examples/settings-layout/default.tsx` is the full page.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/settings-layout/default.tsx` | default | A settings page built from groups and rows: switches and pickers save on the press and say so in the row, the profile saves as you type, and a device signs out at once with Undo; every section is a SettingsPanel, so a switch moves nothing |
| Not applicable: the index is reached through the back link on a phone in default.tsx, which passes `index` at the list's own address | state:index | At the list's own address a phone shows the list, each section with its hint; a wide screen shows the first section beside it |
| `docs/system/examples/settings-layout/default.tsx` | state:saving | A row's line says Saving once a save is slow, then Saved, or Not saved with the switch moved back |
| `docs/system/examples/settings-layout/default.tsx` | state:link-row | Language and dates, a row that opens Display with its value before the chevron |
| `docs/system/examples/settings-layout/default.tsx` | state:undo | Sign out of a device at once, with Undo; the server hears of it when the window ends |
| `docs/system/examples/settings-layout/default.tsx` | composition:Switch | Switches that save at once and move back on a refusal |
| `docs/system/examples/settings-layout/default.tsx` | composition:SaveLine | The profile's save line at the end of its group's heading |

Example: A settings page built from groups and rows: switches and pickers save on the press and say so in the row, the profile saves as you type, and a device signs out at once with Undo; every section is a SettingsPanel, so a switch moves nothing (`docs/system/examples/settings-layout/default.tsx`)

```tsx
import { useRef, useState, type ReactNode } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";
import { SaveLine } from "@/components/cobalt/ui/save-line";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";
import {
  SettingsGroup,
  SettingsLayout,
  SettingsPanel,
  SettingsRow,
  type SettingsSection,
} from "@/components/cobalt/ui/settings-layout";
import { Switch } from "@/components/cobalt/ui/switch";
import { Toaster } from "@/components/cobalt/ui/toaster";
import type { RenderLink } from "@/lib/cobalt/link";
import { Presence, PresenceRow } from "@/lib/cobalt/presence";
import { useAction } from "@/lib/cobalt/use-action";
import { useAutosave, useSaveState } from "@/lib/cobalt/use-autosave";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";
import { useUndoable } from "@/lib/cobalt/use-undoable";

const sections: SettingsSection[] = [
  { href: "#settings/account", label: "Account", hint: "Name, work email and language" },
  { href: "#settings/notifications", label: "Notifications", hint: "Filing alerts and the weekly digest" },
  { href: "#settings/display", label: "Display", hint: "Row density and the first day of the week" },
  { href: "#settings/devices", label: "Devices", hint: "Where you are signed in" },
];

const offline = () => !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";

// Stands in for your API call. It answers after 700ms, and fails while the browser is offline or the
// address has ?network=offline (the docs frame's Offline control sets it).
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      if (offline()) reject(new Error("offline"));
      else resolve();
    }, 700),
  );

function Section({ heading, children }: { heading: string; children: ReactNode }) {
  return (
    <section className="flex flex-col gap-6">
      <h2 className="text-xl font-semibold tracking-tight">{heading}</h2>
      {children}
    </section>
  );
}

/** A switch that saves on the flip: it moves at once, the row says how the save went, and a refusal moves it back. */
function SwitchRow({ id, label, description, initial }: { id: string; label: string; description: string; initial: boolean }) {
  const setting = useOptimisticToggle(`setting:${id}`, initial, { send: request });
  const status = useSaveState(setting.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Switch checked={setting.on} onCheckedChange={setting.flip} />
    </SettingsRow>
  );
}

/** A picker that saves on the choice; a refusal puts the last saved choice back. */
function PickerRow({
  label,
  description,
  options,
  initial,
}: {
  label: string;
  description: string;
  options: { value: string; label: string }[];
  initial: string;
}) {
  const [value, setValue] = useState(initial);
  const saved = useRef(initial);
  const save = useAction(async (next: string) => {
    try {
      await request();
      saved.current = next;
    } catch (error) {
      setValue(saved.current);
      throw error;
    }
  });
  const status = useSaveState(save.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Select
        items={options}
        value={value}
        onValueChange={(next) => {
          setValue(String(next));
          void save.run(String(next));
        }}
      >
        <SelectTrigger className="w-40">
          <SelectValue />
        </SelectTrigger>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </SettingsRow>
  );
}

function Account({ renderLink }: { renderLink: RenderLink }) {
  const [draft, setDraft] = useState({ name: "Maya Chen", email: "maya.chen@example.com" });
  const latest = useRef(draft);
  const stored = useRef(draft);
  const autosave = useAutosave(() => {
    const next = latest.current;
    if (next.name === stored.current.name && next.email === stored.current.email) return null;
    return request().then(
      () => {
        stored.current = next;
        return true;
      },
      () => false,
    );
  });
  const edit = (field: "name" | "email", value: string) => {
    latest.current = { ...latest.current, [field]: value };
    setDraft(latest.current);
    autosave.schedule();
  };
  return (
    <Section heading="Account">
      <SettingsGroup heading="Profile" action={<SaveLine state={autosave.state} onRetry={() => void autosave.retry()} />}>
        <SettingsRow label="Name" description="Shown on your notes and shared searches." layout="stacked">
          <Input value={draft.name} onChange={(e) => edit("name", e.target.value)} />
        </SettingsRow>
        <SettingsRow label="Work email" description="Where filing alerts go." layout="stacked">
          <Input type="email" value={draft.email} onChange={(e) => edit("email", e.target.value)} />
        </SettingsRow>
      </SettingsGroup>
      <SettingsGroup heading="Region">
        <SettingsRow label="Language and dates" href="#settings/display" value="English, Monday first" renderLink={renderLink} />
      </SettingsGroup>
    </Section>
  );
}

function Notifications() {
  return (
    <Section heading="Notifications">
      <SettingsGroup heading="Email">
        <SwitchRow id="filings" label="New filings" description="When a fund you follow files a 13F, an N-PORT or a Form D." initial />
        <SwitchRow id="late" label="Late filings" description="When a fund you follow misses its deadline." initial />
        <SwitchRow id="digest" label="Weekly digest" description="Every Monday at 8:00 AM, what changed last week." initial={false} />
      </SettingsGroup>
    </Section>
  );
}

function Display() {
  return (
    <Section heading="Display">
      <SettingsGroup heading="Tables">
        <PickerRow
          label="Row density"
          description="Compact fits more rows on a screen."
          initial="comfortable"
          options={[
            { value: "comfortable", label: "Comfortable" },
            { value: "compact", label: "Compact" },
          ]}
        />
      </SettingsGroup>
      <SettingsGroup heading="Dates">
        <PickerRow
          label="Weeks start on"
          description="For calendars and weekly totals."
          initial="monday"
          options={[
            { value: "monday", label: "Monday" },
            { value: "sunday", label: "Sunday" },
          ]}
        />
      </SettingsGroup>
    </Section>
  );
}

const signedIn = [
  { id: "mac", name: "MacBook Pro, Boston", seen: "Active now", current: true },
  { id: "phone", name: "iPhone 15, Boston", seen: "Last active 2 hours ago", current: false },
  { id: "pc", name: "Windows PC, New York", seen: "Last active 3 weeks ago", current: false },
];

function Devices() {
  const [hidden, setHidden] = useState<string[]>([]);
  // Lives in the list, not the row, so a row that goes away still commits when its window ends.
  const undoable = useUndoable();
  return (
    <Section heading="Devices">
      <SettingsGroup heading="Signed in">
        {/* A row that goes Leaves and one that comes back Grows, so the rows under it close up smoothly. */}
        <Presence>
          {signedIn
            .filter((device) => !hidden.includes(device.id))
            .map((device) => (
              <PresenceRow as="div" key={device.id}>
                <SettingsRow label={device.name} description={device.seen}>
                  {device.current ? (
                    <span className="text-sm text-muted-foreground">This device</span>
                  ) : (
                    <Button
                      variant="secondary"
                      size="sm"
                      onClick={() =>
                        undoable.run({
                          message: `Signed out of ${device.name}`,
                          failed: `Could not sign out of ${device.name}`,
                          apply: () => setHidden((was) => [...was, device.id]),
                          undo: () => setHidden((was) => was.filter((id) => id !== device.id)),
                          commit: request,
                        })
                      }
                    >
                      Sign out
                    </Button>
                  )}
                </SettingsRow>
              </PresenceRow>
            ))}
        </Presence>
      </SettingsGroup>
    </Section>
  );
}

export default function Example() {
  // Stands in for your router: null is the list's own address, /settings.
  const [path, setPath] = useState<string | null>("#settings/notifications");
  const current = path ?? sections[0]!.href;
  const renderLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href === "#settings" ? null : href);
      }}
    >
      {children}
    </a>
  );
  // Every section is passed, so the layout holds the tallest one's height and a switch moves nothing.
  return (
    <div className="w-full">
      <SettingsLayout heading="Settings" sections={sections} current={current} index={path === null} indexHref="#settings" renderLink={renderLink}>
        <SettingsPanel href="#settings/account">
          <Account renderLink={renderLink} />
        </SettingsPanel>
        <SettingsPanel href="#settings/notifications">
          <Notifications />
        </SettingsPanel>
        <SettingsPanel href="#settings/display">
          <Display />
        </SettingsPanel>
        <SettingsPanel href="#settings/devices">
          <Devices />
        </SettingsPanel>
      </SettingsLayout>
      <Toaster />
    </div>
  );
}
```

Example: Switches that save at once and move back on a refusal (`docs/system/examples/settings-layout/default.tsx`)

```tsx
import { useRef, useState, type ReactNode } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";
import { SaveLine } from "@/components/cobalt/ui/save-line";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";
import {
  SettingsGroup,
  SettingsLayout,
  SettingsPanel,
  SettingsRow,
  type SettingsSection,
} from "@/components/cobalt/ui/settings-layout";
import { Switch } from "@/components/cobalt/ui/switch";
import { Toaster } from "@/components/cobalt/ui/toaster";
import type { RenderLink } from "@/lib/cobalt/link";
import { Presence, PresenceRow } from "@/lib/cobalt/presence";
import { useAction } from "@/lib/cobalt/use-action";
import { useAutosave, useSaveState } from "@/lib/cobalt/use-autosave";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";
import { useUndoable } from "@/lib/cobalt/use-undoable";

const sections: SettingsSection[] = [
  { href: "#settings/account", label: "Account", hint: "Name, work email and language" },
  { href: "#settings/notifications", label: "Notifications", hint: "Filing alerts and the weekly digest" },
  { href: "#settings/display", label: "Display", hint: "Row density and the first day of the week" },
  { href: "#settings/devices", label: "Devices", hint: "Where you are signed in" },
];

const offline = () => !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";

// Stands in for your API call. It answers after 700ms, and fails while the browser is offline or the
// address has ?network=offline (the docs frame's Offline control sets it).
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      if (offline()) reject(new Error("offline"));
      else resolve();
    }, 700),
  );

function Section({ heading, children }: { heading: string; children: ReactNode }) {
  return (
    <section className="flex flex-col gap-6">
      <h2 className="text-xl font-semibold tracking-tight">{heading}</h2>
      {children}
    </section>
  );
}

/** A switch that saves on the flip: it moves at once, the row says how the save went, and a refusal moves it back. */
function SwitchRow({ id, label, description, initial }: { id: string; label: string; description: string; initial: boolean }) {
  const setting = useOptimisticToggle(`setting:${id}`, initial, { send: request });
  const status = useSaveState(setting.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Switch checked={setting.on} onCheckedChange={setting.flip} />
    </SettingsRow>
  );
}

/** A picker that saves on the choice; a refusal puts the last saved choice back. */
function PickerRow({
  label,
  description,
  options,
  initial,
}: {
  label: string;
  description: string;
  options: { value: string; label: string }[];
  initial: string;
}) {
  const [value, setValue] = useState(initial);
  const saved = useRef(initial);
  const save = useAction(async (next: string) => {
    try {
      await request();
      saved.current = next;
    } catch (error) {
      setValue(saved.current);
      throw error;
    }
  });
  const status = useSaveState(save.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Select
        items={options}
        value={value}
        onValueChange={(next) => {
          setValue(String(next));
          void save.run(String(next));
        }}
      >
        <SelectTrigger className="w-40">
          <SelectValue />
        </SelectTrigger>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </SettingsRow>
  );
}

function Account({ renderLink }: { renderLink: RenderLink }) {
  const [draft, setDraft] = useState({ name: "Maya Chen", email: "maya.chen@example.com" });
  const latest = useRef(draft);
  const stored = useRef(draft);
  const autosave = useAutosave(() => {
    const next = latest.current;
    if (next.name === stored.current.name && next.email === stored.current.email) return null;
    return request().then(
      () => {
        stored.current = next;
        return true;
      },
      () => false,
    );
  });
  const edit = (field: "name" | "email", value: string) => {
    latest.current = { ...latest.current, [field]: value };
    setDraft(latest.current);
    autosave.schedule();
  };
  return (
    <Section heading="Account">
      <SettingsGroup heading="Profile" action={<SaveLine state={autosave.state} onRetry={() => void autosave.retry()} />}>
        <SettingsRow label="Name" description="Shown on your notes and shared searches." layout="stacked">
          <Input value={draft.name} onChange={(e) => edit("name", e.target.value)} />
        </SettingsRow>
        <SettingsRow label="Work email" description="Where filing alerts go." layout="stacked">
          <Input type="email" value={draft.email} onChange={(e) => edit("email", e.target.value)} />
        </SettingsRow>
      </SettingsGroup>
      <SettingsGroup heading="Region">
        <SettingsRow label="Language and dates" href="#settings/display" value="English, Monday first" renderLink={renderLink} />
      </SettingsGroup>
    </Section>
  );
}

function Notifications() {
  return (
    <Section heading="Notifications">
      <SettingsGroup heading="Email">
        <SwitchRow id="filings" label="New filings" description="When a fund you follow files a 13F, an N-PORT or a Form D." initial />
        <SwitchRow id="late" label="Late filings" description="When a fund you follow misses its deadline." initial />
        <SwitchRow id="digest" label="Weekly digest" description="Every Monday at 8:00 AM, what changed last week." initial={false} />
      </SettingsGroup>
    </Section>
  );
}

function Display() {
  return (
    <Section heading="Display">
      <SettingsGroup heading="Tables">
        <PickerRow
          label="Row density"
          description="Compact fits more rows on a screen."
          initial="comfortable"
          options={[
            { value: "comfortable", label: "Comfortable" },
            { value: "compact", label: "Compact" },
          ]}
        />
      </SettingsGroup>
      <SettingsGroup heading="Dates">
        <PickerRow
          label="Weeks start on"
          description="For calendars and weekly totals."
          initial="monday"
          options={[
            { value: "monday", label: "Monday" },
            { value: "sunday", label: "Sunday" },
          ]}
        />
      </SettingsGroup>
    </Section>
  );
}

const signedIn = [
  { id: "mac", name: "MacBook Pro, Boston", seen: "Active now", current: true },
  { id: "phone", name: "iPhone 15, Boston", seen: "Last active 2 hours ago", current: false },
  { id: "pc", name: "Windows PC, New York", seen: "Last active 3 weeks ago", current: false },
];

function Devices() {
  const [hidden, setHidden] = useState<string[]>([]);
  // Lives in the list, not the row, so a row that goes away still commits when its window ends.
  const undoable = useUndoable();
  return (
    <Section heading="Devices">
      <SettingsGroup heading="Signed in">
        {/* A row that goes Leaves and one that comes back Grows, so the rows under it close up smoothly. */}
        <Presence>
          {signedIn
            .filter((device) => !hidden.includes(device.id))
            .map((device) => (
              <PresenceRow as="div" key={device.id}>
                <SettingsRow label={device.name} description={device.seen}>
                  {device.current ? (
                    <span className="text-sm text-muted-foreground">This device</span>
                  ) : (
                    <Button
                      variant="secondary"
                      size="sm"
                      onClick={() =>
                        undoable.run({
                          message: `Signed out of ${device.name}`,
                          failed: `Could not sign out of ${device.name}`,
                          apply: () => setHidden((was) => [...was, device.id]),
                          undo: () => setHidden((was) => was.filter((id) => id !== device.id)),
                          commit: request,
                        })
                      }
                    >
                      Sign out
                    </Button>
                  )}
                </SettingsRow>
              </PresenceRow>
            ))}
        </Presence>
      </SettingsGroup>
    </Section>
  );
}

export default function Example() {
  // Stands in for your router: null is the list's own address, /settings.
  const [path, setPath] = useState<string | null>("#settings/notifications");
  const current = path ?? sections[0]!.href;
  const renderLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href === "#settings" ? null : href);
      }}
    >
      {children}
    </a>
  );
  // Every section is passed, so the layout holds the tallest one's height and a switch moves nothing.
  return (
    <div className="w-full">
      <SettingsLayout heading="Settings" sections={sections} current={current} index={path === null} indexHref="#settings" renderLink={renderLink}>
        <SettingsPanel href="#settings/account">
          <Account renderLink={renderLink} />
        </SettingsPanel>
        <SettingsPanel href="#settings/notifications">
          <Notifications />
        </SettingsPanel>
        <SettingsPanel href="#settings/display">
          <Display />
        </SettingsPanel>
        <SettingsPanel href="#settings/devices">
          <Devices />
        </SettingsPanel>
      </SettingsLayout>
      <Toaster />
    </div>
  );
}
```

Example: The profile's save line at the end of its group's heading (`docs/system/examples/settings-layout/default.tsx`)

```tsx
import { useRef, useState, type ReactNode } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";
import { SaveLine } from "@/components/cobalt/ui/save-line";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";
import {
  SettingsGroup,
  SettingsLayout,
  SettingsPanel,
  SettingsRow,
  type SettingsSection,
} from "@/components/cobalt/ui/settings-layout";
import { Switch } from "@/components/cobalt/ui/switch";
import { Toaster } from "@/components/cobalt/ui/toaster";
import type { RenderLink } from "@/lib/cobalt/link";
import { Presence, PresenceRow } from "@/lib/cobalt/presence";
import { useAction } from "@/lib/cobalt/use-action";
import { useAutosave, useSaveState } from "@/lib/cobalt/use-autosave";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";
import { useUndoable } from "@/lib/cobalt/use-undoable";

const sections: SettingsSection[] = [
  { href: "#settings/account", label: "Account", hint: "Name, work email and language" },
  { href: "#settings/notifications", label: "Notifications", hint: "Filing alerts and the weekly digest" },
  { href: "#settings/display", label: "Display", hint: "Row density and the first day of the week" },
  { href: "#settings/devices", label: "Devices", hint: "Where you are signed in" },
];

const offline = () => !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";

// Stands in for your API call. It answers after 700ms, and fails while the browser is offline or the
// address has ?network=offline (the docs frame's Offline control sets it).
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      if (offline()) reject(new Error("offline"));
      else resolve();
    }, 700),
  );

function Section({ heading, children }: { heading: string; children: ReactNode }) {
  return (
    <section className="flex flex-col gap-6">
      <h2 className="text-xl font-semibold tracking-tight">{heading}</h2>
      {children}
    </section>
  );
}

/** A switch that saves on the flip: it moves at once, the row says how the save went, and a refusal moves it back. */
function SwitchRow({ id, label, description, initial }: { id: string; label: string; description: string; initial: boolean }) {
  const setting = useOptimisticToggle(`setting:${id}`, initial, { send: request });
  const status = useSaveState(setting.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Switch checked={setting.on} onCheckedChange={setting.flip} />
    </SettingsRow>
  );
}

/** A picker that saves on the choice; a refusal puts the last saved choice back. */
function PickerRow({
  label,
  description,
  options,
  initial,
}: {
  label: string;
  description: string;
  options: { value: string; label: string }[];
  initial: string;
}) {
  const [value, setValue] = useState(initial);
  const saved = useRef(initial);
  const save = useAction(async (next: string) => {
    try {
      await request();
      saved.current = next;
    } catch (error) {
      setValue(saved.current);
      throw error;
    }
  });
  const status = useSaveState(save.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Select
        items={options}
        value={value}
        onValueChange={(next) => {
          setValue(String(next));
          void save.run(String(next));
        }}
      >
        <SelectTrigger className="w-40">
          <SelectValue />
        </SelectTrigger>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </SettingsRow>
  );
}

function Account({ renderLink }: { renderLink: RenderLink }) {
  const [draft, setDraft] = useState({ name: "Maya Chen", email: "maya.chen@example.com" });
  const latest = useRef(draft);
  const stored = useRef(draft);
  const autosave = useAutosave(() => {
    const next = latest.current;
    if (next.name === stored.current.name && next.email === stored.current.email) return null;
    return request().then(
      () => {
        stored.current = next;
        return true;
      },
      () => false,
    );
  });
  const edit = (field: "name" | "email", value: string) => {
    latest.current = { ...latest.current, [field]: value };
    setDraft(latest.current);
    autosave.schedule();
  };
  return (
    <Section heading="Account">
      <SettingsGroup heading="Profile" action={<SaveLine state={autosave.state} onRetry={() => void autosave.retry()} />}>
        <SettingsRow label="Name" description="Shown on your notes and shared searches." layout="stacked">
          <Input value={draft.name} onChange={(e) => edit("name", e.target.value)} />
        </SettingsRow>
        <SettingsRow label="Work email" description="Where filing alerts go." layout="stacked">
          <Input type="email" value={draft.email} onChange={(e) => edit("email", e.target.value)} />
        </SettingsRow>
      </SettingsGroup>
      <SettingsGroup heading="Region">
        <SettingsRow label="Language and dates" href="#settings/display" value="English, Monday first" renderLink={renderLink} />
      </SettingsGroup>
    </Section>
  );
}

function Notifications() {
  return (
    <Section heading="Notifications">
      <SettingsGroup heading="Email">
        <SwitchRow id="filings" label="New filings" description="When a fund you follow files a 13F, an N-PORT or a Form D." initial />
        <SwitchRow id="late" label="Late filings" description="When a fund you follow misses its deadline." initial />
        <SwitchRow id="digest" label="Weekly digest" description="Every Monday at 8:00 AM, what changed last week." initial={false} />
      </SettingsGroup>
    </Section>
  );
}

function Display() {
  return (
    <Section heading="Display">
      <SettingsGroup heading="Tables">
        <PickerRow
          label="Row density"
          description="Compact fits more rows on a screen."
          initial="comfortable"
          options={[
            { value: "comfortable", label: "Comfortable" },
            { value: "compact", label: "Compact" },
          ]}
        />
      </SettingsGroup>
      <SettingsGroup heading="Dates">
        <PickerRow
          label="Weeks start on"
          description="For calendars and weekly totals."
          initial="monday"
          options={[
            { value: "monday", label: "Monday" },
            { value: "sunday", label: "Sunday" },
          ]}
        />
      </SettingsGroup>
    </Section>
  );
}

const signedIn = [
  { id: "mac", name: "MacBook Pro, Boston", seen: "Active now", current: true },
  { id: "phone", name: "iPhone 15, Boston", seen: "Last active 2 hours ago", current: false },
  { id: "pc", name: "Windows PC, New York", seen: "Last active 3 weeks ago", current: false },
];

function Devices() {
  const [hidden, setHidden] = useState<string[]>([]);
  // Lives in the list, not the row, so a row that goes away still commits when its window ends.
  const undoable = useUndoable();
  return (
    <Section heading="Devices">
      <SettingsGroup heading="Signed in">
        {/* A row that goes Leaves and one that comes back Grows, so the rows under it close up smoothly. */}
        <Presence>
          {signedIn
            .filter((device) => !hidden.includes(device.id))
            .map((device) => (
              <PresenceRow as="div" key={device.id}>
                <SettingsRow label={device.name} description={device.seen}>
                  {device.current ? (
                    <span className="text-sm text-muted-foreground">This device</span>
                  ) : (
                    <Button
                      variant="secondary"
                      size="sm"
                      onClick={() =>
                        undoable.run({
                          message: `Signed out of ${device.name}`,
                          failed: `Could not sign out of ${device.name}`,
                          apply: () => setHidden((was) => [...was, device.id]),
                          undo: () => setHidden((was) => was.filter((id) => id !== device.id)),
                          commit: request,
                        })
                      }
                    >
                      Sign out
                    </Button>
                  )}
                </SettingsRow>
              </PresenceRow>
            ))}
        </Presence>
      </SettingsGroup>
    </Section>
  );
}

export default function Example() {
  // Stands in for your router: null is the list's own address, /settings.
  const [path, setPath] = useState<string | null>("#settings/notifications");
  const current = path ?? sections[0]!.href;
  const renderLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href === "#settings" ? null : href);
      }}
    >
      {children}
    </a>
  );
  // Every section is passed, so the layout holds the tallest one's height and a switch moves nothing.
  return (
    <div className="w-full">
      <SettingsLayout heading="Settings" sections={sections} current={current} index={path === null} indexHref="#settings" renderLink={renderLink}>
        <SettingsPanel href="#settings/account">
          <Account renderLink={renderLink} />
        </SettingsPanel>
        <SettingsPanel href="#settings/notifications">
          <Notifications />
        </SettingsPanel>
        <SettingsPanel href="#settings/display">
          <Display />
        </SettingsPanel>
        <SettingsPanel href="#settings/devices">
          <Devices />
        </SettingsPanel>
      </SettingsLayout>
      <Toaster />
    </div>
  );
}
```

## Variants
Not applicable: one layout that changes at 1024px.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| section | a section's address | change its settings; open another section; go back on a phone | the list and the section from 1024px; the section and a back link below | test |
| index | the list's own address, `index` | open a section | the list, with hints and chevrons, below 1024px; the first section beside the list from 1024px | test |
| current | the row of the open section | read where they are | from 1024px the pill that slides to it and the foreground ink, and `aria-current` | test |
| hover | pointer over a row, under `(hover: hover)` | open it | from 1024px the ink alone, since the pill is the only fill (D43); on a phone's list the grey fill | by hand |
| pressed | pointer or key down on a row | let go to open it | from 1024px the ink, then the pill slides to it; on a phone the fill darkens one step; nothing moves | by hand |
| focus-visible | Tab onto a row | open it with Enter | the 2px outline on its 12px corner | by hand |
| section switch | another section opened from 1024px up | read it | the section in place; the layout keeps the tallest section's height, so nothing below moves and the scroll stays | test |
| saving | a SettingsRow's `status` is not idle | wait, or press Retry | the description's line turns to Saving, Saved or Not saved, in a line that keeps its height | test |
| link-row | a SettingsRow with `href` | open its page | the value before the chevron; the grey fill under the pointer | test |
| undo | a change run through `useUndoable` | press Undo while the toast shows | the change at once, the toast with Undo; the server only when the window ends | test |

Example: A row's line says Saving once a save is slow, then Saved, or Not saved with the switch moved back (`docs/system/examples/settings-layout/default.tsx`)

```tsx
import { useRef, useState, type ReactNode } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";
import { SaveLine } from "@/components/cobalt/ui/save-line";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";
import {
  SettingsGroup,
  SettingsLayout,
  SettingsPanel,
  SettingsRow,
  type SettingsSection,
} from "@/components/cobalt/ui/settings-layout";
import { Switch } from "@/components/cobalt/ui/switch";
import { Toaster } from "@/components/cobalt/ui/toaster";
import type { RenderLink } from "@/lib/cobalt/link";
import { Presence, PresenceRow } from "@/lib/cobalt/presence";
import { useAction } from "@/lib/cobalt/use-action";
import { useAutosave, useSaveState } from "@/lib/cobalt/use-autosave";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";
import { useUndoable } from "@/lib/cobalt/use-undoable";

const sections: SettingsSection[] = [
  { href: "#settings/account", label: "Account", hint: "Name, work email and language" },
  { href: "#settings/notifications", label: "Notifications", hint: "Filing alerts and the weekly digest" },
  { href: "#settings/display", label: "Display", hint: "Row density and the first day of the week" },
  { href: "#settings/devices", label: "Devices", hint: "Where you are signed in" },
];

const offline = () => !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";

// Stands in for your API call. It answers after 700ms, and fails while the browser is offline or the
// address has ?network=offline (the docs frame's Offline control sets it).
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      if (offline()) reject(new Error("offline"));
      else resolve();
    }, 700),
  );

function Section({ heading, children }: { heading: string; children: ReactNode }) {
  return (
    <section className="flex flex-col gap-6">
      <h2 className="text-xl font-semibold tracking-tight">{heading}</h2>
      {children}
    </section>
  );
}

/** A switch that saves on the flip: it moves at once, the row says how the save went, and a refusal moves it back. */
function SwitchRow({ id, label, description, initial }: { id: string; label: string; description: string; initial: boolean }) {
  const setting = useOptimisticToggle(`setting:${id}`, initial, { send: request });
  const status = useSaveState(setting.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Switch checked={setting.on} onCheckedChange={setting.flip} />
    </SettingsRow>
  );
}

/** A picker that saves on the choice; a refusal puts the last saved choice back. */
function PickerRow({
  label,
  description,
  options,
  initial,
}: {
  label: string;
  description: string;
  options: { value: string; label: string }[];
  initial: string;
}) {
  const [value, setValue] = useState(initial);
  const saved = useRef(initial);
  const save = useAction(async (next: string) => {
    try {
      await request();
      saved.current = next;
    } catch (error) {
      setValue(saved.current);
      throw error;
    }
  });
  const status = useSaveState(save.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Select
        items={options}
        value={value}
        onValueChange={(next) => {
          setValue(String(next));
          void save.run(String(next));
        }}
      >
        <SelectTrigger className="w-40">
          <SelectValue />
        </SelectTrigger>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </SettingsRow>
  );
}

function Account({ renderLink }: { renderLink: RenderLink }) {
  const [draft, setDraft] = useState({ name: "Maya Chen", email: "maya.chen@example.com" });
  const latest = useRef(draft);
  const stored = useRef(draft);
  const autosave = useAutosave(() => {
    const next = latest.current;
    if (next.name === stored.current.name && next.email === stored.current.email) return null;
    return request().then(
      () => {
        stored.current = next;
        return true;
      },
      () => false,
    );
  });
  const edit = (field: "name" | "email", value: string) => {
    latest.current = { ...latest.current, [field]: value };
    setDraft(latest.current);
    autosave.schedule();
  };
  return (
    <Section heading="Account">
      <SettingsGroup heading="Profile" action={<SaveLine state={autosave.state} onRetry={() => void autosave.retry()} />}>
        <SettingsRow label="Name" description="Shown on your notes and shared searches." layout="stacked">
          <Input value={draft.name} onChange={(e) => edit("name", e.target.value)} />
        </SettingsRow>
        <SettingsRow label="Work email" description="Where filing alerts go." layout="stacked">
          <Input type="email" value={draft.email} onChange={(e) => edit("email", e.target.value)} />
        </SettingsRow>
      </SettingsGroup>
      <SettingsGroup heading="Region">
        <SettingsRow label="Language and dates" href="#settings/display" value="English, Monday first" renderLink={renderLink} />
      </SettingsGroup>
    </Section>
  );
}

function Notifications() {
  return (
    <Section heading="Notifications">
      <SettingsGroup heading="Email">
        <SwitchRow id="filings" label="New filings" description="When a fund you follow files a 13F, an N-PORT or a Form D." initial />
        <SwitchRow id="late" label="Late filings" description="When a fund you follow misses its deadline." initial />
        <SwitchRow id="digest" label="Weekly digest" description="Every Monday at 8:00 AM, what changed last week." initial={false} />
      </SettingsGroup>
    </Section>
  );
}

function Display() {
  return (
    <Section heading="Display">
      <SettingsGroup heading="Tables">
        <PickerRow
          label="Row density"
          description="Compact fits more rows on a screen."
          initial="comfortable"
          options={[
            { value: "comfortable", label: "Comfortable" },
            { value: "compact", label: "Compact" },
          ]}
        />
      </SettingsGroup>
      <SettingsGroup heading="Dates">
        <PickerRow
          label="Weeks start on"
          description="For calendars and weekly totals."
          initial="monday"
          options={[
            { value: "monday", label: "Monday" },
            { value: "sunday", label: "Sunday" },
          ]}
        />
      </SettingsGroup>
    </Section>
  );
}

const signedIn = [
  { id: "mac", name: "MacBook Pro, Boston", seen: "Active now", current: true },
  { id: "phone", name: "iPhone 15, Boston", seen: "Last active 2 hours ago", current: false },
  { id: "pc", name: "Windows PC, New York", seen: "Last active 3 weeks ago", current: false },
];

function Devices() {
  const [hidden, setHidden] = useState<string[]>([]);
  // Lives in the list, not the row, so a row that goes away still commits when its window ends.
  const undoable = useUndoable();
  return (
    <Section heading="Devices">
      <SettingsGroup heading="Signed in">
        {/* A row that goes Leaves and one that comes back Grows, so the rows under it close up smoothly. */}
        <Presence>
          {signedIn
            .filter((device) => !hidden.includes(device.id))
            .map((device) => (
              <PresenceRow as="div" key={device.id}>
                <SettingsRow label={device.name} description={device.seen}>
                  {device.current ? (
                    <span className="text-sm text-muted-foreground">This device</span>
                  ) : (
                    <Button
                      variant="secondary"
                      size="sm"
                      onClick={() =>
                        undoable.run({
                          message: `Signed out of ${device.name}`,
                          failed: `Could not sign out of ${device.name}`,
                          apply: () => setHidden((was) => [...was, device.id]),
                          undo: () => setHidden((was) => was.filter((id) => id !== device.id)),
                          commit: request,
                        })
                      }
                    >
                      Sign out
                    </Button>
                  )}
                </SettingsRow>
              </PresenceRow>
            ))}
        </Presence>
      </SettingsGroup>
    </Section>
  );
}

export default function Example() {
  // Stands in for your router: null is the list's own address, /settings.
  const [path, setPath] = useState<string | null>("#settings/notifications");
  const current = path ?? sections[0]!.href;
  const renderLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href === "#settings" ? null : href);
      }}
    >
      {children}
    </a>
  );
  // Every section is passed, so the layout holds the tallest one's height and a switch moves nothing.
  return (
    <div className="w-full">
      <SettingsLayout heading="Settings" sections={sections} current={current} index={path === null} indexHref="#settings" renderLink={renderLink}>
        <SettingsPanel href="#settings/account">
          <Account renderLink={renderLink} />
        </SettingsPanel>
        <SettingsPanel href="#settings/notifications">
          <Notifications />
        </SettingsPanel>
        <SettingsPanel href="#settings/display">
          <Display />
        </SettingsPanel>
        <SettingsPanel href="#settings/devices">
          <Devices />
        </SettingsPanel>
      </SettingsLayout>
      <Toaster />
    </div>
  );
}
```

Example: Language and dates, a row that opens Display with its value before the chevron (`docs/system/examples/settings-layout/default.tsx`)

```tsx
import { useRef, useState, type ReactNode } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";
import { SaveLine } from "@/components/cobalt/ui/save-line";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";
import {
  SettingsGroup,
  SettingsLayout,
  SettingsPanel,
  SettingsRow,
  type SettingsSection,
} from "@/components/cobalt/ui/settings-layout";
import { Switch } from "@/components/cobalt/ui/switch";
import { Toaster } from "@/components/cobalt/ui/toaster";
import type { RenderLink } from "@/lib/cobalt/link";
import { Presence, PresenceRow } from "@/lib/cobalt/presence";
import { useAction } from "@/lib/cobalt/use-action";
import { useAutosave, useSaveState } from "@/lib/cobalt/use-autosave";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";
import { useUndoable } from "@/lib/cobalt/use-undoable";

const sections: SettingsSection[] = [
  { href: "#settings/account", label: "Account", hint: "Name, work email and language" },
  { href: "#settings/notifications", label: "Notifications", hint: "Filing alerts and the weekly digest" },
  { href: "#settings/display", label: "Display", hint: "Row density and the first day of the week" },
  { href: "#settings/devices", label: "Devices", hint: "Where you are signed in" },
];

const offline = () => !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";

// Stands in for your API call. It answers after 700ms, and fails while the browser is offline or the
// address has ?network=offline (the docs frame's Offline control sets it).
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      if (offline()) reject(new Error("offline"));
      else resolve();
    }, 700),
  );

function Section({ heading, children }: { heading: string; children: ReactNode }) {
  return (
    <section className="flex flex-col gap-6">
      <h2 className="text-xl font-semibold tracking-tight">{heading}</h2>
      {children}
    </section>
  );
}

/** A switch that saves on the flip: it moves at once, the row says how the save went, and a refusal moves it back. */
function SwitchRow({ id, label, description, initial }: { id: string; label: string; description: string; initial: boolean }) {
  const setting = useOptimisticToggle(`setting:${id}`, initial, { send: request });
  const status = useSaveState(setting.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Switch checked={setting.on} onCheckedChange={setting.flip} />
    </SettingsRow>
  );
}

/** A picker that saves on the choice; a refusal puts the last saved choice back. */
function PickerRow({
  label,
  description,
  options,
  initial,
}: {
  label: string;
  description: string;
  options: { value: string; label: string }[];
  initial: string;
}) {
  const [value, setValue] = useState(initial);
  const saved = useRef(initial);
  const save = useAction(async (next: string) => {
    try {
      await request();
      saved.current = next;
    } catch (error) {
      setValue(saved.current);
      throw error;
    }
  });
  const status = useSaveState(save.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Select
        items={options}
        value={value}
        onValueChange={(next) => {
          setValue(String(next));
          void save.run(String(next));
        }}
      >
        <SelectTrigger className="w-40">
          <SelectValue />
        </SelectTrigger>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </SettingsRow>
  );
}

function Account({ renderLink }: { renderLink: RenderLink }) {
  const [draft, setDraft] = useState({ name: "Maya Chen", email: "maya.chen@example.com" });
  const latest = useRef(draft);
  const stored = useRef(draft);
  const autosave = useAutosave(() => {
    const next = latest.current;
    if (next.name === stored.current.name && next.email === stored.current.email) return null;
    return request().then(
      () => {
        stored.current = next;
        return true;
      },
      () => false,
    );
  });
  const edit = (field: "name" | "email", value: string) => {
    latest.current = { ...latest.current, [field]: value };
    setDraft(latest.current);
    autosave.schedule();
  };
  return (
    <Section heading="Account">
      <SettingsGroup heading="Profile" action={<SaveLine state={autosave.state} onRetry={() => void autosave.retry()} />}>
        <SettingsRow label="Name" description="Shown on your notes and shared searches." layout="stacked">
          <Input value={draft.name} onChange={(e) => edit("name", e.target.value)} />
        </SettingsRow>
        <SettingsRow label="Work email" description="Where filing alerts go." layout="stacked">
          <Input type="email" value={draft.email} onChange={(e) => edit("email", e.target.value)} />
        </SettingsRow>
      </SettingsGroup>
      <SettingsGroup heading="Region">
        <SettingsRow label="Language and dates" href="#settings/display" value="English, Monday first" renderLink={renderLink} />
      </SettingsGroup>
    </Section>
  );
}

function Notifications() {
  return (
    <Section heading="Notifications">
      <SettingsGroup heading="Email">
        <SwitchRow id="filings" label="New filings" description="When a fund you follow files a 13F, an N-PORT or a Form D." initial />
        <SwitchRow id="late" label="Late filings" description="When a fund you follow misses its deadline." initial />
        <SwitchRow id="digest" label="Weekly digest" description="Every Monday at 8:00 AM, what changed last week." initial={false} />
      </SettingsGroup>
    </Section>
  );
}

function Display() {
  return (
    <Section heading="Display">
      <SettingsGroup heading="Tables">
        <PickerRow
          label="Row density"
          description="Compact fits more rows on a screen."
          initial="comfortable"
          options={[
            { value: "comfortable", label: "Comfortable" },
            { value: "compact", label: "Compact" },
          ]}
        />
      </SettingsGroup>
      <SettingsGroup heading="Dates">
        <PickerRow
          label="Weeks start on"
          description="For calendars and weekly totals."
          initial="monday"
          options={[
            { value: "monday", label: "Monday" },
            { value: "sunday", label: "Sunday" },
          ]}
        />
      </SettingsGroup>
    </Section>
  );
}

const signedIn = [
  { id: "mac", name: "MacBook Pro, Boston", seen: "Active now", current: true },
  { id: "phone", name: "iPhone 15, Boston", seen: "Last active 2 hours ago", current: false },
  { id: "pc", name: "Windows PC, New York", seen: "Last active 3 weeks ago", current: false },
];

function Devices() {
  const [hidden, setHidden] = useState<string[]>([]);
  // Lives in the list, not the row, so a row that goes away still commits when its window ends.
  const undoable = useUndoable();
  return (
    <Section heading="Devices">
      <SettingsGroup heading="Signed in">
        {/* A row that goes Leaves and one that comes back Grows, so the rows under it close up smoothly. */}
        <Presence>
          {signedIn
            .filter((device) => !hidden.includes(device.id))
            .map((device) => (
              <PresenceRow as="div" key={device.id}>
                <SettingsRow label={device.name} description={device.seen}>
                  {device.current ? (
                    <span className="text-sm text-muted-foreground">This device</span>
                  ) : (
                    <Button
                      variant="secondary"
                      size="sm"
                      onClick={() =>
                        undoable.run({
                          message: `Signed out of ${device.name}`,
                          failed: `Could not sign out of ${device.name}`,
                          apply: () => setHidden((was) => [...was, device.id]),
                          undo: () => setHidden((was) => was.filter((id) => id !== device.id)),
                          commit: request,
                        })
                      }
                    >
                      Sign out
                    </Button>
                  )}
                </SettingsRow>
              </PresenceRow>
            ))}
        </Presence>
      </SettingsGroup>
    </Section>
  );
}

export default function Example() {
  // Stands in for your router: null is the list's own address, /settings.
  const [path, setPath] = useState<string | null>("#settings/notifications");
  const current = path ?? sections[0]!.href;
  const renderLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href === "#settings" ? null : href);
      }}
    >
      {children}
    </a>
  );
  // Every section is passed, so the layout holds the tallest one's height and a switch moves nothing.
  return (
    <div className="w-full">
      <SettingsLayout heading="Settings" sections={sections} current={current} index={path === null} indexHref="#settings" renderLink={renderLink}>
        <SettingsPanel href="#settings/account">
          <Account renderLink={renderLink} />
        </SettingsPanel>
        <SettingsPanel href="#settings/notifications">
          <Notifications />
        </SettingsPanel>
        <SettingsPanel href="#settings/display">
          <Display />
        </SettingsPanel>
        <SettingsPanel href="#settings/devices">
          <Devices />
        </SettingsPanel>
      </SettingsLayout>
      <Toaster />
    </div>
  );
}
```

Example: Sign out of a device at once, with Undo; the server hears of it when the window ends (`docs/system/examples/settings-layout/default.tsx`)

```tsx
import { useRef, useState, type ReactNode } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";
import { SaveLine } from "@/components/cobalt/ui/save-line";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";
import {
  SettingsGroup,
  SettingsLayout,
  SettingsPanel,
  SettingsRow,
  type SettingsSection,
} from "@/components/cobalt/ui/settings-layout";
import { Switch } from "@/components/cobalt/ui/switch";
import { Toaster } from "@/components/cobalt/ui/toaster";
import type { RenderLink } from "@/lib/cobalt/link";
import { Presence, PresenceRow } from "@/lib/cobalt/presence";
import { useAction } from "@/lib/cobalt/use-action";
import { useAutosave, useSaveState } from "@/lib/cobalt/use-autosave";
import { useOptimisticToggle } from "@/lib/cobalt/use-optimistic-toggle";
import { useUndoable } from "@/lib/cobalt/use-undoable";

const sections: SettingsSection[] = [
  { href: "#settings/account", label: "Account", hint: "Name, work email and language" },
  { href: "#settings/notifications", label: "Notifications", hint: "Filing alerts and the weekly digest" },
  { href: "#settings/display", label: "Display", hint: "Row density and the first day of the week" },
  { href: "#settings/devices", label: "Devices", hint: "Where you are signed in" },
];

const offline = () => !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";

// Stands in for your API call. It answers after 700ms, and fails while the browser is offline or the
// address has ?network=offline (the docs frame's Offline control sets it).
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      if (offline()) reject(new Error("offline"));
      else resolve();
    }, 700),
  );

function Section({ heading, children }: { heading: string; children: ReactNode }) {
  return (
    <section className="flex flex-col gap-6">
      <h2 className="text-xl font-semibold tracking-tight">{heading}</h2>
      {children}
    </section>
  );
}

/** A switch that saves on the flip: it moves at once, the row says how the save went, and a refusal moves it back. */
function SwitchRow({ id, label, description, initial }: { id: string; label: string; description: string; initial: boolean }) {
  const setting = useOptimisticToggle(`setting:${id}`, initial, { send: request });
  const status = useSaveState(setting.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Switch checked={setting.on} onCheckedChange={setting.flip} />
    </SettingsRow>
  );
}

/** A picker that saves on the choice; a refusal puts the last saved choice back. */
function PickerRow({
  label,
  description,
  options,
  initial,
}: {
  label: string;
  description: string;
  options: { value: string; label: string }[];
  initial: string;
}) {
  const [value, setValue] = useState(initial);
  const saved = useRef(initial);
  const save = useAction(async (next: string) => {
    try {
      await request();
      saved.current = next;
    } catch (error) {
      setValue(saved.current);
      throw error;
    }
  });
  const status = useSaveState(save.status);
  return (
    <SettingsRow label={label} description={description} status={status}>
      <Select
        items={options}
        value={value}
        onValueChange={(next) => {
          setValue(String(next));
          void save.run(String(next));
        }}
      >
        <SelectTrigger className="w-40">
          <SelectValue />
        </SelectTrigger>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </SettingsRow>
  );
}

function Account({ renderLink }: { renderLink: RenderLink }) {
  const [draft, setDraft] = useState({ name: "Maya Chen", email: "maya.chen@example.com" });
  const latest = useRef(draft);
  const stored = useRef(draft);
  const autosave = useAutosave(() => {
    const next = latest.current;
    if (next.name === stored.current.name && next.email === stored.current.email) return null;
    return request().then(
      () => {
        stored.current = next;
        return true;
      },
      () => false,
    );
  });
  const edit = (field: "name" | "email", value: string) => {
    latest.current = { ...latest.current, [field]: value };
    setDraft(latest.current);
    autosave.schedule();
  };
  return (
    <Section heading="Account">
      <SettingsGroup heading="Profile" action={<SaveLine state={autosave.state} onRetry={() => void autosave.retry()} />}>
        <SettingsRow label="Name" description="Shown on your notes and shared searches." layout="stacked">
          <Input value={draft.name} onChange={(e) => edit("name", e.target.value)} />
        </SettingsRow>
        <SettingsRow label="Work email" description="Where filing alerts go." layout="stacked">
          <Input type="email" value={draft.email} onChange={(e) => edit("email", e.target.value)} />
        </SettingsRow>
      </SettingsGroup>
      <SettingsGroup heading="Region">
        <SettingsRow label="Language and dates" href="#settings/display" value="English, Monday first" renderLink={renderLink} />
      </SettingsGroup>
    </Section>
  );
}

function Notifications() {
  return (
    <Section heading="Notifications">
      <SettingsGroup heading="Email">
        <SwitchRow id="filings" label="New filings" description="When a fund you follow files a 13F, an N-PORT or a Form D." initial />
        <SwitchRow id="late" label="Late filings" description="When a fund you follow misses its deadline." initial />
        <SwitchRow id="digest" label="Weekly digest" description="Every Monday at 8:00 AM, what changed last week." initial={false} />
      </SettingsGroup>
    </Section>
  );
}

function Display() {
  return (
    <Section heading="Display">
      <SettingsGroup heading="Tables">
        <PickerRow
          label="Row density"
          description="Compact fits more rows on a screen."
          initial="comfortable"
          options={[
            { value: "comfortable", label: "Comfortable" },
            { value: "compact", label: "Compact" },
          ]}
        />
      </SettingsGroup>
      <SettingsGroup heading="Dates">
        <PickerRow
          label="Weeks start on"
          description="For calendars and weekly totals."
          initial="monday"
          options={[
            { value: "monday", label: "Monday" },
            { value: "sunday", label: "Sunday" },
          ]}
        />
      </SettingsGroup>
    </Section>
  );
}

const signedIn = [
  { id: "mac", name: "MacBook Pro, Boston", seen: "Active now", current: true },
  { id: "phone", name: "iPhone 15, Boston", seen: "Last active 2 hours ago", current: false },
  { id: "pc", name: "Windows PC, New York", seen: "Last active 3 weeks ago", current: false },
];

function Devices() {
  const [hidden, setHidden] = useState<string[]>([]);
  // Lives in the list, not the row, so a row that goes away still commits when its window ends.
  const undoable = useUndoable();
  return (
    <Section heading="Devices">
      <SettingsGroup heading="Signed in">
        {/* A row that goes Leaves and one that comes back Grows, so the rows under it close up smoothly. */}
        <Presence>
          {signedIn
            .filter((device) => !hidden.includes(device.id))
            .map((device) => (
              <PresenceRow as="div" key={device.id}>
                <SettingsRow label={device.name} description={device.seen}>
                  {device.current ? (
                    <span className="text-sm text-muted-foreground">This device</span>
                  ) : (
                    <Button
                      variant="secondary"
                      size="sm"
                      onClick={() =>
                        undoable.run({
                          message: `Signed out of ${device.name}`,
                          failed: `Could not sign out of ${device.name}`,
                          apply: () => setHidden((was) => [...was, device.id]),
                          undo: () => setHidden((was) => was.filter((id) => id !== device.id)),
                          commit: request,
                        })
                      }
                    >
                      Sign out
                    </Button>
                  )}
                </SettingsRow>
              </PresenceRow>
            ))}
        </Presence>
      </SettingsGroup>
    </Section>
  );
}

export default function Example() {
  // Stands in for your router: null is the list's own address, /settings.
  const [path, setPath] = useState<string | null>("#settings/notifications");
  const current = path ?? sections[0]!.href;
  const renderLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href === "#settings" ? null : href);
      }}
    >
      {children}
    </a>
  );
  // Every section is passed, so the layout holds the tallest one's height and a switch moves nothing.
  return (
    <div className="w-full">
      <SettingsLayout heading="Settings" sections={sections} current={current} index={path === null} indexHref="#settings" renderLink={renderLink}>
        <SettingsPanel href="#settings/account">
          <Account renderLink={renderLink} />
        </SettingsPanel>
        <SettingsPanel href="#settings/notifications">
          <Notifications />
        </SettingsPanel>
        <SettingsPanel href="#settings/display">
          <Display />
        </SettingsPanel>
        <SettingsPanel href="#settings/devices">
          <Devices />
        </SettingsPanel>
      </SettingsLayout>
      <Toaster />
    </div>
  );
}
```

### State precedence
- Current and hover: current wins. The pill stays under the pointer, so the open section stays readable (D9).
- Section and index: Not applicable: an address is one or the other.
- Focus-visible and current or hover: both show. The outline is drawn outside the fill.
- Saving and a row's description: saving wins. The words take the description's line while a save reports, and the description comes back after.
- Undo and a section switch: the switch wins and commits the change. Leaving the section ends its window, as leaving the page does.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| another section opens, from 1024px up | announce | `duration-settle ease-settle` (`--t-settle`, 300ms, on `--curve-settle`), through `useIndicator`, as the sidebar's and the nav's pills; the row's ink on the same spring, so it lands as the pill does; not on first paint, a resize or a font swap | transform (translateY) and height of the pill, color of the label | the pill jumps; the colour change stays |
| pointer over and out, and press, on a row from 1024px up | input | the ink on `--t-settle` | color | the same colour change |
| pointer over and out, and press, on a row of the phone's list | input | `pressable`, `--t-press` on `--curve` | background-color, box-shadow | the same colour change; there is no movement to drop |
| a row's save line changes wording | announce | SaveLine's handover, `--t-pop` and `--t-icon` | opacity | the same fades |

## Props

<!-- Props generated from registry/cobalt/ui/settings-layout.tsx with TypeScript by scripts/props-table.mjs -->
### SettingsLayout

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  | One `SettingsPanel` for each section, each with its own h2. |
| `current` | `string` |  | The `href` of the open section. |
| `heading` | `string` |  | The page's title, an h1 over the list. |
| `indexHref` | `string` |  | The list's own address, where the back link goes. |
| `sections` | `readonly SettingsSection[]` |  |  |
| `backLabel?` | `string` | `"Back to settings"` |  |
| `className?` | `string` |  |  |
| `index?` | `boolean` | `false` | True on the list's own address. |
| `renderLink?` | `RenderLink` | `defaultLink` |  |
| `sticky?` | `boolean` |  | Holds the list in view from 1024px up as the section scrolls. |

### SettingsPanel

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  | The section, with its own h2. |
| `href` | `string` |  | The section's `href`, as in the layout's `sections`. |
| `className?` | `string` |  |  |
| `keepMounted?` | `boolean` | `true` |  |

### SettingsGroup

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  | The rows: `SettingsRow`s. |
| `heading` | `string` |  | What the rows have in common: "Email", "Two-step sign-in". |
| `action?` | `ReactNode` |  | A SaveLine or one text action at the end of the heading's line. |
| `className?` | `string` |  |  |
| `description?` | `ReactNode` |  | One line under the card, for what holds for every row in it. |
| `headingLevel?` | `2 \| 3` | `3` | 3 under a section's own h2; 2 on a page whose groups are its top headings. |

### SettingsRow

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `label` | `string` |  |  |
| `children?` | `ReactNode` |  | The control: a Switch, a Select, a Button. |
| `className?` | `string` |  |  |
| `description?` | `ReactNode` |  | What the setting does, in one sentence. |
| `href?` | `string` |  | Makes the row a link to the setting's own page. |
| `layout?` | `"stacked" \| "inline"` | `"inline"` | `stacked` for a text field: the control under the words, full width. |
| `onCheck?` | `() => void` |  |  |
| `onRetry?` | `() => void` |  |  |
| `onShowLatest?` | `() => void` |  |  |
| `renderLink?` | `RenderLink` | `defaultLink` |  |
| `status?` | `SaveState` |  | How the last save of this setting went. |
| `value?` | `ReactNode` |  | The current value, shown before the chevron on a link row: "English", "3 devices". |

`heading` is the page's h1. `sections` lists each section's `href`, `label` and `hint`. `current` is the `href` of the open section. `children` are the `SettingsPanel`s, one per section, each with an `href` from `sections`, the section as its children, and `keepMounted` (true; false renders a heavy section only while it is open). `index` is true on the list's own address. `indexHref` is that address, where the back link goes, with `backLabel` its words, "Back to settings" by default. `renderLink` swaps the anchors for a router's links. `sticky` holds the list in view from 1024px up: left out, only inside `AppShellMain`; true for a page that scrolls the window; false never. `className` is for placement.

`SettingsGroup` takes `heading`, `headingLevel` (3 under a section's h2), an `action` at the heading's end, a `description` under the card and the rows as `children`. `SettingsRow` takes `label`, `description`, the control as `children`, `layout` (`stacked` puts a text field under the words at full width), a `status` with `onRetry`, `onCheck` and `onShowLatest` for its save line, or `href` and `value` for a row that opens a page, through `renderLink`. `useUndoable({ window })` returns `run`, which takes the toast's `message`, `apply`, `undo`, `commit` and `failed` words.

## Usage

### When to use
- An app's account, notification, privacy and display settings, more than 2 sections of them.
- An admin area of sections that each hold a form or a list of switches.

### When not to use
- A page with 1 or 2 groups of settings. Use Card instead, one per group, on one page.
- Views of one record. Use Tabs instead.
- The app's main sections. Use Nav instead.

### Rules
- `rule/settings-layout-real-addresses`: When building the sections, give each one its own address in `href` and route to it, instead of a state that swaps the section on one address, because Back, a bookmark and a link sent to a colleague then open the right section, and on a phone Back returns to the list. Evidence: principle platform: the address is the state a person can share and go back to. Check: review.
  - Don't: `<SettingsLayout sections={sections.map((s) => ({ ...s, href: "#" }))} ...>`
  - Do: `<SettingsLayout sections={[{ href: "/settings/notifications", label: "Notifications", hint: "Filing alerts" }]} ...>`
- `rule/settings-layout-every-section`: When building the page, pass every section as a `SettingsPanel`, instead of only the open section as the children, because the layout then holds the tallest section's height from the first frame, so a switch moves nothing below the sections and never pulls the page's scroll back. Evidence: person D37; measured at 1440 every section 804px tall with the old window-height floor, the Display section about 400px of it empty, and 403.5px for every section with the panels, `.design-system/evidence/settings-layout/panels-and-pill.json`. Check: test `settings-layout.test.tsx` "every section stays mounted in one cell".
  - Don't: `<SettingsLayout current={path} ...>{view[path]}</SettingsLayout>`
  - Do: `<SettingsLayout current={path} ...><SettingsPanel href="/settings/account"><Account /></SettingsPanel><SettingsPanel href="/settings/display"><Display /></SettingsPanel></SettingsLayout>`
- `rule/settings-layout-switch-acts-at-once`: When a section holds switches, save each on the flip through `useOptimisticToggle` and pass `useSaveState(setting.status)` as the row's `status`, instead of a Save button for the switches, because a switch that waits for a button reads as on while it is not. Evidence: person D39, whose feedback table moves a setting at once and back with a message on a failure (docs/system/feedback.md); single use docs/system/examples/settings-layout/default.tsx:54-57. Check: review.
  - Don't: `<Switch checked={draft.digest} onCheckedChange={...} />` with a Save button under the card
  - Do: `<SettingsRow label="Weekly digest" status={useSaveState(setting.status)}><Switch checked={setting.on} onCheckedChange={setting.flip} /></SettingsRow>`
- `rule/settings-layout-rows-from-the-kit`: When a section lists settings, build them from `SettingsGroup` and `SettingsRow`, instead of a Card of hand-laid rows, because the kit holds the row's geometry, ties the name and the description to the control and keeps the save line's height in one place. Evidence: app 1/2 source apps, Tag's settings kit decides a row's geometry in one place, docs/research/2026-10-17-missing-parts.md F2; measured 4 examples re-building these rows by hand before the kit, the same report. Check: review.
  - Don't: `<Card><CardContent><ul><li className="flex py-4"><label>Weekly digest</label><Switch /></li></ul></CardContent></Card>`
  - Do: `<SettingsGroup heading="Email"><SettingsRow label="Weekly digest" description="Every Monday at 8:00 AM."><Switch /></SettingsRow></SettingsGroup>`
- `rule/settings-layout-undo-commits-late`: When a setting removes something the person can bring back, such as a device's sign-in or a saved search, run it through `useUndoable` and keep the hook in the list, instead of calling the server at once and reversing on Undo, because a commit that waits for the window to end has nothing to reverse, and an Undo the person can see always works. Evidence: app 2/2 source apps commit late, Tag's pending delete and the TSA app's logo field, docs/research/2026-10-17-missing-parts.md F4; single use docs/system/examples/settings-layout/default.tsx:216-223. Check: test `use-undoable.test.ts` "Undo puts it back and the server never hears of it".
  - Don't: `await api.signOut(device); toast("Signed out", { action: { label: "Undo", onClick: () => api.signIn(device) } })`
  - Do: `undoable.run({ message: "Signed out of iPhone 15", failed: "Could not sign out", apply: hide, undo: show, commit: () => api.signOut(device) })`
- `rule/settings-layout-index-shows-first`: When rendering the list's own address, pass `index` with the first section's `href` as `current`, instead of an empty pane, because a wide screen then opens on a section and a phone still shows the list. Evidence: single use docs/system/examples/settings-layout/default.tsx:257; principle heuristic: aesthetic and minimalist design, an empty pane beside a list says nothing. Check: test `settings-layout.test.tsx` renders the index with no back link.
  - Don't: `<SettingsLayout index current="" ...>{null}</SettingsLayout>`
  - Do: `<SettingsLayout index current={sections[0].href} ...><SettingsPanel href={sections[0].href}><Account /></SettingsPanel>...</SettingsLayout>`

### Content
- `rule/settings-layout-hint-lists-contents`: When writing a section's `hint`, list what it holds, such as "Name, work email and firm", in at most 6 words, instead of describing the section, because the hint shows only in the phone's list, where a person picks a section by what is in it. Evidence: principle heuristic: recognition rather than recall, a person picks a section by what is in it. Check: review.
  - Don't: `{ label: "Account", hint: "Manage your account settings here" }`
  - Do: `{ label: "Account", hint: "Name, work email and firm" }`

### Anti-slop
- `rule/settings-layout-no-dividers`: When rows share a `SettingsGroup`, let the kit split them by its 10px row padding, instead of a line between rows, because D11 keeps lines to dense tables, and the group's one card already says the rows belong together. Evidence: person D11. Check: review.
  - Don't: `<SettingsRow className="border-b border-border" label="Weekly digest" />`
  - Do: `<SettingsRow label="Weekly digest" description="Every Monday at 8:00 AM." />`
- `rule/settings-layout-no-icons-per-row`: When listing sections, pass each name as `label` with no glyph, instead of an icon before each name, because 4 to 8 one-word names are scanned faster than 4 to 8 pictures, and the system's other lists of words carry none. Evidence: principle heuristic: aesthetic and minimalist design; person D14. Check: review.
  - Don't: `{ label: "Notifications", icon: BellIcon }`
  - Do: `{ label: "Notifications", hint: "Filing alerts and reminders" }`

### Limits
- `rule/settings-layout-section-count`: When there are more than 12 sections, group them into fewer, such as Account with Security, instead of a longer list, because the list is held in view beside the section, and at 1440x900 the 14 sections of the worst case already take 532px of the 804px under the top bar; a longer list scrolls away from the section it stands beside. Evidence: measured 14 rows of 36px with a 2px gap, all in view, from 112px down at 1440x900, docs/system/stress/settings-layout.tsx. Check: probe docs/system/stress/settings-layout.tsx on the break-ui harness.
  - Don't: 20 sections, one per setting
  - Do: 5 sections: Account, Notifications, Display, Privacy, Billing

## Accessibility
Rests on a `nav` named by the page's h1, a `ul` of links and the host's sections, each with its own h2, of which only the open one is in the accessibility tree.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the list | moves through the section links in order, then into the section | the next link, then the section's first control | by hand |
| Enter | a section link | opens that section | the host's focus after a route change | by hand |
| Enter | the back link on a phone | returns to the list | the host's focus after a route change | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| list | navigation | the h1 through `aria-labelledby` | none | "Settings, navigation" | test |
| row | link | its name, then its hint on a phone | `aria-current="page"` when open | the name and "link", then "current page" | test |
| chevron | none, `aria-hidden` | none | none | nothing | by hand |
| back link | link | its words | none | "Back to settings, link" | test |
| a section not open | none: `invisible` and `inert`, so it is out of the accessibility tree and the tab order | none | none | nothing | test |
| group | region, from `section` with `aria-labelledby` | its h3 | none | the heading, then the rows | test |
| row name | label, bound to the control by the Field | its text | none | the control's name | test |
| row description | none, bound by `aria-describedby` | none | none | after the control's name | test |
| link row | link | its name, value and description | none | "Language and dates, English, Monday first, link" | test |

## Tokens
| Part | State | Token |
|---|---|---|
| list on a phone | all | `--card`, `--r-2xl` |
| row | all | `--r-xl`, `--control` |
| row | hover, pressed | `--muted`, `--hover`, `--t-press`, `--curve` |
| row from 1024px | rest, current | `--muted-foreground`, then `--foreground` on `--t-settle` |
| pill from 1024px | current | `--thumb`, `--r-xl`, `--t-settle`, `--curve-settle` |
| hint, chevron | all | `--muted-foreground` |
| group's card | all | `--card`, `--r-2xl` |
| group heading, row description, link row value | all | `--muted-foreground` |
| link row | hover, pressed | `--muted`, `--hover`, `--t-press`, `--curve` |

## Related
- Nav: the app's main sections across the top.
- Tabs: views of one record.
- BackLink: the link back to the list on a phone.
- Switch: the setting that acts on the flip.
- SaveLine: the line a row or a group says its saves in.
- Toaster: where useUndoable's Undo shows.
- RadioGroup: a choice among a few, saved with its form.
- List and detail: a list beside the record that is open, which becomes two screens on a phone.
- Sidebar: the app's navigation down the side, in groups, with a mark that slides to the current place.
