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

## Description

Most motion uses one easing curve, `--curve`. Nothing bounces. Controls you use often animate less. Menus and popovers open next to the control that opened them. `registry/cobalt/lib/motion.ts` holds the timings, and a test checks that tokens.css matches it.

## Tokens

<!-- tokens:start motion -->
| Token | Light | Dark | Role |
|---|---|---|---|
| `--t-press` | `140ms` | same | A press, and a colour change under the pointer |
| `--t-pop` | `150ms` | same | Pop: a menu or popover opening; closing takes 70 percent of it |
| `--t-fade` | `150ms` | same | A plain fade with nothing moving |
| `--t-leave` | `200ms` | same | Leave: something closing, and a sheet sliding out |
| `--t-arrive` | `220ms` | same | Arrive: a new item appearing while you watch, a dialog or a toast opening |
| `--t-icon` | `250ms` | same | Two icons, or two wordings, swapping in one place |
| `--t-settle` | `300ms` | same | Settle and Swap, a panel closing, and every sliding thumb: a segmented control's, the active tab's, the nav's pill |
| `--t-crossfade` | `320ms` | same | Large content changing in place |
| `--t-layout` | `450ms` | same | Grow, a panel opening, any change of size |
| `--t-sheet` | `450ms` | same | Slide: a sheet opening |
| `--t-travel` | `500ms` | same | Travel: a shared element moving between two places, on the motion library's travel spring |
| `--curve` | `cubic-bezier(0.23, 1, 0.32, 1)` | same | Every colour change, press, pop, arrive and leave, and the nav's pill sliding |
| `--curve-in-out` | `cubic-bezier(0.77, 0, 0.175, 1)` | same | Two icons, or two wordings, swapping in one place |
| `--curve-sheet` | `cubic-bezier(0.32, 0.72, 0, 1)` | same | Slide |
| `--curve-shake` | `cubic-bezier(0.22, 1, 0.36, 1)` | same | Shake |
| `--curve-layout` | `linear(0, 0.0192, 0.0669, 0.1317, 0.2054, 0.2824, 0.3586, 0.4317, 0.5001, 0.563, 0.62, 0.6711, 0.7164, 0.7564, 0.7914, 0.8219, 0.8483, 0.8711, 0.8907, 0.9075, 0.9218, 0.9341, 0.9445, 0.9533, 0.9608, 0.9671, 0.9724, 0.9769, 0.9807, 0.9839, 0.9865, 0.9888, 0.9906, 0.9922, 0.9935, 0.9946, 0.9955, 0.9963, 0.9969, 0.9974, 0.9979, 0.9982, 0.9985, 0.9988, 1)` | same | Grow in CSS: the layout spring (--t-layout), sampled every 10ms, so a panel that opens moves as the motion library would move it |
| `--curve-settle` | `linear(0, 0.0411, 0.1342, 0.2478, 0.3638, 0.4725, 0.5692, 0.6524, 0.7222, 0.7798, 0.8267, 0.8644, 0.8944, 0.9181, 0.9367, 0.9513, 0.9626, 0.9714, 0.9782, 0.9834, 0.9874, 0.9904, 0.9927, 0.9945, 0.9959, 0.9969, 0.9976, 0.9982, 0.9987, 1)` | same | Settle in CSS: the settle spring (--t-settle), sampled the same way, for a close or a thumb's slide that never keeps the person waiting |
<!-- tokens:end motion -->

## Specimens

Each verb runs live on the system's own part (a Button for Press, a StateButton for Settle, Grow, a Popover, a Sheet, a SegmentedControl's thumb for Travel, Swap, a row arriving and a row leaving, a rejected code for Shake and a NumberField's total for Count), with its duration and curve printed from `registry/cobalt/lib/motion.ts`. Below them, each curve token is plotted from the same file, and Play runs a square along each plot on the token itself, for the time of one real use. Under reduced motion the squares jump to the end.

## Content changes

IconSwap, TextSwap, Crossfade and Swap change what a box shows while the box keeps its size. [Content changes](content-changes) says which one to use.

## Presets

| Motion | Use for                                                          | Preset                                                               |
| ------ | ---------------------------------------------------------------- | -------------------------------------------------------------------- |
| Press  | pressing a control                                               | `pressable` (the `--hover` tint on `duration-press ease-out`)        |
| Settle | a control showing its new state, such as a saved button          | `springs.settle`, StateButton                                        |
| Grow   | a control that grows into its panel by its real width and height | `springs.layout`, Grow                                               |
| Pop    | menus, popovers, selects and tooltips                            | `popup-motion` (`duration-pop` fade, exit at 70 percent)             |
| Slide  | a sheet over the page                                            | `duration-sheet ease-sheet` in, `duration-leave` out, Sheet          |
| Travel | one element moving between two places, such as a selection thumb | `springs.travel`; in CSS, `duration-settle ease-settle` on a segmented control's or tabs' thumb and `duration-layout ease-out` on the nav's pill |
| Swap   | content stepping forward or back in the same box                 | `springs.settle` in, 70 percent of `--t-pop` out, Swap               |
| Arrive | a new item appearing while you watch                             | the `arrive` keyframes in styles.css at `--t-arrive`                 |
| Leave  | an item being removed                                            | a `duration-leave` fade while its height closes on `duration-settle ease-settle` |
| Shake  | an input that was rejected                                       | `shake` from lib/motion.ts                                           |
| Count  | a number that changed                                            | `tabular-nums`, so the width stays the same                          |

## How often

| How often you see it                                                       | Allowed motion                                                             |
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| Hundreds of times a day, such as nav links, tabs, typing, filters, hover   | colour changes only, with `pressable` or `duration-press`                  |
| Tens of times a day, such as saving, opening an item, opening a menu       | one motion at its standard duration                                        |
| Once a day or less, such as pasting a link, verifying an email, publishing | several motions together, up to about 600ms. Staggered lists go only here. |

## Usage

- `rule/motion-tokens-only`: When a component animates, use a named duration such as `duration-press`, a named curve such as `ease-out`, or a spring from `registry/cobalt/lib/motion.ts`, because a raw number cannot be changed from one place. Evidence: app 2/2 source apps define every duration and curve once (tsaglobal apps/web/app/lib/motion.ts, adv-atlas web/css/tokens.css). Check: lint rule/arbitrary-value for `duration-[...]` and `ease-[...]`, and the vitest parity test (`registry/cobalt/lib/motion.test.ts`).
  - Don't: `<div className="transition-opacity duration-300 ease-[cubic-bezier(.2,0,0,1)]">`
  - Do: `<div className="transition-opacity duration-settle ease-out">`
- `rule/motion-no-bounce`: When an element moves, use a spring with `bounce: 0` or the `ease-out` curve, because overshoot draws attention every time it plays. Evidence: app 2/2 source apps ship `bounce: 0` and curves inside 0 to 1 (tsaglobal apps/web/app/lib/motion.ts, adv-atlas web/css/tokens.css); principle heuristic: aesthetic and minimalist design, motion shows the change and nothing more. Check: lint trap/motion-overshoot (scripts/check-system.mjs).
  - Don't: `<motion.div transition={{ type: "spring", bounce: 0.4 }}>`
  - Do: `<motion.div transition={springs.settle}>`
- `rule/motion-exit-faster`: When a surface closes, make its exit 50 to 70 percent as long as its entrance, because a slow exit keeps you waiting on something you already dismissed. Evidence: app 2/2 source apps exit at 55 to 70 percent of the entrance (tsaglobal apps/web/app/app.css popup-motion, adv-atlas web/css/popover.css). Check: review on the showcase.
  - Don't: `<PopoverContent className="data-ending-style:duration-sheet">`
  - Do: `<PopoverContent>`
- `rule/motion-frequent-is-quiet`: When a control is used hundreds of times a day, such as a nav link, a tab, a filter or a row, animate only its colour with `pressable` or `duration-press`, because movement there pulls your eye away from the task. Evidence: person D14; app 2/2 source apps transition only colour on nav links (tsaglobal apps/web/app/components/app-shell.tsx, adv-atlas web/css/bar.css). Check: review of the showcase at the frequent surfaces.
  - Don't: `<a className="hover:-translate-y-0.5 transition-transform duration-settle">Events</a>`
  - Do: `<a className="transition-colors duration-press hover:text-foreground">Events</a>`
- `rule/motion-from-the-control`: When a surface opens from a control, anchor it to that control and fade it in with `popup-motion`, because your eyes stay where you clicked. Evidence: principle heuristic: visibility of system status, the surface shows where it came from; person D14. Check: review of every overlay in the showcase.
  - Don't: `<PopoverContent className="fixed top-1/2 left-1/2">`
  - Do: `<PopoverContent>`
- `rule/motion-press-is-a-tint`: When a control needs press feedback, use `pressable`, which darkens it in place, because scaling moves the label under your finger. Evidence: person D36. Check: review.
  - Don't: `<button className="transition-transform active:scale-95">Save</button>`
  - Do: `<button className="pressable">Save</button>`
- `rule/motion-icon-in-a-slot`: When an icon changes, such as an eye becoming a crossed eye or a check replacing a copy icon, put both glyphs in one fixed box with `IconSwap`, because adding and removing a glyph shifts the text beside it. Evidence: app 3/3 changing icons in tsaglobal sit in an IconSwap cell (components/motion/icon-swap.tsx, components/pill.tsx, components/share-button.tsx); principle heuristic: aesthetic and minimalist design, nothing beside the icon moves. Check: review.
  - Don't: `{copied ? <CheckIcon /> : <CopyIcon />}`
  - Do: `<IconSwap show={copied ? "second" : "first"} first={<CopyIcon />} second={<CheckIcon />} />`
- `rule/motion-reduced`: When `prefers-reduced-motion` is set, keep fades and colour changes and remove movement, because movement can make people with vestibular disorders feel sick. Evidence: app 2/2 source apps strip movement under reduced motion (tsaglobal apps/web/app/app.css, adv-atlas web/css/base.css); principle wcag: 2.3.3 Animation from interactions, movement can be turned off. Check: review with the setting on, against the reduced-motion rule in registry/cobalt/base.css.
  - Don't: `<div className="motion-reduce:transition-none">`
  - Do: `<div className="transition-[opacity,translate] duration-arrive ease-out motion-reduce:translate-0">`

## Accessibility

Under `prefers-reduced-motion`, the base styles limit every transition to opacity and colour. The press tint is a `box-shadow`, so it becomes instant. The base styles also force `scale: 1` on starting and ending styles, which has no effect today because nothing scales. The spinner is the only loop. It has `role="status"` and stops under reduced motion (measured 0 animations, .design-system/evidence/spinner/motion-1280.json). No motion delays a click, a keystroke or a scroll. Every motion is a CSS transition or a spring, so a new state can interrupt it.

## Not tokens

- The press tint is the `--hover` token drawn as an inset `box-shadow` by `pressable`.
- The 70 percent exit is a `calc()` on the entrance token.
- The 4px arrive offset and the 8px settle offset, which Swap and StateButton use, are in `distances` in `registry/cobalt/lib/motion.ts`.
- Swap's exit is 70 percent of `--t-pop`, the same `calc()` a popup's exit uses.
