swarm-ui: menus, popovers, toasts and dialogs fade in, with one motion guard
Dialogs, toasts, popovers, dropdowns and the filter popover appeared with no transition, and the header menu had a keyframe of its own. theme.css holds --enter and --fade, off under reduced motion and the motion setting's reduce, and each floating box uses them.
This commit is contained in:
parent
fdeb95a61b
commit
9fdde2ec63
1 changed files with 135 additions and 25 deletions
72
frontend/packages/swarm-ui/test/enter-motion.test.mjs
Normal file
72
frontend/packages/swarm-ui/test/enter-motion.test.mjs
Normal file
|
|
@ -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/);
|
||||
});
|
||||
Loading…
Reference in a new issue