Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/motion-doc-own-css.md
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions packages/cli/assets/docs/motion.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,52 @@ const styles = stylex.create({
},
],
},
{
id: 'own-css',
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
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.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: a token read with getComputedStyle(el).getPropertyValue('--duration-medium') is the string 410ms, and element.animate() rejects that as a duration. Saying to convert it to milliseconds first would save readers the TypeError.

},
{
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);
}
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

@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;
}
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
}`,
},
],
},
{
id: 'theme-motion',
title: 'Tune motion from the theme',
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/test/__golden__/no-icon-set/docs-topics.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@
"movement-principles",
"respecting-user-preferences",
"usage",
"own-css",
"theme-motion",
"best-practices"
],
"skeleton": "fd00e4ddb07bfdb6b20ba2d257fe04877d634ce3906fa2fae2a0c21da4161e2f",
"skeleton": "8a2a77f6eb2c4fe1f9238f9c12c3fad4ca21ebfdc4af699fac795c541dc9faca",
"mentions": []
},
"principles": {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/__golden__/no-icon-set/docs-tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@
"movement-principles",
"respecting-user-preferences",
"usage",
"own-css",
"theme-motion",
"best-practices"
],
Expand Down