diff --git a/docs/4-implementation/web-ui/css-vars.md b/docs/4-implementation/web-ui/css-vars.md index 036d8d62a..fe93c10f3 100644 --- a/docs/4-implementation/web-ui/css-vars.md +++ b/docs/4-implementation/web-ui/css-vars.md @@ -120,6 +120,13 @@ stylesheet names a role and never a number: Stacking inside one component (1 or 2) stays a plain number. A new floating box uses `--z-popover` and `--shadow-pop`. +## Entrance motion + +A box that floats over the page (a menu, a popover, a toast, a dialog) fades in and drops 4px into place when it opens, and a dialog's backdrop fades in. +`theme.css` holds the two animations as variables, `--enter` and `--fade`, each a whole `animation` value, so a rule says `animation: var(--enter)` and writes no keyframe of its own. +Both are `none` under the OS's reduced-motion preference and when the settings menu's motion setting is **reduce**, and back on when it's **allow**. +A new floating box uses them and needs no motion guard of its own. + ## Status tones A badge, a hint, a banner and a toast all take one of five tones, defined in diff --git a/frontend/packages/shared/src/dropdown/Dropdown.css b/frontend/packages/shared/src/dropdown/Dropdown.css index 3271c9c23..bc24ef5a7 100644 --- a/frontend/packages/shared/src/dropdown/Dropdown.css +++ b/frontend/packages/shared/src/dropdown/Dropdown.css @@ -17,6 +17,7 @@ display: inline-block; } .ui-dropdown { + animation: var(--enter); position: absolute; top: calc(100% + 0.25em); left: 0; diff --git a/frontend/packages/shared/src/header-menu/HeaderMenu.css b/frontend/packages/shared/src/header-menu/HeaderMenu.css index c86ad77f1..a31e2219e 100644 --- a/frontend/packages/shared/src/header-menu/HeaderMenu.css +++ b/frontend/packages/shared/src/header-menu/HeaderMenu.css @@ -19,7 +19,10 @@ border-radius: var(--radius-md); background: var(--bg-elev); box-shadow: var(--shadow-pop); - animation: header-menu-enter 140ms ease; + /* Mount-triggered, not a state transition: the popover only exists in the DOM + while open, so a keyframe on entry is the right tool. `--enter` is the + shared one, with its motion guard (`theme.css`). */ + animation: var(--enter); } /* A long list, such as the firing alerts: wide, and it scrolls. */ .header-menu-wide { @@ -28,29 +31,6 @@ max-height: 70vh; overflow-y: auto; } -/* Mount-triggered, not a state transition: the popover only exists in the DOM - while open, so a keyframe on entry is the right tool. */ -@keyframes header-menu-enter { - from { - opacity: 0; - transform: translateY(-0.25em) scale(0.98); - } - to { - opacity: 1; - transform: none; - } -} -@media (prefers-reduced-motion: reduce) { - .header-menu-popover { - animation: none; - } -} -:root[data-motion="reduce"] .header-menu-popover { - animation: none; -} -:root[data-motion="allow"] .header-menu-popover { - animation: header-menu-enter 140ms ease; -} /* A row that is a link or a button. */ .header-menu-item { display: flex; diff --git a/frontend/packages/shared/src/jobq-graph/jobq-graph.css b/frontend/packages/shared/src/jobq-graph/jobq-graph.css index 1d753d554..2966cd3ca 100644 --- a/frontend/packages/shared/src/jobq-graph/jobq-graph.css +++ b/frontend/packages/shared/src/jobq-graph/jobq-graph.css @@ -44,7 +44,7 @@ creates a new `.jg-node` DOM node when its `key` (the node id) is genuinely new, so this only plays once per node, the first time it appears in a fetched snapshot. Same shape as Shell.css's - `shell-page-enter` / the header menu's `header-menu-enter` — + `shell-page-enter` / the shared `--enter` in `theme.css` — see either for the three-rule motion-guard this mirrors. */ .jg-node { margin: 0; diff --git a/frontend/packages/shared/src/theme.css b/frontend/packages/shared/src/theme.css index 47eecffe4..12cca9c51 100644 --- a/frontend/packages/shared/src/theme.css +++ b/frontend/packages/shared/src/theme.css @@ -109,3 +109,46 @@ var(--purple-dim) ); } + +/* Entrance motion. A floating box (a menu, a popover, a toast, a dialog) fades + in and drops a few pixels into place as it opens, and a dialog's backdrop + fades in. `--enter` and `--fade` are whole `animation` values, so a rule + writes `animation: var(--enter)` and the motion guard lives here once: off + under `prefers-reduced-motion` and the motion setting's "reduce", back on + for "allow". */ +:root { + --enter: ui-enter 0.14s ease-out; + --fade: ui-fade 0.14s ease-out; +} +@media (prefers-reduced-motion: reduce) { + :root { + --enter: none; + --fade: none; + } +} +:root[data-motion="reduce"] { + --enter: none; + --fade: none; +} +:root[data-motion="allow"] { + --enter: ui-enter 0.14s ease-out; + --fade: ui-fade 0.14s ease-out; +} +@keyframes ui-enter { + from { + opacity: 0; + transform: translateY(-4px); + } + to { + opacity: 1; + transform: none; + } +} +@keyframes ui-fade { + from { + opacity: 0; + } + to { + opacity: 1; + } +} diff --git a/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css b/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css index 1c2f17c93..3299857bb 100644 --- a/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css +++ b/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css @@ -33,8 +33,12 @@ background: var(--bg-elev); color: var(--fg); } +.ui-dialog[open] { + animation: var(--enter); +} .ui-dialog::backdrop { background: rgba(0, 0, 0, 0.5); + animation: var(--fade); } /* `plain` (see Dialog.tsx's file-top comment): drop this dialog's own card look entirely — sizing/backdrop/scroll behavior above are the diff --git a/frontend/packages/swarm-ui/src/ui/multiselect-filter/MultiselectFilter.css b/frontend/packages/swarm-ui/src/ui/multiselect-filter/MultiselectFilter.css index 73fc86723..13568bcaa 100644 --- a/frontend/packages/swarm-ui/src/ui/multiselect-filter/MultiselectFilter.css +++ b/frontend/packages/swarm-ui/src/ui/multiselect-filter/MultiselectFilter.css @@ -41,6 +41,7 @@ position: relative; } .ui-multiselect-filter-popover { + animation: var(--enter); position: absolute; top: 100%; left: 0; diff --git a/frontend/packages/swarm-ui/src/ui/popover/Popover.css b/frontend/packages/swarm-ui/src/ui/popover/Popover.css index 6e6f95074..2d1f0c763 100644 --- a/frontend/packages/swarm-ui/src/ui/popover/Popover.css +++ b/frontend/packages/swarm-ui/src/ui/popover/Popover.css @@ -3,6 +3,7 @@ card (a `Panel`), so the box itself only floats, casts a shadow and caps its size to the viewport. */ .ui-popover { + animation: var(--enter); position: fixed; z-index: var(--z-popover); box-sizing: border-box; diff --git a/frontend/packages/swarm-ui/src/ui/toast/Toast.css b/frontend/packages/swarm-ui/src/ui/toast/Toast.css index ad9592e62..f392220e1 100644 --- a/frontend/packages/swarm-ui/src/ui/toast/Toast.css +++ b/frontend/packages/swarm-ui/src/ui/toast/Toast.css @@ -14,6 +14,7 @@ pointer-events: none; } .ui-toast { + animation: var(--enter); pointer-events: auto; cursor: pointer; background: var(--bg-elev); diff --git a/frontend/packages/swarm-ui/test/enter-motion.test.mjs b/frontend/packages/swarm-ui/test/enter-motion.test.mjs new file mode 100644 index 000000000..8851a5e1c --- /dev/null +++ b/frontend/packages/swarm-ui/test/enter-motion.test.mjs @@ -0,0 +1,72 @@ +// Floating boxes share one entrance. Run by `npm test`. `theme.css` defines +// `--enter` and `--fade` with the motion guard, and the boxes use them rather +// than a keyframe of their own, so the guard can't be forgotten on a new one. +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { test } from "node:test"; + +const read = (rel) => readFileSync(new URL(rel, import.meta.url), "utf8"); +const theme = read("../../shared/src/theme.css"); + +test("the entrance is off under reduced motion and back on for allow", () => { + assert.match( + theme, + /prefers-reduced-motion: reduce\)\s*\{\s*:root\s*\{\s*--enter:\s*none;\s*--fade:\s*none;/, + ); + assert.match( + theme, + /:root\[data-motion="reduce"\]\s*\{\s*--enter:\s*none;\s*--fade:\s*none;/, + ); + assert.match( + theme, + /:root\[data-motion="allow"\]\s*\{\s*--enter:\s*ui-enter[^;]*;\s*--fade:\s*ui-fade/, + ); +}); + +const BOXES = [ + [ + "dropdown", + "../../shared/src/dropdown/Dropdown.css", + /\.ui-dropdown \{[^}]*animation:\s*var\(--enter\)/, + ], + [ + "header menu", + "../../shared/src/header-menu/HeaderMenu.css", + /\.header-menu-popover \{[^}]*animation:\s*var\(--enter\)/, + ], + [ + "popover", + "../src/ui/popover/Popover.css", + /\.ui-popover \{[^}]*animation:\s*var\(--enter\)/, + ], + [ + "filter popover", + "../src/ui/multiselect-filter/MultiselectFilter.css", + /\.ui-multiselect-filter-popover \{[^}]*animation:\s*var\(--enter\)/, + ], + [ + "toast", + "../src/ui/toast/Toast.css", + /\.ui-toast \{[^}]*animation:\s*var\(--enter\)/, + ], + [ + "dialog", + "../src/ui/dialog/Dialog.css", + /\.ui-dialog\[open\] \{[^}]*animation:\s*var\(--enter\)/, + ], + [ + "dialog backdrop", + "../src/ui/dialog/Dialog.css", + /\.ui-dialog::backdrop \{[^}]*animation:\s*var\(--fade\)/, + ], +]; + +for (const [name, file, re] of BOXES) { + test(`the ${name} enters with the shared motion`, () => { + assert.match(read(file), re); + }); +} + +test("no box keeps a keyframe of its own", () => { + assert.doesNotMatch(read(BOXES[1][1]), /@keyframes/); +});