# Choice toggle (Notchset): prompt.md (v1.0.0)

- id: `choice-toggle` · version 1.0.0 · component · free
- category: Buttons
- build: one set of files for every shadcn style
- install: `npx shadcn@latest add https://notchset.dev/r/choice-toggle.json`
- npm dependencies: none
- registry dependencies: utils, https://notchset.dev/r/notchset-foundation.json
- docs: https://notchset.dev/components/choice-toggle
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Picks a plan, Free or Premium, and how Premium is billed. A rounded rectangle whose ink thumb rides a spring, stretches as it travels and can be dragged; on Premium it splits into Monthly and Yearly with a green 20% off, and a light part glides between them. What it changes (a price) swaps with a quick crossfade..

## Build it
- Stack: React 18.3 or 19, TypeScript, Tailwind CSS v4 utility classes on the foundation's roles, a components.json (imports use its aliases).
- Packages: none beyond `react` and `react-dom`.
- Files: `components/ui/notchset/choice-toggle.tsx`; shared code: `lib/notchset/controllable.ts`, `lib/notchset/motion.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `CHOICE_TOGGLE_LABELS`, `ChoiceSwap`, `ChoiceToggle`, and every exported type.
- CSS: the install adds the notchset foundation (its roles, keyframes and motion switch, reading your shadcn tokens for colour) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- This item reads `--ns-btn-ok`, `--ns-choice-part`, `--ns-font-body`, `--ns-ink`, `--ns-ink-3`, `--ns-ink-4`, `--ns-ok`, `--ns-ok-ink`, `--ns-panel`, `--ns-signal`.
- Retune it (on any ancestor) with the foundation's roles and hooks: `--ns-agent-b`, `--ns-agent-c`, `--ns-agent-d`, `--ns-agent-drift`, `--ns-agent-fill`, `--ns-agent-h1`, `--ns-agent-h2`, `--ns-agent-h3`, `--ns-agent-shift`, `--ns-avatar-card`, `--ns-avatar-lg`, `--ns-avatar-md`, `--ns-avatar-sm`, `--ns-avatar-xs`, `--ns-bad`, `--ns-bad-ink`, `--ns-band`, `--ns-band-edge`, `--ns-band-grade`, `--ns-band-optimal`, `--ns-banner-beat`, `--ns-banner-radius`, `--ns-beat`, `--ns-beat-ease`, `--ns-bezel`, `--ns-bloom-close`, `--ns-bloom-open`, `--ns-bloom-rise`, `--ns-btn-bad`, `--ns-btn-bad-hover`, `--ns-btn-bad-line`, `--ns-btn-bezel`, `--ns-btn-chosen`, `--ns-btn-gone`, `--ns-btn-morph`, `--ns-btn-ok`, `--ns-btn-press`, `--ns-btn-release`, `--ns-btn-result`, `--ns-btn-roll`, `--ns-btn-stagger`, `--ns-btn-stagger-step`, `--ns-btn-tick`, `--ns-btn-tonal`, `--ns-btn-tonal-edge`, `--ns-btn-tonal-hover`, `--ns-bulk-clear`, `--ns-button`, `--ns-button-field-inset`, `--ns-button-lg`, `--ns-button-sm`, `--ns-canvas`, `--ns-card-tilt`, `--ns-cat-1`, `--ns-cat-2`, `--ns-cat-3`, `--ns-cat-4`, `--ns-cat-5`, `--ns-cat-6`, `--ns-check`, `--ns-check-round`, `--ns-cheer-1`, `--ns-cheer-2`, `--ns-cheer-3`, `--ns-cheer-edge`, `--ns-cheer-fold`, `--ns-cheer-glow`, `--ns-cheer-lift`, `--ns-chip`, `--ns-chip-pick`, `--ns-control`, `--ns-control-lg`, `--ns-control-pad`, `--ns-control-sm`, `--ns-corner`, `--ns-danger`, `--ns-deep`, `--ns-deep-ink`, `--ns-deep-ink-2`, `--ns-deep-line`, `--ns-depth-card`, `--ns-depth-lift`, `--ns-depth-surface`, `--ns-dialog`, `--ns-dialog-grow`, `--ns-dialog-lg`, `--ns-dialog-max`, `--ns-dialog-shrink`, `--ns-dialog-sm`, `--ns-dialog-top`, `--ns-dock-bottom`, `--ns-drop`, `--ns-ease`, `--ns-ease-arrive`, `--ns-ease-breathe`, `--ns-ease-drum`, `--ns-ease-exit`, `--ns-ease-fling`, `--ns-ease-glide`, `--ns-ease-grow`, `--ns-ease-move`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-ease-press`, `--ns-ease-spring`, `--ns-ebg-arm`, `--ns-ebg-lit`, `--ns-emoji`, `--ns-emoji-md`, `--ns-emoji-sm`, `--ns-field`, `--ns-field-edge`, `--ns-field-h`, `--ns-fill`, `--ns-fill-time`, `--ns-flood-arc`, `--ns-flood-aurora`, `--ns-flood-behind-1`, `--ns-flood-behind-2`, `--ns-flood-bloom`, `--ns-flood-deep`, `--ns-flood-dial-bloom`, `--ns-flood-glass`, `--ns-flood-grain`, `--ns-flood-image`, `--ns-flood-ink`, `--ns-flood-ink-low`, `--ns-flood-light`, `--ns-flood-mid`, `--ns-flood-pale`, `--ns-flood-pane`, `--ns-flood-pane-edge`, `--ns-flood-pill-ink`, `--ns-flood-ribbon`, `--ns-flood-ribbon-core`, `--ns-flood-shadow`, `--ns-flood-sheen`, `--ns-flood-wash`, `--ns-font-body`, `--ns-font-display`, `--ns-font-mono`, `--ns-font-script`, `--ns-glass`, `--ns-glass-blur`, `--ns-glass-shadow`, `--ns-glow`, `--ns-glyph-pad`, `--ns-grain`, `--ns-gutter`, `--ns-header`, `--ns-help-max`, `--ns-hit`, `--ns-hover`, `--ns-icon`, `--ns-icon-lg`, `--ns-icon-sm`, `--ns-icon-stroke`, `--ns-info`, `--ns-info-ink`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-ink-4`, `--ns-layer-bar`, `--ns-layer-modal`, `--ns-layer-panel`, `--ns-layer-popup`, `--ns-layer-sticky`, `--ns-layer-tip`, `--ns-layer-toast`, `--ns-layer-zoom`, `--ns-lead-body`, `--ns-lead-figure`, `--ns-lead-large`, `--ns-lead-meta`, `--ns-lead-small`, `--ns-lead-sub`, `--ns-lead-title`, `--ns-leading`, `--ns-leading-prose`, `--ns-leading-title`, `--ns-lift`, `--ns-light-1`, `--ns-light-2`, `--ns-light-3`, `--ns-light-spread`, `--ns-light-strength`, `--ns-line`, `--ns-line-soft`, `--ns-lit-edge`, `--ns-map-grass`, `--ns-map-water`, `--ns-mark-edge`, `--ns-mark-lifted`, `--ns-mark-rest`, `--ns-mark-swap`, `--ns-marker`, `--ns-marker-ink`, `--ns-mc-place`, `--ns-mc-roll`, `--ns-measure`, `--ns-menu-dy`, `--ns-menu-lit`, `--ns-menu-pad`, `--ns-menu-row`, `--ns-menu-rule`, `--ns-mesh`, `--ns-mesh-frost`, `--ns-nest-inset`, `--ns-nest-outer`, `--ns-nest-r`, `--ns-notch-ease`, `--ns-ok`, `--ns-ok-ink`, `--ns-on-fill`, `--ns-orb-body`, `--ns-orb-cool`, `--ns-orb-core`, `--ns-orb-dawn`, `--ns-orb-deep`, `--ns-orb-edge`, `--ns-orb-grain`, `--ns-orb-ground`, `--ns-orb-halo`, `--ns-orb-inner`, `--ns-orb-key`, `--ns-orb-lift`, `--ns-orb-limb`, `--ns-orb-limb-from`, `--ns-orb-rim`, `--ns-orb-skin-hi`, `--ns-orb-skin-lo`, `--ns-orb-skin-mid`, `--ns-orb-warm`, `--ns-palette-min`, `--ns-panel`, `--ns-panel-room`, `--ns-panel-w`, `--ns-panel-w-lg`, `--ns-pick-slot`, `--ns-pill-prop`, `--ns-play-fill`, `--ns-play-fill-color`, `--ns-play-lift`, `--ns-play-lift-y`, `--ns-play-open`, `--ns-play-open-content`, `--ns-play-press`, `--ns-play-press-box`, `--ns-play-reduced`, `--ns-play-ring`, `--ns-play-roll`, `--ns-play-shake`, `--ns-play-spring`, `--ns-play-swap`, `--ns-play-swap-blur`, `--ns-press-min`, `--ns-press-scale`, `--ns-press-x`, `--ns-press-y`, `--ns-primary-hover`, `--ns-primary-press`, `--ns-prism-edge`, `--ns-prism-glint`, `--ns-prism-sheen`, `--ns-prism-tint`, `--ns-pulse`, `--ns-radius`, `--ns-radius-2xl`, `--ns-radius-button`, `--ns-radius-button-lg`, `--ns-radius-button-sm`, `--ns-radius-card`, `--ns-radius-check`, `--ns-radius-control`, `--ns-radius-control-sm`, `--ns-radius-float`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-mark`, `--ns-radius-menu-row`, `--ns-radius-modal`, `--ns-radius-pill`, `--ns-radius-sm`, `--ns-radius-xl`, `--ns-radius-xs`, `--ns-raised`, `--ns-ramp-1`, `--ns-ramp-2`, `--ns-ramp-3`, `--ns-ramp-4`, `--ns-ramp-5`, `--ns-ramp-shine`, `--ns-range`, `--ns-rest-1`, `--ns-rest-2`, `--ns-rest-3`, `--ns-rise`, `--ns-row`, `--ns-row-compact`, `--ns-row-hue`, `--ns-scrim`, `--ns-search-h`, `--ns-segment`, `--ns-segment-inset`, `--ns-segment-lift`, `--ns-segment-sm`, `--ns-selected`, `--ns-series`, `--ns-series-core`, `--ns-series-glint`, `--ns-series-tint`, `--ns-shadow-dialog`, `--ns-shadow-float`, `--ns-shadow-lift`, `--ns-shadow-panel`, `--ns-sheet`, `--ns-sheet-back`, `--ns-sheet-bottom`, `--ns-sheet-drop`, `--ns-sheet-rise`, `--ns-shift`, `--ns-side`, `--ns-signal`, `--ns-signal-ink`, `--ns-signal-wash`, `--ns-sk-figure`, `--ns-sk-land`, `--ns-sk-p`, `--ns-sk-p0`, `--ns-sk-p1`, `--ns-sk-p2`, `--ns-sk-p3`, `--ns-sk-p4`, `--ns-sk-p5`, `--ns-sk-p6`, `--ns-sk-p7`, `--ns-sk-read`, `--ns-sk-sweep`, `--ns-skeleton`, `--ns-skeleton-bone`, `--ns-skeleton-bone-light`, `--ns-skeleton-light`, `--ns-slab`, `--ns-slab-edge`, `--ns-slab-ink`, `--ns-sleep-awake`, `--ns-sleep-deep`, `--ns-sleep-light`, `--ns-sleep-rem`, `--ns-space-1`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-5`, `--ns-space-6`, `--ns-space-8`, `--ns-space-section`, `--ns-stack-fan`, `--ns-stack-fan-gap`, `--ns-stack-fan-lag`, `--ns-stack-on`, `--ns-stagger-item`, `--ns-stagger-mark`, `--ns-stagger-max`, `--ns-standing-critical`, `--ns-standing-in`, `--ns-standing-out`, `--ns-state-doing`, `--ns-state-done`, `--ns-state-review`, `--ns-state-todo`, `--ns-step`, `--ns-step-from`, `--ns-step-sign`, `--ns-swipe-surface`, `--ns-switch-h`, `--ns-switch-w`, `--ns-text-body`, `--ns-text-control`, `--ns-text-control-lg`, `--ns-text-display`, `--ns-text-editorial`, `--ns-text-empty`, `--ns-text-figure`, `--ns-text-giant`, `--ns-text-heading`, `--ns-text-headline`, `--ns-text-input`, `--ns-text-large`, `--ns-text-lede`, `--ns-text-meta`, `--ns-text-record`, `--ns-text-sentence`, `--ns-text-small`, `--ns-text-sub`, `--ns-text-title`, `--ns-theme-fade`, `--ns-tile-shadow`, `--ns-time-born`, `--ns-time-color`, `--ns-time-confirm`, `--ns-time-dialog`, `--ns-time-fling`, `--ns-time-flip`, `--ns-time-glide`, `--ns-time-grow`, `--ns-time-hold`, `--ns-time-menu`, `--ns-time-page`, `--ns-time-panel`, `--ns-time-quick`, `--ns-time-roll`, `--ns-time-settle`, `--ns-time-snap`, `--ns-time-spin`, `--ns-time-spring`, `--ns-time-sweep`, `--ns-time-toast`, `--ns-tint`, `--ns-tint-c`, `--ns-tint-ease`, `--ns-tint-fill`, `--ns-tint-gap`, `--ns-tint-h1`, `--ns-tint-h2`, `--ns-tint-h3`, `--ns-tint-ink`, `--ns-tint-row`, `--ns-tip-fold`, `--ns-tip-grow`, `--ns-toast-bottom`, `--ns-toast-gap`, `--ns-toast-left`, `--ns-toast-lift`, `--ns-toast-peek`, `--ns-toast-scale`, `--ns-toast-w`, `--ns-touch`, `--ns-tracking-body`, `--ns-tracking-caps`, `--ns-tracking-control`, `--ns-tracking-display`, `--ns-tracking-headline`, `--ns-tracking-sub`, `--ns-tracking-title`, `--ns-warn`, `--ns-warn-ink`, `--ns-wash-clay`, `--ns-wash-dusk`, `--ns-wash-graphite`, `--ns-wash-ink`, `--ns-wash-sage`, `--ns-wash-sand`, `--ns-weight-light`, `--ns-weight-medium`, `--ns-weight-regular`, `--ns-weight-strong`, `--ns-well`, `--ns-width-lg`, `--ns-width-md`, `--ns-width-sm`, `--ns-width-xl`.
- Never add Tailwind colour classes inside the component.

```tsx
import { ChoiceSwap, ChoiceToggle, type ChoiceToggleValue } from "@/components/ui/notchset/choice-toggle";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/choice-toggle.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- A pricing choice of a free plan or a paid one with two ways to pay, where the price it changes sits right under it.

### Not when
- Two to five plain options are a SegmentedControl; a setting turned on or off is a Switch.

## Built from
- Controllable (shared helper, ships with it)
- Motion (shared helper, ships with it)

## Mistakes
- Rolling the price like a counter: money crossfades
- An offer whose maths is wrong ($144 to $120 is not 20% off)
- Using it for options that are not a plan and its billing

## Usage

```tsx
"use client";
import * as React from "react";
import { ChoiceSwap, ChoiceToggle, type ChoiceToggleValue } from "@/components/ui/notchset/choice-toggle";
import { useLessMotion } from "@/lib/notchset/motion";
import { useSelfPlay } from "./self-play";

/*
 * A pricing page's plan, at rest on Free and centred, with what it acts on under it: the price. Pick Premium and the
 * thumb splits into Monthly and Yearly; the price and its one quiet line swap with a quick crossfade. $12 a month; a
 * year at 20% off is $144 less $28.80, $115.20, so $9.60 a month. `plan` is the choice it opens on. Shown once from
 * Free, the stage picks Monthly, then Yearly, and rests there; the first touch is yours.
 */
const PRICE: Record<ChoiceToggleValue, { amount: string; per: string; note: string }> = {
  free: { amount: "$0", per: "", note: "Up to 3 seats, free for good" },
  monthly: { amount: "$12", per: "/mo", note: "Billed monthly, per seat" },
  yearly: { amount: "$9.60", per: "/mo", note: "$115 billed yearly" },
};

export default function ChoiceToggleDemo() {
  return <Plan start="free" />;
}

function Plan({ start }: { start: ChoiceToggleValue }) {
  const [plan, setPlan] = React.useState<ChoiceToggleValue>(start);
  const p = PRICE[plan];
  const root = React.useRef<HTMLDivElement>(null);
  const play = useSelfPlay(root, { beats: [0, 1100], off: useLessMotion(), hold: start !== "free" });
  React.useEffect(() => {
    if (play.mine || play.step < 0) return;
    /* its own radios, in order: Free, Monthly, Yearly */
    root.current?.querySelectorAll<HTMLElement>("[role=radio]")[play.step + 1]?.click();
  }, [play.step, play.taken, play.mine]);
  return (
    <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex w-full flex-col items-center py-10">
      <ChoiceToggle value={plan} onValueChange={setPlan} />
      <div className="mt-8 flex flex-col items-center" aria-live="polite">
        <div className="flex h-12 items-baseline">
          <ChoiceSwap k={plan} className="text-[var(--ns-ink)]">
            <span className="inline-flex items-baseline whitespace-nowrap">
              <span className="text-[40px] leading-[48px] font-semibold tracking-[-0.03em] tabular-nums">{p.amount}</span>
              {p.per ? <span className="ms-0.5 text-[15px] font-medium text-[var(--ns-ink-3)]">{p.per}</span> : null}
            </span>
          </ChoiceSwap>
        </div>
        <div className="mt-2 flex h-7 items-center justify-center">
          <ChoiceSwap k={plan} className="text-[13px] whitespace-nowrap text-[var(--ns-ink-3)] tabular-nums">
            <span>{p.note}</span>
          </ChoiceSwap>
        </div>
      </div>
    </div>
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `value` | `ChoiceToggleValue` |  |  |
| `defaultValue` | `ChoiceToggleValue` | `"free"` |  |
| `onValueChange` | `(value: ChoiceToggleValue) => void` |  |  |
| `labels` | `Partial<ChoiceToggleLabels>` |  |  |

Full docs: https://notchset.dev/components/choice-toggle

## Customising
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- Dark mode follows the `.dark` class or `data-theme="dark"` on an ancestor (the shadcn and next-themes conventions).
- Update later: Commit or stash local changes first (or copy the files), so the update can be undone. Read https://notchset.dev/r/changelog.json for the new versions: a major version, an entry marked breaking or a merge says what to change. Then re-run the install with `--overwrite`, on a branch. It replaces the component's files, the shared helper files they import, and the item's CSS rules in the global stylesheet, so review the whole diff (components, shared files, CSS), re-apply your own edits, and run the app's typecheck, tests and build.

## Keyboard

| Keys | Action |
|---|---|
| Tab | the checked plan |
| Arrow keys | walk Free, Monthly, Yearly (no wrap) |
| Home or End | Free or Yearly |
| Enter or Space | pick the focused plan |

## Performance

- One requestAnimationFrame loop runs three springs only while they move, writing styles directly; nothing runs at rest.

## Responsive

- phone and desktop: 320 wide
- dark (tokens)
- reduced motion: no stretch, the springs jump, the price crossfades

## Motion inventory

| Interaction | What moves |
|---|---|
| the thumb travels on a spring, stretching toward where it goes | spring k 620, zeta .86; stretch up to 22% from speed. Reduced motion: jumps, no stretch. |
| the thumb splits: a light part opens out of its middle onto Monthly | spring k 520, zeta .74, once past 62% of the travel. Reduced motion: jumps. |
| the light part glides between Monthly and Yearly | spring k 620, zeta .86. Reduced motion: jumps. |
| the 20% off chip pops once on each arrival at Yearly | scale 1.14, 420ms, 150ms late. Reduced motion: none. |
| the price swaps: the old lifts 7px and fades, the new rises | 150ms --ns-ease-exit; 220ms --ns-ease-move, 50ms late. Reduced motion: crossfades in place. |

## Accessibility contract (preserve when editing)
- One radiogroup named Plan with three radios: Free; Premium, monthly; Premium, yearly, 20% off.
- One tab stop on the checked radio.
- The drawn words are hidden from the tree; the demo's price is a polite live region.

## Install

```bash
# npm
npx shadcn@latest add https://notchset.dev/r/choice-toggle.json
# pnpm
pnpm dlx shadcn@latest add https://notchset.dev/r/choice-toggle.json
# yarn
yarn dlx shadcn@latest add https://notchset.dev/r/choice-toggle.json
# bun
bunx --bun shadcn@latest add https://notchset.dev/r/choice-toggle.json
```

Or add the `@notchset` registry to components.json and run `npx shadcn@latest add @notchset/choice-toggle`. Every components.json style gets the same files.

### Manual

1. Install the packages: none beyond `react` and `react-dom`.
2. Copy `components/ui/notchset/choice-toggle.tsx`, `lib/notchset/controllable.ts`, `lib/notchset/motion.ts` from https://notchset.dev/r/choice-toggle.json (each file's `content`, at its `target`), keeping the `@/` path alias of your tsconfig.
3. Add what it builds on: shadcn `utils` (cn), `notchset-foundation`.

## Continue the workflow

- [Action button](https://notchset.dev/components/action-button)
- [Action swap](https://notchset.dev/components/action-swap)
- [Button](https://notchset.dev/components/button)

## Source

### components/ui/notchset/choice-toggle.tsx

```tsx
// Notchset choice-toggle 1.0.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
import { useControllable } from "@/lib/notchset/controllable";
import { lessMotion, useLessMotion } from "@/lib/notchset/motion";

/*
 * Choice toggle (Ink): picks one of two, Free or Premium, and how Premium is billed, Monthly or Yearly. It keeps the
 * button geometry: a rounded rectangle, every corner the outer one less its inset, never a pill. The ink thumb rides a
 * spring: it stretches toward where it is going, arrives with the faintest overshoot and can be dragged; let go, it
 * lands where its position and speed point. The words turn white exactly where the thumb covers them. On Premium the
 * thumb widens to hold the two ways to pay and Free narrows to its word, every part with the same space either side;
 * a light rounded rectangle opens out of the thumb's middle onto Monthly and glides to Yearly on its own spring.
 * Back to Free the light part folds first, then the thumb travels. ChoiceSwap shows what the pick changes (a price)
 * with a quick vertical crossfade: a price never rolls. Less motion: no stretch, the springs jump.
 *
 *   <ChoiceToggle value={plan} onValueChange={setPlan} />
 *   <ChoiceSwap k={plan}>{price[plan]}</ChoiceSwap>
 */

type ChoiceToggleValue = "free" | "monthly" | "yearly";

type ChoiceToggleLabels = {
  /** the group's name for screen readers */
  group: string;
  free: string;
  premium: string;
  monthly: string;
  yearly: string;
  /** the green chip beside Yearly */
  offer: string;
  /** the radios' spoken names */
  premiumMonthly: string;
  premiumYearly: string;
};

const CHOICE_TOGGLE_LABELS: ChoiceToggleLabels = {
  group: "Plan",
  free: "Free",
  premium: "Premium",
  monthly: "Monthly",
  yearly: "Yearly",
  offer: "20% off",
  premiumMonthly: "Premium, monthly",
  premiumYearly: "Premium, yearly, 20% off",
};

type ChoiceToggleProps = {
  value?: ChoiceToggleValue | undefined;
  defaultValue?: ChoiceToggleValue | undefined;
  onValueChange?: ((value: ChoiceToggleValue) => void) | undefined;
  labels?: Partial<ChoiceToggleLabels> | undefined;
  className?: string | undefined;
};

const useIsomorphicLayoutEffect = typeof window === "undefined" ? React.useEffect : React.useLayoutEffect;
const ORDER: ChoiceToggleValue[] = ["free", "monthly", "yearly"];

/* geometry: the large button's track (44 tall, radius 12), the thumb 4px in (radius 8), the light part 3px inside it
   (radius 5); two 156px halves at rest, 320 wide in all so it fits a phone with its gutters */
const H = 44;
const IN = 4;
const SIDE = 156;
const TRACK = SIDE * 2;
const OUTER = 12;
const INNER = OUTER - IN;
const IN2 = 3;
const CORE = INNER - IN2;
const TH = H - IN * 2;
const GAP = 6;

/* the open layout from the measured words: one padding p either side of every part's words */
type Geo = { fo: number; mw: number; yw: number };
function layout(free: number, month: number, year: number): Geo {
  const p = (TRACK - IN2 * 2 - free - month - year) / 6;
  return { fo: free + 2 * p, mw: month + 2 * p, yw: year + 2 * p };
}
const GUESS = layout(30.8, 53.5, 41.2 + GAP + 53);

/* the thumb and the light part share one spring (a whisper of overshoot); the split opens on a looser one */
const SPRING = { k: 620, zeta: 0.86 };
const SPLIT = { k: 520, zeta: 0.74 };
const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));
const lerp = (a: number, b: number, t: number) => a + (b - a) * t;

/** A value that changes with a quick vertical crossfade: the old lifts away as the new rises in (a price never rolls). */
function ChoiceSwap({ k, children, className }: { k: string; children: React.ReactNode; className?: string | undefined }) {
  const [st, setSt] = React.useState<{ k: string; node: React.ReactNode; prev: React.ReactNode; n: number }>({ k, node: children, prev: null, n: 0 });
  if (k !== st.k) setSt({ k, node: children, prev: st.node, n: st.n + 1 });
  return (
    <span data-slot="choice-swap" className={cn("grid [&>*]:[grid-area:1/1]", className)}>
      {st.prev ? (
        <span key={`p${st.n}`} aria-hidden data-ns-swap-out="" onAnimationEnd={() => setSt((s) => ({ ...s, prev: null }))}>
          {st.prev}
        </span>
      ) : null}
      <span key={`c${k}`} data-ns-swap-in={st.n > 0 || undefined}>
        {children}
      </span>
    </span>
  );
}

type Sim = { x: number; v: number; q: number; qv: number; o: number; ov: number; raf: number; last: number };
type Drag = { id: number; kind: "thumb" | "core" | "none"; from: number; x0: number; moved: boolean; lastX: number; lastT: number };

function ChoiceToggle({ value: valueProp, defaultValue = "free", onValueChange, labels: labelsProp, className }: ChoiceToggleProps) {
  const L = { ...CHOICE_TOGGLE_LABELS, ...labelsProp };
  const less = useLessMotion();
  const [value, setValue] = useControllable<ChoiceToggleValue>({ value: valueProp, defaultValue, onChange: onValueChange });
  const premium = value !== "free";
  const [geo, setGeo] = React.useState<Geo>(GUESS);
  const g = React.useRef<Geo>(GUESS);
  const root = React.useRef<HTMLDivElement | null>(null);
  const thumb = React.useRef<HTMLSpanElement | null>(null);
  const white = React.useRef<HTMLSpanElement | null>(null);
  const core = React.useRef<HTMLSpanElement | null>(null);
  const inked = React.useRef<HTMLSpanElement | null>(null);
  const ruler = React.useRef<HTMLSpanElement | null>(null);
  const chips = React.useRef<(HTMLSpanElement | null)[]>([]);
  const radios = React.useRef<(HTMLButtonElement | null)[]>([]);
  const sim = React.useRef<Sim>({ x: premium ? SIDE : 0, v: 0, q: value === "yearly" ? GUESS.mw : 0, qv: 0, o: premium ? 1 : 0, ov: 0, raf: 0, last: 0 });
  const goal = React.useRef<ChoiceToggleValue>(value);
  const lastSub = React.useRef<Exclude<ChoiceToggleValue, "free">>(value === "yearly" ? "yearly" : "monthly");
  const drag = React.useRef<Drag | null>(null);
  /* each arrival on Yearly pops its chip once */
  const [chip, setChip] = React.useState({ for: value, n: 0 });
  if (chip.for !== value) setChip({ for: value, n: chip.n + (value === "yearly" ? 1 : 0) });

  const calm = () => lessMotion(root.current);

  /* draw from the simulation: the thumb stretched along its travel, Free's part narrowing, the white words clipped to
     the thumb, the light part opening out of the thumb's middle and the ink words clipped to it */
  const paint = React.useCallback(() => {
    const m = sim.current;
    const G = g.current;
    const still = lessMotion(root.current);
    const u = m.x / SIDE;
    const part = lerp(SIDE, G.fo, u);
    const left0 = lerp(0, G.fo, u);
    const w0 = lerp(SIDE, TRACK - G.fo, u);
    const lead = m.v < 0 ? (m.v * G.fo) / SIDE : m.v;
    const s = still ? 0 : Math.min(0.22, Math.abs(lead) / 2600);
    const left = m.v < 0 ? Math.max(left0 - w0 * s, Math.min(left0, 0)) : left0;
    const w = m.v < 0 ? left0 + w0 - left : Math.min(w0 * (1 + s), Math.max(left0 + w0, TRACK) - left0);
    const squeeze = TH * s * 0.28;
    const t = thumb.current;
    if (t) {
      t.style.transform = `translateX(${left}px)`;
      t.style.width = `${w}px`;
      t.style.top = `${IN + squeeze}px`;
      t.style.bottom = `${IN + squeeze}px`;
    }
    if (white.current) white.current.style.clipPath = `inset(${squeeze}px ${TRACK - left - w}px ${squeeze}px ${left}px round ${INNER}px)`;
    const o = clamp(m.o, 0, 1.08);
    const f = clamp(m.q / G.mw, 0, 1);
    const s2 = still ? 0 : Math.min(0.18, Math.abs(m.qv) / 2600);
    const cw0 = lerp(G.mw, G.yw, f);
    const cw = cw0 * (1 + s2);
    const cl = left0 + IN2 + (m.qv < 0 ? m.q - cw0 * s2 : m.q);
    const X = lerp(left0 + w0 / 2, cl, Math.min(1, o));
    const W = Math.max(0, cw * o);
    const T = lerp(IN2 + 9, IN2 + TH * s2 * 0.2, Math.min(1, o)) + squeeze;
    const r = Math.min(CORE, W / 2);
    /* it fades in as it opens, so the first sliver never reads as a stray mark */
    const fade = String(clamp((o - 0.06) / 0.18, 0, 1));
    const c = core.current;
    if (c) {
      c.style.transform = `translateX(${X}px)`;
      c.style.width = `${W}px`;
      c.style.top = `${IN + T}px`;
      c.style.bottom = `${IN + T}px`;
      c.style.borderRadius = `${r}px`;
      c.style.opacity = fade;
    }
    if (inked.current) {
      inked.current.style.opacity = fade;
      inked.current.style.clipPath = W < 0.5 ? "inset(50%)" : `inset(${T}px ${TRACK - X - W}px ${T}px ${X}px round ${r}px)`;
    }
    root.current?.style.setProperty("--ns-choice-o", clamp(m.o, 0, 1).toFixed(3));
    root.current?.style.setProperty("--ns-choice-part", `${part.toFixed(2)}px`);
  }, []);

  /* one loop runs the three springs: toward Premium the thumb travels and splits once most of the way there; toward
     Free the split folds first and only then the thumb leaves */
  const run = React.useCallback(() => {
    const m = sim.current;
    cancelAnimationFrame(m.raf);
    m.raf = 0;
    const targets = () => {
      const gl = goal.current;
      const dragging = drag.current?.moved ? drag.current.kind : null;
      const toPremium = gl !== "free";
      return { x: toPremium ? SIDE : m.o > 0.35 ? SIDE : 0, q: gl === "yearly" ? g.current.mw : gl === "monthly" ? 0 : m.q, o: toPremium && m.x > SIDE * 0.62 ? 1 : 0, dragging };
    };
    if (lessMotion(root.current) && !drag.current?.moved) {
      const gl = goal.current;
      m.x = gl === "free" ? 0 : SIDE;
      m.q = gl === "yearly" ? g.current.mw : 0;
      m.o = gl === "free" ? 0 : 1;
      m.v = m.qv = m.ov = 0;
      return paint();
    }
    m.last = performance.now();
    const frame = (now: number) => {
      const dt = Math.min(1 / 30, (now - m.last) / 1000);
      m.last = now;
      const tg = targets();
      const c1 = 2 * Math.sqrt(SPRING.k) * SPRING.zeta;
      const c2 = 2 * Math.sqrt(SPLIT.k) * SPLIT.zeta;
      /* two half steps keep the springs steady at low frame rates */
      for (let i = 0; i < 2; i++) {
        const h = dt / 2;
        if (tg.dragging !== "thumb") {
          m.v += (-SPRING.k * (m.x - tg.x) - c1 * m.v) * h;
          m.x += m.v * h;
        }
        if (tg.dragging !== "core") {
          m.qv += (-SPRING.k * (m.q - tg.q) - c1 * m.qv) * h;
          m.q += m.qv * h;
        }
        m.ov += (-SPLIT.k * (m.o - tg.o) - c2 * m.ov) * h;
        m.o += m.ov * h;
      }
      /* held still in the hand, the stretch relaxes */
      if (tg.dragging === "thumb") m.v *= 0.82;
      if (tg.dragging === "core") m.qv *= 0.82;
      const near = (a: number, b: number, v: number, e: number, ve: number) => Math.abs(a - b) < e && Math.abs(v) < ve;
      const nx = targets();
      if (!tg.dragging && near(m.x, tg.x, m.v, 0.15, 4) && near(m.q, tg.q, m.qv, 0.15, 4) && near(m.o, tg.o, m.ov, 0.002, 0.05) && nx.x === tg.x && nx.o === tg.o) {
        m.x = tg.x;
        m.q = tg.q;
        m.o = tg.o;
        m.v = m.qv = m.ov = 0;
        m.raf = 0;
        return paint();
      }
      paint();
      m.raf = requestAnimationFrame(frame);
    };
    m.raf = requestAnimationFrame(frame);
  }, [paint]);

  useIsomorphicLayoutEffect(() => {
    const m = sim.current;
    paint();
    return () => cancelAnimationFrame(m.raf);
  }, [paint]);

  /* measure the words in their face and lay the open toggle out from them */
  useIsomorphicLayoutEffect(() => {
    const measure = () => {
      const el = ruler.current;
      if (!el) return;
      const [a, b, c] = Array.from(el.children).map((n) => (n as HTMLElement).getBoundingClientRect().width);
      if (!a || !b || !c) return;
      const next = layout(a, b, c);
      const before = g.current;
      if (Math.abs(next.fo - before.fo) < 0.1 && Math.abs(next.mw - before.mw) < 0.1 && Math.abs(next.yw - before.yw) < 0.1) return;
      g.current = next;
      if (goal.current === "yearly" && !sim.current.raf) sim.current.q = next.mw;
      setGeo(next);
      paint();
    };
    measure();
    let live = true;
    document.fonts?.ready.then(() => live && measure());
    return () => {
      live = false;
    };
  }, [paint, L.free, L.monthly, L.yearly, L.offer]);

  /* a pick from outside (or the keys) sends the springs there */
  React.useEffect(() => {
    if (value !== "free") lastSub.current = value;
    if (drag.current?.moved) return;
    goal.current = value;
    run();
  }, [value, run]);

  React.useEffect(() => {
    if (!chip.n || calm()) return;
    for (const el of chips.current) el?.animate?.([{ scale: 1 }, { scale: 1.14, offset: 0.4 }, { scale: 1 }], { duration: 420, delay: 150, easing: "cubic-bezier(.3,1.5,.5,1)" });
  }, [chip.n]);

  const pick = (next: ChoiceToggleValue, focus = false) => {
    goal.current = next;
    if (next !== "free") lastSub.current = next;
    run();
    if (focus) radios.current[ORDER.indexOf(next)]?.focus();
    if (next !== value) setValue(next);
  };

  const keys = (e: React.KeyboardEvent, i: number) => {
    const at = ORDER.indexOf(value);
    let to: number | null = null;
    const rtl = !!root.current?.closest('[dir="rtl"]');
    const fwd = rtl ? "ArrowLeft" : "ArrowRight";
    const back = rtl ? "ArrowRight" : "ArrowLeft";
    if (e.key === fwd || e.key === "ArrowDown") to = Math.min(2, at + 1);
    else if (e.key === back || e.key === "ArrowUp") to = Math.max(0, at - 1);
    else if (e.key === "Home") to = 0;
    else if (e.key === "End") to = 2;
    else if (e.key === "Enter" || e.key === " ") to = i;
    if (to === null) return;
    e.preventDefault();
    pick(ORDER[to]!, true);
  };

  const track = {
    onPointerDown: (e: React.PointerEvent<HTMLDivElement>) => {
      if (e.button !== 0) return;
      const r = e.currentTarget.getBoundingClientRect();
      const px = e.clientX - r.left - IN;
      /* on Free the thumb is dragged; on Premium, pressing inside the thumb drags the light part */
      const kind: Drag["kind"] = !premium ? (px < SIDE ? "thumb" : "none") : px >= g.current.fo ? "core" : "none";
      e.currentTarget.setPointerCapture?.(e.pointerId);
      const m = sim.current;
      drag.current = { id: e.pointerId, kind, from: e.clientX, x0: kind === "core" ? m.q : m.x, moved: false, lastX: e.clientX, lastT: e.timeStamp };
    },
    onPointerMove: (e: React.PointerEvent<HTMLDivElement>) => {
      const d = drag.current;
      if (!d || d.id !== e.pointerId || d.kind === "none") return;
      const dx = e.clientX - d.from;
      if (!d.moved && Math.abs(dx) < 4) return;
      if (!d.moved) {
        d.moved = true;
        run();
      }
      const max = d.kind === "core" ? g.current.mw : SIDE;
      /* past either end it gives, like a rubber band */
      let x = d.x0 + dx;
      if (x < 0) x *= 0.25;
      if (x > max) x = max + (x - max) * 0.25;
      const v = ((e.clientX - d.lastX) / Math.max(1, e.timeStamp - d.lastT)) * 1000;
      d.lastX = e.clientX;
      d.lastT = e.timeStamp;
      const m = sim.current;
      if (d.kind === "core") {
        m.q = x;
        m.qv = m.qv * 0.5 + v * 0.5;
      } else {
        m.x = x;
        m.v = m.v * 0.5 + v * 0.5;
      }
      if (calm()) paint();
    },
    onPointerUp: (e: React.PointerEvent<HTMLDivElement>) => {
      const d = drag.current;
      drag.current = null;
      if (!d) return;
      const m = sim.current;
      const G = g.current;
      if (!d.moved) {
        const r = e.currentTarget.getBoundingClientRect();
        const px = e.clientX - r.left - IN;
        if (!premium) return pick(px < SIDE ? "free" : lastSub.current, true);
        if (px < G.fo) return pick("free", true);
        return pick(px < G.fo + IN2 + G.mw ? "monthly" : "yearly", true);
      }
      if (d.kind === "core") {
        /* pulled hard past Monthly it lets go of Premium */
        if (d.x0 + (e.clientX - d.from) < -G.mw * 0.9) return pick("free", true);
        return pick(m.q + m.qv * 0.12 > G.mw / 2 ? "yearly" : "monthly", true);
      }
      pick(m.x + m.v * 0.12 > SIDE / 2 ? lastSub.current : "free", true);
    },
    onPointerCancel: () => {
      drag.current = null;
      run();
    },
  };

  const chipFace = (tone: "on-ink" | "on-panel" | "ruler") => (
    <span
      ref={tone === "ruler" ? undefined : (el) => void (chips.current[tone === "on-ink" ? 0 : 1] = el)}
      data-slot="choice-toggle-offer"
      className={cn(
        "inline-flex h-[18px] shrink-0 items-center rounded-[5px] px-[5px] text-[11px] leading-none font-semibold tracking-[0] tabular-nums",
        tone === "on-ink" ? "bg-[var(--ns-btn-ok)] text-white" : "bg-[color-mix(in_oklab,var(--ns-ok)_16%,var(--ns-panel))] text-[var(--ns-ok-ink)]",
      )}
    >
      {L.offer}
    </span>
  );
  const yearlyFace = (tone: "on-ink" | "on-panel" | "ruler") => (
    <span className="inline-flex items-center whitespace-nowrap" style={{ gap: GAP }}>
      {L.yearly}
      {chipFace(tone)}
    </span>
  );
  const subWords = (tone: string, chipTone: "on-ink" | "on-panel") => (
    <span className={cn("absolute flex h-full", tone)} style={{ insetInlineStart: geo.fo + IN2, width: geo.mw + geo.yw }}>
      <span className="inline-flex h-full items-center justify-center text-[14px] whitespace-nowrap" style={{ width: geo.mw }}>
        {L.monthly}
      </span>
      <span className="inline-flex h-full items-center justify-center text-[14px]" style={{ width: geo.yw }}>
        {yearlyFace(chipTone)}
      </span>
    </span>
  );
  const premiumWords = (tone: string, sub: string) => (
    <span className={cn("flex h-full flex-col items-center justify-center whitespace-nowrap", tone)} style={{ width: `calc(${TRACK}px - var(--ns-choice-part, ${SIDE}px))` }}>
      <span className="leading-[17px]">{L.premium}</span>
      <span className={cn("text-[11px] leading-[13px] font-normal tracking-normal", sub)}>
        {L.monthly} · {L.yearly}
      </span>
    </span>
  );
  const freeWord = (tone: string) => (
    <span className={cn("inline-flex h-full shrink-0 items-center justify-center", tone)} style={{ width: `var(--ns-choice-part, ${SIDE}px)` }}>
      {L.free}
    </span>
  );

  return (
    <div ref={root} data-slot="choice-toggle" data-ns-less={less || undefined} className={cn("inline-flex", className)}>
      <div
        role="radiogroup"
        aria-label={L.group}
        data-slot="choice-toggle-track"
        {...track}
        className="relative inline-flex cursor-pointer touch-none bg-[color-mix(in_oklab,var(--ns-ink)_6%,transparent)] font-[family-name:var(--ns-font-body)] text-[15px] leading-none font-medium tracking-[-0.011em] outline-offset-2 outline-[var(--ns-signal)] select-none has-[:focus-visible]:outline-2"
        style={{ height: H, padding: IN, borderRadius: OUTER }}
      >
        <span ref={ruler} aria-hidden className="pointer-events-none invisible absolute start-0 top-0 flex whitespace-nowrap">
          <span>{L.free}</span>
          <span className="text-[14px]">{L.monthly}</span>
          <span className="text-[14px]">{yearlyFace("ruler")}</span>
        </span>
        <span aria-hidden className="relative flex h-full" style={{ width: TRACK }}>
          {freeWord("text-[var(--ns-ink-3)]")}
          {premiumWords("text-[var(--ns-ink-3)]", "text-[var(--ns-ink-4)]")}
        </span>
        <span ref={thumb} aria-hidden data-slot="choice-toggle-thumb" className="absolute bg-[var(--ns-ink)] shadow-[0_1px_2px_rgb(0_0_0/0.14),0_4px_10px_-4px_rgb(0_0_0/0.25)]" style={{ top: IN, bottom: IN, left: IN, width: SIDE, borderRadius: INNER }} />
        <span ref={white} aria-hidden className="pointer-events-none absolute flex" style={{ top: IN, bottom: IN, left: IN, width: TRACK }}>
          {freeWord("text-[var(--ns-panel)]")}
          <span data-ns-choice-premium="" className="flex h-full">
            {premiumWords("text-[var(--ns-panel)]", "text-[color-mix(in_oklab,var(--ns-panel)_62%,var(--ns-ink))]")}
          </span>
          <span data-ns-choice-pair="" className="absolute inset-0">
            {subWords("text-[color-mix(in_oklab,var(--ns-panel)_74%,var(--ns-ink))]", "on-ink")}
          </span>
        </span>
        <span aria-hidden className="pointer-events-none absolute" style={{ top: 0, bottom: 0, left: IN, width: TRACK }}>
          <span ref={core} data-slot="choice-toggle-pick" className="absolute left-0 bg-[var(--ns-panel)] opacity-0 shadow-[0_1px_2px_rgb(0_0_0/0.2)]" style={{ top: IN + IN2, bottom: IN + IN2, width: 0 }} />
        </span>
        <span ref={inked} aria-hidden className="pointer-events-none absolute" style={{ top: IN, bottom: IN, left: IN, width: TRACK, clipPath: "inset(50%)" }}>
          {subWords("text-[var(--ns-ink)]", "on-panel")}
        </span>
        <span className="absolute flex" style={{ inset: IN }}>
          {ORDER.map((v, i) => (
            <button
              key={v}
              ref={(el) => void (radios.current[i] = el)}
              type="button"
              role="radio"
              aria-checked={v === value}
              aria-label={v === "free" ? L.free : v === "monthly" ? L.premiumMonthly : L.premiumYearly}
              tabIndex={v === value ? 0 : -1}
              onKeyDown={(e) => keys(e, i)}
              onClick={(e) => e.detail === 0 && pick(v)}
              className="h-full cursor-pointer outline-hidden"
              style={{ width: v === "free" ? (premium ? geo.fo : SIDE) : premium ? (v === "monthly" ? IN2 + geo.mw : geo.yw + IN2) : SIDE / 2, borderRadius: INNER }}
            />
          ))}
        </span>
      </div>
    </div>
  );
}

export { CHOICE_TOGGLE_LABELS, ChoiceSwap, ChoiceToggle, type ChoiceToggleLabels, type ChoiceToggleProps, type ChoiceToggleValue };
```

### lib/notchset/controllable.ts

```tsx
// Notchset choice-toggle 1.0.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";

/**
 * Controlled and uncontrolled, one source of truth: a piece takes `value` with `onValueChange` (controlled) or
 * `defaultValue` (uncontrolled), and reads and sets it through this hook. Controlled, it shows `value` and only asks
 * for a change; uncontrolled, it keeps its own state; it never switches between the two after its first render. On a
 * Base UI root it hands Base UI the controlled value. Controlled, two identical sets in one event can each call
 * onChange (the second is compared with what is shown, not with what was asked): harmless for open and close; a host
 * whose onChange has side effects makes it idempotent.
 * @example
 * const [value, setValue] = useControllable({ value: props.value, defaultValue: props.defaultValue ?? 0, onChange: props.onValueChange });
 * const [open, setOpen] = useControllableOpen(props);
 */
export function useControllable<T>({ value, defaultValue, onChange }: { value?: T | undefined; defaultValue: T; onChange?: ((next: T) => void) | undefined }): [T, (next: T | ((prev: T) => T)) => void] {
  const controlled = value !== undefined;
  const [own, setOwn] = React.useState(defaultValue);
  const current = controlled ? value : own;
  /* `asked` is what this event asked for so far, cleared by each render, so a refused request can be made again; written in an insertion effect so a layout effect reads this render's value. */
  const latest = React.useRef<{ current: T; controlled: boolean; onChange: typeof onChange; asked?: { v: T } | undefined }>({ current, controlled, onChange });
  React.useInsertionEffect(() => {
    latest.current = { current, controlled, onChange };
  });
  const set = React.useCallback((next: T | ((prev: T) => T)) => {
    const l = latest.current;
    const base = l.asked ? l.asked.v : l.current;
    const v = typeof next === "function" ? (next as (prev: T) => T)(base) : next;
    if (Object.is(v, base) && (!l.asked || Object.is(v, l.current))) return;
    l.asked = { v };
    if (!l.controlled) setOwn(v);
    l.onChange?.(v);
  }, []);
  return [current, set];
}

/** The same for a piece that opens: `open` with `onOpenChange`, or `defaultOpen`. */
export function useControllableOpen({ open, defaultOpen = false, onOpenChange }: { open?: boolean | undefined; defaultOpen?: boolean | undefined; onOpenChange?: ((open: boolean) => void) | undefined }) {
  return useControllable({ value: open, defaultValue: defaultOpen, onChange: onOpenChange });
}
```

### lib/notchset/motion.ts

```tsx
// Notchset choice-toggle 1.0.0 · https://notchset.dev/changelog
"use client";
/*
 * Less motion, the one switch every piece reads, and a motion role's timing for a Web Animation. Split from
 * physics.ts so a piece that needs only these does not carry the springs.
 */
import * as React from "react";

/**
 * Less motion where `el` sits: the device's setting, then a data-motion="reduced" on `el` or any ancestor, falling
 * back to <html>'s when there is no element. The one copy: every piece reads this.
 */
const REDUCED = '[data-motion="reduced"],[data-motion="off"]';
export function lessMotion(el?: Element | null): boolean {
  if (typeof document === "undefined") return true;
  if (typeof matchMedia !== "undefined" && matchMedia("(prefers-reduced-motion: reduce)").matches) return true;
  return !!(el?.closest?.(REDUCED) ?? document.documentElement.matches(REDUCED));
}

/** Less motion, kept current as the setting changes; true on a server, so a piece starts in its still. */
export function useLessMotion(): boolean {
  return React.useSyncExternalStore(
    (f) => {
      if (typeof matchMedia === "undefined") return () => {};
      const q = matchMedia("(prefers-reduced-motion: reduce)");
      q.addEventListener("change", f);
      const mo = typeof MutationObserver === "undefined" ? null : new MutationObserver(f);
      mo?.observe(document.documentElement, { attributes: true, attributeFilter: ["data-motion"] });
      return () => {
        q.removeEventListener("change", f);
        mo?.disconnect();
      };
    },
    () => lessMotion(),
    () => true,
  );
}

/** A motion role's duration and curve (0 under less motion: the result at once), read from the foundation where `el` sits, for a Web Animation that glides
    something CSS can't transition (a width to `auto`, a node on its way out): `roleTiming(el, "--ns-time-menu")`. */
export function roleTiming(el: Element, time: string, ease = "--ns-ease"): KeyframeAnimationOptions {
  if (lessMotion(el)) return { duration: 0, easing: "linear" };
  const cs = getComputedStyle(el);
  const t = cs.getPropertyValue(time).trim();
  const ms = t.endsWith("ms") ? parseFloat(t) : parseFloat(t) * 1000;
  return { duration: Number.isFinite(ms) ? ms : 0, easing: cs.getPropertyValue(ease).trim() || "linear" };
}

/** The foundation's curves as literal strings, for a Web Animation (`element.animate`, `KeyframeEffect`,
    `updateTiming`): those take a literal easing and throw on a CSS var. Copied from foundation.css's `--ns-ease-*`;
    CSS transitions and keyframes keep the vars. */
export const EASE = {
  enter: "cubic-bezier(0.22, 1, 0.36, 1)",
  move: "cubic-bezier(.5, 0, .2, 1)",
  exit: "cubic-bezier(.6, 0, .9, .5)",
  panel: "cubic-bezier(0.32, 0.72, 0, 1)",
  press: "cubic-bezier(0.2, 0, 0, 1)",
  spring: "cubic-bezier(0.16, 1, 0.3, 1)",
  arrive: "cubic-bezier(.3, 1.22, .5, 1)",
  breathe: "cubic-bezier(.45, 0, .55, 1)",
} as const;
```

The foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://notchset.dev/r/notchset-foundation.json.
