motion/springs
import { … } from 'zidane-ui'ui/src/motion/springs.ts
Functions#
applyMotionVarsFunction#
Write the motion switches and every --zg-motion-* / --zg-panel-* var
on root (usually <html>): what an app calls when its motion settings
change, so it never copies the curves. Returns the vars written.
function applyMotionVars(
root: HTMLElement,
prefs: MotionPrefs,
options?: ApplyMotionOptions,
): Record<string, string>Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| root | HTMLElement | The element to write to, usually | |
| prefs | MotionPrefs | The motion level and spring switch to apply. | |
| options? | ApplyMotionOptions | {} | See |
Returns
Record<string, string>cssMotionVarsFunction#
--zg-motion-<name>-duration / -ease for every motion and for hover,
for CSS that stays CSS. Below full, movement is 0ms; fades stay a brief
tween under reduced; off zeroes everything.
function cssMotionVars(prefs: MotionPrefs): Record<string, string>Parameters
| Name | Type | Description |
|---|---|---|
| prefs | MotionPrefs | The live motion level and spring switch. |
Returns
Record<string, string>A map of custom property names to values.
currentMotionPrefsFunction#
Both switches, read off <html> for imperative code.
function currentMotionPrefs(): MotionPrefsReturns
currentMotionTransitionFunction#
Non-hook read for imperative animations (animate(), scroll glides).
function currentMotionTransition(name: MotionName, visualDuration?: number): TransitionParameters
| Name | Type | Description |
|---|---|---|
| name | MotionName | The motion to resolve. |
| visualDuration? | number | Overrides the motion's duration, in seconds, for example from the panel slider. A value of 0 or less is instant. |
Returns
TransitioncurrentWithFadeFunction#
Non-hook withFade, for animate() calls that move and fade one element.
function currentWithFade(name: MotionName, visualDuration?: number): TransitionParameters
| Name | Type | Description |
|---|---|---|
| name | MotionName | The movement motion to use. |
| visualDuration? | number | Overrides the motion's duration, in seconds, for example from the panel slider. A value of 0 or less is instant. |
Returns
TransitionfadeTransitionFunction#
The fade curve for opacity / colour: fade, or fade-out for an exit.
function fadeTransition(prefs: MotionPrefs, exit?: boolean): TransitionParameters
| Name | Type | Default | Description |
|---|---|---|---|
| prefs | MotionPrefs | The live motion level and spring switch. | |
| exit? | boolean | false | Use the leaving curve, |
Returns
TransitionThe transition for opacity and colour.
menuTransitionFunction#
A menu's open (menu) or close (menu-exit) transition: one tween for
scale / position, with the enter's opacity on the same curve but shorter
(MENU_FADE_RATIO) so the surface is solid before it finishes growing.
Reduced: an opacity-only 80ms tween (pair it with no transform). Off: instant.
function menuTransition(prefs: MotionPrefs, exit?: boolean): TransitionParameters
| Name | Type | Default | Description |
|---|---|---|---|
| prefs | MotionPrefs | The live motion level and spring switch. | |
| exit? | boolean | false | Use the close transition, |
Returns
TransitionThe transition for a menu's scale and position, with a shorter opacity curve on enter.
motionTransitionFunction#
The motion transition for name under prefs. visualDuration overrides
the spec's duration (seconds; the panel slider), scaling the tween too.
function motionTransition(
name: MotionName,
prefs: MotionPrefs,
visualDuration?: number,
): TransitionParameters
| Name | Type | Description |
|---|---|---|
| name | MotionName | The motion to resolve. |
| prefs | MotionPrefs | The live motion level and spring switch. |
| visualDuration? | number | Overrides the motion's duration, in seconds, for example from the panel slider. A value of 0 or less is instant. |
Returns
TransitionA motion transition: instant when off, a short fade when reduced, otherwise a spring
or tween.
motionVarsFunction#
Every motion custom property for prefs: the named curves, hover and the panels.
function motionVars(prefs: MotionPrefs, panelMs?: number): Record<string, string>Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| prefs | MotionPrefs | The live motion level and spring switch. | |
| panelMs? | number | DEFAULT_PANEL_MS | The panel spring's perceived duration, in ms. |
Returns
Record<string, string>A map of custom property names to values.
panelMotionVarsFunction#
--zg-panel-ms / --zg-panel-ease for the layout panels (sidebar, side
panel, terminal drawer, tree column). They animate width / height in CSS
(a JS tween would re-lay out the chat column every frame), on the panel
spring sized by the user's slider: panelMs is the spring's perceived
duration; --zg-panel-ms becomes its settle time, which is also what
usePresence (readPanelMs) waits before unmounting a closed panel.
function panelMotionVars(panelMs: number, prefs: MotionPrefs): Record<string, string>Parameters
| Name | Type | Description |
|---|---|---|
| panelMs | number | The panel spring's perceived duration, in ms. Zero or less makes panels instant. |
| prefs | MotionPrefs | The live motion level and spring switch. |
Returns
Record<string, string>--zg-panel-ms and --zg-panel-ease.
useMenuTransitionFunction#
menuTransition under the live preferences.
function useMenuTransition(exit?: boolean): TransitionParameters
| Name | Type | Default | Description |
|---|---|---|---|
| exit? | boolean | false | Use the close transition instead of the open one. |
Returns
TransitionuseMotionPrefsFunction#
Both switches, live.
function useMotionPrefs(): MotionPrefsReturns
useMotionTransitionFunction#
motionTransition(name) under the live preferences.
function useMotionTransition(name: MotionName, visualDuration?: number): TransitionParameters
| Name | Type | Description |
|---|---|---|
| name | MotionName | The motion to resolve. |
| visualDuration? | number | Overrides the motion's duration, in seconds, for example from the panel slider. A value of 0 or less is instant. |
Returns
TransitionuseSpringsFunction#
Spring animations on (html[data-springs] is not off).
function useSprings(): booleanReturns
booleanuseTabExitFunction#
A closing tab's exit, for every tab strip (tabs in an AnimatePresence initial={false}):
it folds to nothing on settle as it fades out, so the tabs after it flow left from where
they were. None with motion reduced or off: the tab goes at once and the rest close up.
function useTabExit(): TargetAndTransition | undefinedReturns
TargetAndTransition | undefineduseWithFadeFunction#
withFade(name) under the live preferences.
function useWithFade(name: MotionName, visualDuration?: number): TransitionParameters
| Name | Type | Description |
|---|---|---|
| name | MotionName | The movement motion to use. |
| visualDuration? | number | Overrides the motion's duration, in seconds, for example from the panel slider. A value of 0 or less is instant. |
Returns
TransitionwithFadeFunction#
name's transition for movement, with every FADE_KEYS value on the
fade curve (fade-out when name is an exit): spring the transform,
fade the opacity. Pass it as a motion component's transition.
function withFade(
name: MotionName,
prefs: MotionPrefs,
visualDuration?: number,
): TransitionParameters
| Name | Type | Description |
|---|---|---|
| name | MotionName | The movement motion to use. |
| prefs | MotionPrefs | The live motion level and spring switch. |
| visualDuration? | number | Overrides the motion's duration, in seconds, for example from the panel slider. A value of 0 or less is instant. |
Returns
TransitionThe movement transition with opacity and colour keys on the fade curve.
Constants#
DEFAULT_PANEL_MSConstant#
The panel slider's default (ms): the panel spring's perceived duration.
const DEFAULT_PANEL_MS = 200FADE_KEYSConstant#
The values withFade puts on the fade curve: never sprung, whatever moves around them.
const FADE_KEYS: readonly ['opacity', 'color', 'backgroundColor', 'borderColor', 'fill', 'stroke', 'filter', 'backdropFilter']HOVER_MOTIONConstant#
Hover / press colour feedback: one short tween, the same with springs on or off.
const HOVER_MOTION: { duration: number; ease: readonly [0.4, 0, 0.2, 1] }INSTANTConstant#
Instant: what every motion resolves to with motion off.
const INSTANT: TransitionMENU_FADE_RATIOConstant#
A menu's enter opacity lands ahead of its scale: ~100ms of the 140ms menu.
const MENU_FADE_RATIO = 0.7MOTION_NAMESConstant#
Every MotionName, in the order of MOTIONS.
const MOTION_NAMES: MotionName[]MOTIONSConstant#
The curve of every MotionName: its spring (when it has one), tween duration in
seconds and easing.
const MOTIONS: Readonly<Record<MotionName, MotionSpec>>REDUCED_FADEConstant#
Reduced motion: a short fade; transforms jump (MotionConfig reducedMotion).
const REDUCED_FADE: TransitionInterfaces#
ApplyMotionOptionsInterface#
Options of applyMotionVars.
interface ApplyMotionOptionsProperties
| Name | Type | Description |
|---|---|---|
| attributes? | boolean | Also write |
| panelMs? | number | The panel slider (ms). Default |
MotionPrefsInterface#
The two switches that pick what plays: the motion level and whether movement springs.
interface MotionPrefsProperties
| Name | Type | Description |
|---|---|---|
| level | MotionLevel | Motion level. |
| springs | boolean | Whether movement uses springs. When off, it uses the tween twins. |
Types#
MotionNameType#
Name of a motion in the design system's vocabulary. snap, pop, panel, slide and
settle are movement that springs; exit is a fast straight exit; fade and fade-out are
the opacity curves for entering and leaving; menu and menu-exit are the menu tweens.
type MotionName =
| 'snap'
| 'pop'
| 'panel'
| 'slide'
| 'settle'
| 'exit'
| 'fade'
| 'fade-out'
| 'menu'
| 'menu-exit'