agentleFS
bydioramabydiorama/ui/.claude/skills/motion-component/SKILL.md

motion-component

Skill11 starsChanged 6 days agoMITView on GitHub

Building, extending or reviewing one of this library's owned motion components (ADR 0028 §6 — Presence, Count, TextSwap, IconSwap, Stagger, Feedback) or any registry component whose job is movement. Use when adding a motion item, when a motion test passes on code that does not animate (or fails on code that does), when an item will not leave, leaves at once, or drops focus, or when a motion level does not reach a component. Covers the API shape, the CSS-first lifecycle, motion levels, and how to MEASURE motion in Chromium.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep every state rendered (IconSwap): when the set is small and known: all glyphs stay in the DOM, a data attribute picks one, and …

    line 27
  2. Distinctive:

    Mount and unmount (Presence): when the content is open-ended:

    line 37

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Motion components

The owned motion components are motion with no look of their own. They follow add-component like everything else — this skill is what that pipeline does not say about movement. ADR 0028 is the decision record; the app-motion skill is the consumer's view of the result.

Before code

  1. A sheet exists, drawn with design-component §1d — filmstrips whose values come from ../design-component/scripts/motion-frames.mjs, a motion-levels table, a token map. Build from its numbers.
  2. The sheet's open decisions went to the user (exit length, compound order, first-render behaviour, a new distance vs a reused token) and are badged Decided on it. Do not settle them in code.
  3. Is it actually yours? Popover, Modal, Sheet, Drawer, Select, Menu and Toast own their mount/unmount motion through Base UI; effects own ambient loops (effects skill). A motion component wraps neither.

Two shapes that worked

Keep every state rendered (IconSwap) when the set is small and known: all glyphs stay in the DOM, a data attribute picks one, and per-state classes carry the transition. Nothing mounts, so there is no exit to wait for, no focus hand-off and no first-render rule to write — the first render simply has no "before". The DESTINATION state's duration-* is the one a transition runs on, so "arrive on base, leave on fast" is two class strings, not code. A filter in the motion (IconSwap's blur) belongs to the hidden state only: the shown state has NO filter, not blur(0), or the element stays on its own layer at rest (craft rule 23). Assert filter: none at rest.

Mount and unmount (Presence) when the content is open-ended:

DecisionWhy
No element of its own; each keyed child is the itemWorks inside <ul>, a stack or a toolbar without changing layout or validity
State on the item as data-<name>="entering|present|leaving"The only thing the CSS reads; tests and devtools can see it
Classes merged onto the child with cloneElement + cn()Keeps tailwind-merge's conflict rules; the child must forward className/ref/data-* (CONVENTIONS §5)
Refs merged with Base UI useRender({ render, ref })It merges the element's OWN ref. Hand-merging inside render trips react-hooks/refs and react-hooks/immutability, and every workaround (useMemo, a state holder) is rejected too
Arrival through starting: (CSS @starting-style)No JavaScript and no extra frame; added ONLY to items that arrived after mount, which is how first-render items stay still
Everything a transition, never a keyframeA reversed change turns around mid-flight. A keyframe is for a true one-shot (a shake), and then motion-safe:
Travel × --ui-motion-travel, durations from tokensReduced and Off then need no code at all
A size change measured and set inline, not a wrapperA wrapper inside <ul> is invalid; auto cannot transition. Clear the inline value when it settles
List state derived DURING render (if (state.children !== children) setState(…))React's documented pattern; an effect would render one frame in the wrong state

Lifecycle traps already paid for

TrapRule
A leaving item removed instantlyWait for the item's OWN getAnimations() after one frame — a transition is created at the next style pass, not at the attribute write. Never its subtree: a spinner inside never finishes
Focus dropped to <body> when an item leavesSetting inert on a focused element blurs it at commit. Move focus FIRST, then set el.inert = true imperatively in the layout effect — never as a rendered prop
Focus target not foundA registry of sibling refs loses the race: React re-attaches refs per fiber, so a sibling's ref can be detached when your effect runs. Items are DOM siblings — walk them (nextElementSibling) for the nearest non-leaving item
A fold restarting mid-flightAn effect that depends on neighbour data re-runs whenever a sibling changes. Keep such values in a ref; depend only on the item's own state
An item added back mid-exit vanishesThe merge must turn leaving back to present for a returning key, and a size animation must transition from its CURRENT inline value
The caller's inline style erasedThe component owns the properties it animates on the item. Say so in the doc and the dont list; an inline height on a collapsing item is overwritten
A height fold that stalls, then jumps shutWith border-box sizing height: 0 stops at padding + border (Presence's collapse sat at 17px for ~170ms, then vanished). Fold height, vertical padding, border and margin together, measured at rest BEFORE closing the box — or put the padding on an inner element. check:motion flags a class string that transitions height beside py-* without padding
A selection that cross-fades between two fillsOne shared element should travel (Tabs: Base UI's Tabs.Indicator and its --active-tab-* variables). Hide the items' own fill only while the indicator is shown, through a variable rather than a competing class, so static HTML and Reduced keep the per-item fill. Base UI keeps the indicator hidden until measured, so its first placement never animates
A panel or item that slides in on page load@starting-style applies to an element's first style too. Gate the entrance on something that is only true after a change — Tabs uses not-data-[activation-direction=none]:starting:
Removal at Off happening synchronouslyOff is 1ms, not 0, precisely so there is still an animation to wait for and a same-frame reversal still works

Measuring motion in Chromium

getComputedStyle reads the same for a working and a dead transition (ADR 0018). Every assertion goes through getAnimations() or transition events.

TrapRule
No transition on code that worksMount and change in one task and the browser has no "before" style. Wait two frames (shown()) between mounting and the change, as any real page has
A slide asserted absent fails at Reduced0% and none are different values, so Chromium still creates a translate transition that moves nothing. Assert where a transition STARTS (effect.getKeyframes()[0]), not whether one exists
A 1ms transition at Off that "never ran"It ends before any frame — even before its own transitionrun is delivered. Assert the computed transitionDuration (0.001s) and the event's propertyName
Reading after the factCapture at transitionrun, registered synchronously right after the change
A neighbour's transition read mid-flightA settle helper waits for the whole subtree's FINITE animations, twice: movement can start a hover transition on something it passes under
A size asserted as a numberAssert the relationship: the item settles at a sibling's own height
Console output swallowed in the browser runnerThrow an Error carrying the findings; vitest prints the message
A probe that removes transition-[x] and the test still passesNot the test's fault: a duration-* with no transition property means transition-property: all, which still includes x. Break the motion itself — skip the inline value, change the kind

Then prove each new test bites: break the duration, the focus hand-off, the travel token — one at a time — watch the named test fail, restore, and never git checkout the probe away.

First of its kind — gates and pages that will not know it yet

WhatRule
starting: utilitiesIn VARIANT (scripts/lib/classes.mjs) and in both enter/exit rules (check:utilities, check:motion) since Presence. A new variant gets the same treatment — probe with a class that cannot exist
A component that paints nothinga11y.rendersNoColour: "<a sentence why>" instead of an invented contrast pair. check:contrast rejects a short reason or one beside pairs
data-slot contractProps extend OwnedSlot even with no element, and the module is listed in registry/ui/data-slot.types.test.tsx — data-slot.test.ts fails until it is
Visual matrixOne case per component (check:visual-coverage); for motion, draw the REST state under every kind — a forgotten inline height or a mid-flight offset shows there. The Linux baseline comes from the "Generate visual baselines" workflow; say so in the handoff
Site catalogueNeeds a motif in apps/site/src/components/motifs/: the BEFORE state, an arrow, the AFTER state, both at rest and at full opacity (the Change helper in utilities.tsx). A frame caught mid-transition reads as broken — half-faded text, a clipped bar — and translucent text fails the catalogue's contrast audit
Widths in a site examplemax-w-sm is --ui-space-sm, 8px, in this theme, not Tailwind's 24rem; Presence's example collapsed to a column of single words. Use an explicit width (w-80 max-w-full). check:utilities now scans apps/site/src/examples too
A slot name that starts with a utility prefix (text-swap)check:utilities read it as a text-* colour, in the JSX attribute and inside a [data-slot="…"] selector string. Data-attribute values are now blanked like prose attributes (scripts/lib/classes.mjs)
A motion item that imports another (@/ui/presence)The alias is listed by hand in the root and Storybook tsconfigs, .storybook/main.ts and vitest.config.ts (uiItems); the error is "Cannot find module"
A component generic over its keys (IconSwap's show: keyof icons)forwardRef loses the generic; cast the result to <K extends string>(props: Props<K> & { ref?: Ref<…> }) => ReactElement, and type the picked key NoInfer<K> so a wrong name errors instead of widening K
A one-shot that must replay (a shake)A CSS keyframe does not restart when its class is re-added. Use el.animate() (the browser's own, not a runtime), ask motionLevel(el) first, read durations and easings from the tokens with getComputedStyle, and put lengths in the keyframes as calc(var(--token) * k) so they follow the token. Cancel the previous run before starting another
A "draw-on" of a glyphcheck:strokes bans stroke-dasharray and check:icons private glyphs. Wipe the shared glyph in with a clip-path: inset() transition from starting: instead; getKeyframes() names it clipPath (camelCase) while the transition is clip-path
A per-item delay (Stagger)Put the index in a custom property on the item and a static class reading it ([transition-delay:calc(var(--i)*var(--step))]); a dynamic class name never compiles. Scope it to the entering state so it does not delay the item's later transitions. Delays summed in calc() come back as 300.00000000000006 — round before comparing
A leaving copy that must never be text (Count's old digit)Draw it with before:content-[attr(data-x)] on an empty aria-hidden span: generated content is not in textContent, not copied, not found, and inside aria-hidden not read
An exiting layer nested inside the arriving oneIt inherits the arrival's starting opacity and moves with it. Make them siblings in one grid cell (col-start-1 row-start-1)
A length token compared with a measured px valueTokens may be authored in rem (--ui-space-xs is 0.25rem). Resolve through a probe element's width: var(--token), never parseFloat
A scaled element's position asserted with getBoundingClientRect()The rect includes the scale: a hidden glyph at 0.5 sits a quarter-size in from its corner. Compare centres
StoriesA type role is a composite — text-label-sm font-semibold overrides its weight and the story gate fails. Use the role alone

Definition of done, beyond add-component

The sheet badged APPROVED, its gaps updated to what was built, and any change made at implementation recorded on it · every phase measured at Full, Reduced and Off · reversal and focus hand-off tested · each new test and each touched gate probed failing first · app-motion updated if consumers should now reach for the component instead of a snippet.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.