Skip to content

Motion Token Architecture: Duration, Easing, and Composite Layers #674

Closed

Description

@tedmcdo

Summary

This proposal outlines a motion token system for XDS, organized into three layers: duration, easing, and composites. This document covers the naming approaches evaluated and the rationale for the layered architecture landed on.

Naming Schemes Considered

1. Flat Semantic Tokens (e.g. --motion-enter, --motion-slide-in)

Pros:

  • Simple to consume, one token per use case
  • Abstracts away implementation details (builders don't need to think about curves or timing)
  • Easy to enforce consistency since there are fewer knobs to turn

Cons:

  • Without primitive layers underneath, it may lead to many combinations. Every new interaction pattern (enter, exit, slide, expand, collapse, fade, etc.) needs its own token. A layered approach helps with this by letting builders compose from primitives directly when no composite token exists.
  • Hard to extend without breaking the naming convention.

2. Physics-Based Tokens (e.g. springs)

Pros:

  • Feels most natural visually
  • Can accommodate some very complex animations

Cons:

  • Springs are JavaScript-exclusive. They require a JS animation runtime and cannot be expressed as CSS custom properties, making them a poor fit for a token-based system and significantly harder to theme.
  • The CSS linear() function can approximate spring curves by baking them into a series of stops, but the resulting values are verbose and difficult to customize or hand-tune compared to a simple cubic-bezier() with four control points.
  • Harder to adopt for builders unfamiliar with spring dynamics

3. Scale-Based Naming (e.g. --duration-100, --duration-200, etc.)

Pros:

  • Zero ambiguity, you know exactly what you're getting
  • Easy to reason about relationships (300 is between 200 and 400)
  • Simple to add new values without renaming everything (just add --duration-275)

Cons:

  • If you ever want to globally shift your timing scale (say, make everything 20% faster), you'd have to update every value and every reference, or live with misleading names (--duration-300: 240ms).
  • Loses the "why". Seeing --duration-300 on a component doesn't tell you how it's being used (e.g. micro-interaction or a layout shift).

4. Layered Primitives + Composites (proposed approach)

Pros:

  • Separation of concerns: duration and easing are independent axes that can be mixed and matched
  • Composites provide guardrails: semantic composite tokens (--motion-enter, --motion-exit) give builders the easy path while the primitives remain accessible for edge cases
  • Extensible: adding a new easing curve doesn't require touching duration tokens, and vice versa
  • Readable: var(--duration-medium) var(--easing-decelerate) is self-documenting in a way that var(--motion-200) is not
  • Range support: duration tokens can express a range (fast-min, fast, fast-max) giving designers flexibility within a bounded corridor

Cons:

  • Slightly more complex than a flat system. Builders need to understand the layering to customize.
  • Composite tokens need to be curated to avoid becoming too large to manage easily.
  • The min/max range convention for durations is non-standard and needs documentation (based on XMDS)

Proposed Token Structure

:root {
    /* Layer 1: Duration primitives */
    --duration-fast-min: 130ms;
    --duration-fast: 175ms;
    --duration-fast-max: 230ms;
    --duration-medium-min: 310ms;
    --duration-medium: 410ms;
    --duration-medium-max: 550ms;

    /* Layer 2: Easing primitives */
    --easing-decelerate: cubic-bezier(0.24, 1, 0.4, 1);

    /* Layer 3: Semantic composites */
    --motion-enter: var(--duration-medium-max) var(--easing-decelerate);
    --motion-exit: var(--duration-medium-min) var(--easing-decelerate);
    --motion-slide-in: var(--duration-medium) var(--easing-decelerate);
    --motion-slide-out: var(--duration-medium-min) var(--easing-decelerate);
}

Why This Approach

Duration and easing are distinct concerns. By keeping primitives separate and composing them into semantic tokens at a higher layer, we get:

  1. A small token surface: a handful of durations x a handful of easings covers a wide range of use cases
  2. Composites as the happy path: most builders should reach for --motion-enter and never think about the layers beneath
  3. Primitives as an escape hatch: when a component needs a non-standard combination, it can compose from primitives rather than requesting a new one-off token
  4. Clear mental model: "pick your duration, pick your easing, or use a preset" is easy to teach
  5. Avoids explosion of combinations: composite tokens only need to cover the most common patterns. When a component needs a non-standard combination, builders compose directly from primitives (var(--duration-fast) var(--easing-decelerate)) rather than requesting a new semantic token. The primitives handle the long tail.

Questions to answer

  • What additional primitives and composites are needed?
  • How should reduced-motion preferences interact with these tokens? (e.g. --duration-fast: 0ms under prefers-reduced-motion?)
  • Should composites include transition-property or stay limited to duration/easing values? Under the current proposal builders still have to specify what is being transitioned, like opacity, transforms, etc.

Activity

  1. added
    theming
    design
    on Mar 18, 2026
  2. tedmcdo commented on Mar 18, 2026

    @tedmcdo
    ContributorAuthor

    Will upload a prototype (3/18) using this token structure to demonstrate navigational changes.

  3. added
    enhancement
    on Mar 18, 2026
  4. rubyycheung commented on Mar 18, 2026

    @rubyycheung
    Contributor

    @tedmcdo can you add a compute formula and another example for comparision?

  5. rubyycheung commented on Mar 18, 2026

    @rubyycheung
    Contributor

    Cindy: Hardcode for now to help with exploration and decision-making

  6. tedmcdo commented on Mar 18, 2026

    @tedmcdo
    ContributorAuthor

    @tedmcdo can you add a compute formula and another example for comparision?

    Durations are decreasing values by 25% from 550. Then the numbers get rounded to cleaner numbers. This was meant to align with typical ranges for enter/exit ratios: exits should generally be 60-75% the speed of entrances.

  7. cixzhang commented on Mar 18, 2026

    @cixzhang
    Contributor

    Motion Token Analysis & Vibe Test Results

    Hey Ted! We did a deep audit of existing animations in XDS and ran a vibe test on the proposed token architecture. Here's everything.


    Audit: Current Animation Surface

    XDS currently has 2 motion tokens in tokens.stylex.ts:

    '--transition-fast': '0.15s ease',   // 150ms
    '--transition-normal': '0.2s ease',  // 200ms

    These bundle duration + easing into one shorthand, which is technically invalid when used as transitionDuration (the ease leaks in). The new system fixes this by separating concerns.

    30 components use these tokens (Button, Calendar, Checkbox, Switch, Tab, etc.) — all mechanical find-and-replace migrations. 6 components bypass the tokens entirely with hardcoded values — these are the highest-priority targets:

    Component Current Hardcoded Value Proposed Token
    MobileNav (drawer) 0.25s cubic-bezier(0.4, 0, 0.2, 1) --motion-slide-in / --motion-slide-out
    Collapsible (chevron) 150ms ease --duration-fast + --easing-decelerate
    HoverCard 0.15s ease --duration-fast + --easing-decelerate
    Popover 0.15s ease --duration-fast + --easing-decelerate
    Tooltip 0.1s ease --duration-fast-min + --easing-decelerate
    TopNavMegaMenu (panel) 0.2s ease-out --motion-enter

    4 looping animations (Spinner, Skeleton, StatusDot, ProgressBar indeterminate) don't fit the enter/exit model — recommend leaving as-is.


    Vibe Test: Do LLMs Use min/max Variants?

    We ran a structured vibe test — 10 prompts × 2 configs (with and without min/max range tokens), 20 sub-agent runs total.

    Result: LLMs absolutely reach for min/max variants, and they produce better motion design when they have them.

    • 9 of 10 with-range prompts used at least one min/max variant
    • --duration-medium-min was the most popular (5 uses) — naturally chosen for dropdowns, popovers, accordion collapses, and exit animations
    • Simple interactions (card hover, tab toggle) produced identical results in both configs — no added confusion

    Where range tokens made the biggest difference

    Asymmetric timing — when prompts asked for "snappier close" or "faster collapse":

    Prompt With Range Without Range
    Dropdown open/close 310ms → 230ms (26% delta) 410ms → 175ms (57% delta)
    Accordion expand/collapse 410ms → 310ms (25% delta) 410ms → 175ms (57% delta)
    Side panel enter/exit 550ms / 410ms / 310ms (3-layer stagger) 410ms / 175ms (binary jump)

    Without range tokens, the agent is forced into jarring ratios because there's no middle ground between fast and medium.

    Element-size differentiation:

    Element With Range Without Range
    Full dialog medium-max (550ms) medium (410ms)
    Small popover medium-min (310ms) medium (410ms)
    Checkbox toggle fast-min (130ms) fast (175ms)

    With only 2 durations, a small popover and a full dialog get the same timing.

    One caveat: The LLM treats the "Use when..." descriptions as gospel. Having "tooltip fades" listed under --duration-medium-min (310ms) led the agent to pick 310ms for tooltips — but XDS currently uses 100ms. The documentation descriptions need careful curation.


    Answers to Open Questions

    1. prefers-reduced-motion: We'd handle this at the consumption site, not in the tokens. The tokens always represent designed intent; a global rule (@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; } }) disables animation system-wide. This matches existing behavior in MobileNav/StatusDot and ensures nothing slips through.

    2. Should composites include transition-property? Recommend no — keep them limited to duration/easing. Builders should still specify what's being transitioned. This keeps the composites simple and avoids encoding layout assumptions.

    3. What additional primitives/composites? Based on the audit:

    • Add --easing-standard: cubic-bezier(0.4, 0, 0.2, 1) — MobileNav already uses this, and the vibe test agents naturally chose it for symmetric transitions (hover, toggle states)
    • Consider whether we need --easing-accelerate for exit-only animations (nothing uses it today, but it completes the set)

    Idea: Computed Duration Scale

    Rather than defining all 6 duration values manually, we could derive min/max from base values + a ratio in the theme config — as a dedicated motionScale key, similar to how type scales work:

    const oceanTheme = defineTheme({
      motionScale: {
        fast: '175ms',
        medium: '410ms',
        ratio: 0.75,  // min = base * ratio, max = base / ratio
      },
    });
    
    // Computed at theme creation:
    // --duration-fast-min:  175 * 0.75 = 131ms  ≈ 130ms
    // --duration-fast-max:  175 / 0.75 = 233ms  ≈ 230ms
    // --duration-medium-min: 410 * 0.75 = 308ms ≈ 310ms
    // --duration-medium-max: 410 / 0.75 = 547ms ≈ 550ms

    This means theme authors only configure 3 values (fast, medium, ratio) and get a coherent 6-token scale. A "snappy" theme sets a lower base; a "cinematic" theme raises the base — and the proportional relationships are preserved automatically.


    Summary

    Aspect Finding
    Migration scope ~36 files, mechanically simple
    Min/max range ✅ Keep it — LLMs use it well, enables better asymmetric timing
    Composites ✅ Discoverable and used naturally as shortcuts
    Reduced motion Handle globally, not in tokens
    Token docs Critical — LLMs follow "Use when..." literally
    Duration scale Compute min/max from base + ratio via motionScale config

    — via Navi on behalf of @Cindyxz

  8. added 3 commits that reference this issue on Mar 18, 2026
    e235a71
    ef281aa
    3d3cbc2
  9. added 2 commits that reference this issue on Apr 26, 2026
    eacbd34
    442b505
  10. added 4 commits that reference this issue on Jun 21, 2026
    90b1141
    e90894d
    a64fd14
    7d760c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    designenhancementtheming

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions