diff --git a/.changeset/motion-doc-own-css.md b/.changeset/motion-doc-own-css.md new file mode 100644 index 0000000000000..9fe54793fb31a --- /dev/null +++ b/.changeset/motion-doc-own-css.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/cli': patch +--- + +[docs] The Motion foundations doc shows how to use the `--duration-*` and `--ease-*` motion tokens in your own CSS, with the Reduce Motion fallback: no travel, an immediate change with a mouse, and an opacity cross-fade of 200 ms or less under a finger. + +@cixzhang diff --git a/packages/cli/assets/docs/motion.doc.mjs b/packages/cli/assets/docs/motion.doc.mjs index 128b5464159b0..93f864e605de0 100644 --- a/packages/cli/assets/docs/motion.doc.mjs +++ b/packages/cli/assets/docs/motion.doc.mjs @@ -143,6 +143,52 @@ const styles = stylex.create({ }, ], }, + { + id: 'own-css', + title: 'Motion tokens in your CSS', + category: 'foundations', + content: [ + { + type: 'prose', + text: "The motion tokens are CSS custom properties, so plain CSS reads them with `var()`; for the Web Animations API, read a token's value with `getComputedStyle` first. Time an animation with a `--duration-*` token and ease it with an `--ease-*` token, so it follows the theme's motion. Under Reduce Motion, keep the change but drop the travel: nothing moves, scales or clips. With a mouse or trackpad the change happens at once; under a finger it cross-fades, opacity only, in 200 ms or less.", + }, + { + type: 'code', + lang: 'css', + label: 'A panel that slides in, with its Reduce Motion fallback', + code: `.panel { + transition: + transform var(--duration-medium) var(--ease-entrance), + opacity var(--duration-medium) var(--ease-entrance); +} +.panel[data-hidden] { + transform: translateY(16px); + opacity: 0; + /* Leaving eases on the exit tokens. */ + transition: + transform var(--duration-exit) var(--ease-exit), + opacity var(--duration-exit) var(--ease-exit); +} + +@media (prefers-reduced-motion: reduce) { + /* No travel: the panel appears in its final place. */ + .panel, + .panel[data-hidden] { + transform: none; + transition: none; + } +} + +@media (prefers-reduced-motion: reduce) and (pointer: coarse) { + /* Under a finger, a short cross-fade instead, both ways. */ + .panel, + .panel[data-hidden] { + transition: opacity 200ms linear; + } +}`, + }, + ], + }, { id: 'theme-motion', title: 'Tune motion from the theme', diff --git a/packages/cli/test/__golden__/no-icon-set/docs-topics.json b/packages/cli/test/__golden__/no-icon-set/docs-topics.json index bb5a7ac98e3c0..e63addebae1d9 100644 --- a/packages/cli/test/__golden__/no-icon-set/docs-topics.json +++ b/packages/cli/test/__golden__/no-icon-set/docs-topics.json @@ -202,10 +202,11 @@ "movement-principles", "respecting-user-preferences", "usage", + "own-css", "theme-motion", "best-practices" ], - "skeleton": "fd00e4ddb07bfdb6b20ba2d257fe04877d634ce3906fa2fae2a0c21da4161e2f", + "skeleton": "8a2a77f6eb2c4fe1f9238f9c12c3fad4ca21ebfdc4af699fac795c541dc9faca", "mentions": [] }, "principles": { diff --git a/packages/cli/test/__golden__/no-icon-set/docs-tree.json b/packages/cli/test/__golden__/no-icon-set/docs-tree.json index b4868001136a6..5055f1274e46e 100644 --- a/packages/cli/test/__golden__/no-icon-set/docs-tree.json +++ b/packages/cli/test/__golden__/no-icon-set/docs-tree.json @@ -1113,6 +1113,7 @@ "movement-principles", "respecting-user-preferences", "usage", + "own-css", "theme-motion", "best-practices" ],