Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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
42 changes: 42 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,48 @@ 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;
}
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