Motion
GHO-65 recipes on top of the token catalog. Components consume semantic --ghost-* variables. data-motion attributes are documented utilities in @ghostvue/themes default CSS. They are not per-component tokens.
Set --ghost-motion-intensity (0–1, default 1) on any subtree to scale every duration without rewriting each property. Modes still nest through data-ghost-mode.
Progress indicators use the same pace across bundled presets. Determinate progress updates and the shared spinner period scale relative to each preset's default intensity. For example, changing Calm from 0.6 to 0.3 halves both.
Durations and easing
| Token | Use |
|---|---|
motion.duration.instant | Snap with no interpolation |
motion.duration.fast | Color, opacity, and control transitions |
motion.duration.moderate | Default enter |
motion.duration.slow | Large surfaces |
motion.duration.expressive | Emphasized / looping motion |
motion.easing.standard | Symmetric default |
motion.easing.decelerate | Enters |
motion.easing.accelerate | Exits |
Springs
gentle, snappy, and bouncy are authored as stiffness / damping / mass and compiled to CSS linear() plus a settle duration (--ghost-motion-spring-gentle-duration, and the same for snappy and bouncy). Use the easing string as animation-timing-function or transition-timing-function, and the settle duration as the duration.
Choreography
- Exits run faster than enters.
motion.exit.durationaliases fast;motion.enter.durationaliases moderate. Arrivals get time to land; departures get out of the way. - Stagger from the trigger. Offset each item by
n * var(--ghost-motion-stagger). Under reduced motion stagger becomes 0 so the group appears together. - Animate from the trigger origin. Set
transform-origin(ortransform-box) on the moving surface to the point that opened it — the button, the row, the caret — instead of the viewport center.
.menu {
transform-origin: var(--menu-origin, top left);
transition:
opacity var(--ghost-motion-enter-duration) var(--ghost-motion-enter-easing),
transform var(--ghost-motion-enter-duration)
var(--ghost-motion-enter-easing);
}
.menu[data-state='closed'] {
opacity: 0;
transform: translateY(var(--ghost-motion-translate))
scale(var(--ghost-motion-scale));
transition-duration: var(--ghost-motion-exit-duration);
transition-timing-function: var(--ghost-motion-exit-easing);
}Under prefers-reduced-motion: reduce, translate becomes 0px and scale becomes 1, so the same rule fades without moving. Fade duration stays 80ms so the state change is still visible.
Overlay entry and exit
The default theme fades in Dialog, Popover, HoverCard, Select, Combobox, DropdownMenu, ContextMenu, Menubar, and CommandPalette surfaces. With motion enabled, they also scale from 98% over the fast duration (120ms by default). Dialog slides 4px instead so controls such as date cells keep their full size. Reduced motion keeps an opacity-only fade.
Dialog, Drawer, Popover, HoverCard, CommandPalette, and DatePicker surfaces (and the Dialog, Drawer, and CommandPalette backdrops) also animate out. On close, the headless part switches the surface to data-state="closed" and GhostPresence keeps it mounted only while its own CSS transition runs. The theme's [data-state='closed'] rules mirror the entry and are never slower than it, over --ghost-motion-exit-duration with --ghost-motion-exit-easing:
| Surface | Exit |
|---|---|
| Dialog, DatePicker | Fade out and slide back 4px |
| Drawer | Fade out and slide to its anchored edge |
| Popover, HoverCard, CommandPalette | Fade out and scale to 98% |
| Dialog, Drawer, CommandPalette scrim | Fade out |
Under reduced motion, exits fade over --ghost-motion-fade-duration with no travel or scale. Focus, Escape, scroll lock, and background inert release the moment an overlay closes; the departing surface is inert and ignores the pointer while it fades. With --ghost-motion-intensity: 0 (or no theme), the exit has no duration and the surface unmounts in the same frame.
Intensity
.quiet-panel {
--ghost-motion-intensity: 0.5;
}Every duration on that subtree, including nested springs, halves. 0 freezes interpolation; state changes remain in the end values.
Live readings
A value that changes many times a second, such as an input level, needs the same motion rules plus a readable status, a pause, and a way to stop work nobody can see. This example uses app-supplied samples from a seeded test signal, so you can try it without a microphone. Move the slider to change the input.
A test-signal slider drives a pausable level meter with a hysteresis status that respects reduced motion and motion intensity.
- Status. The text says "Quiet" or "Signal detected" and is a polite status. Hysteresis keeps it steady: a quiet input must reach 30% to count as a signal, and a signal must fall below 15% to count as quiet. The test signal moves up to 6% either way, which stays inside that gap. The meter (
role="meter") is named "Input level", and its value text includes the status. - Motion. The fill scales over
--ghost-motion-duration-fastwith--ghost-motion-easing-standard, so--ghost-motion-intensityon any ancestor scales it. Underprefers-reduced-motion: reduce, or with intensity0, the bar stays still and moves only when the status changes. The status text still updates. - Pause. Pause keeps the last reading on the bar and in the text, marked "Paused". The input is still sampled, so Resume shows the current input immediately. The button keeps focus while its name changes between Pause and Resume.
- Visibility and cleanup. When the meter is offscreen or the tab is hidden, the example cancels its sample subscription and any pending frame, then subscribes again when the meter is visible. A user's pause stays in effect after that. Unmounting removes the sample timer, frame callback, intersection observer, and visibility and reduced-motion listeners. The server render uses the slider's default level, so hydration starts from the same reading.
Sample rate and frame time
The test signal emits one sample every 50 ms (20 per second) from the fixed seed 0x5eed, so the sequence of fluctuations is the same on every run. Samples that arrive within one frame are combined, so the bar repaints at most once per frame and only after a new sample. The fill changes transform, so a repaint does not trigger layout.
To check sample rate and frame time, build the docs and playground, then run the browser checks:
pnpm --filter @ghostvue/playground build
NODE_OPTIONS=--max-old-space-size=6144 pnpm docs:build
pnpm exec playwright test tests/e2e/docs-input-level-meter.spec.ts -g "sample rate|frame time"With a paused page clock, the test checks that one second produces 20 samples and no more than 20 frame callbacks. It also checks that the median interval between real animation frames stays under 20 ms while the meter updates. To profile by hand, open /examples.html?id=slider/input-level-meter in the playground. Record five seconds in the browser's performance panel and confirm the meter's frame work does not include layout.
Live demos
These reuse data-motion timing functions. Travel, duration, and replay are demo-local so easing can be compared across the full track — production recipes still move 4.5rem in 120–1204ms. Replay remounts every row together. The first run waits until the board is on screen.
Reduced motion is on. Dots fade in place instead of traveling, so this demo is not broken.
Theme crossfade helper
startThemeTransition is a small optional export from @ghostvue/themes. It sets data-ghost-mode inside document.startViewTransition when that API exists and the user has not requested reduced motion. Otherwise it writes the attribute immediately.
import { startThemeTransition } from '@ghostvue/themes'
await startThemeTransition(document.querySelector('.ghost-theme'), 'dark')Nested mode on this card.
Playground
The playground Motion section uses the same recipes, an intensity slider, and the crossfade helper. Reduced-motion browser tests assert computed button transitions and collapsed translate/scale tokens.