Skip to content

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.

TypeScript
function applyMotionVars(
  root: HTMLElement,
  prefs: MotionPrefs,
  options?: ApplyMotionOptions,
): Record<string, string>
Parameters
NameTypeDefaultDescription
rootHTMLElement

The element to write to, usually document.documentElement.

prefsMotionPrefs

The motion level and spring switch to apply.

options?ApplyMotionOptions{}

See ApplyMotionOptions.

Record<string, string>

ui/src/motion/springs.ts:297

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.

TypeScript
function cssMotionVars(prefs: MotionPrefs): Record<string, string>
Parameters
NameTypeDescription
prefsMotionPrefs

The live motion level and spring switch.

Record<string, string>

A map of custom property names to values.

ui/src/motion/springs.ts:230

currentMotionPrefsFunction#

Both switches, read off <html> for imperative code.

TypeScript
function currentMotionPrefs(): MotionPrefs

ui/src/motion/springs.ts:388

currentMotionTransitionFunction#

Non-hook read for imperative animations (animate(), scroll glides).

TypeScript
function currentMotionTransition(name: MotionName, visualDuration?: number): Transition
Parameters
NameTypeDescription
nameMotionName

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.

Transition

ui/src/motion/springs.ts:400

currentWithFadeFunction#

Non-hook withFade, for animate() calls that move and fade one element.

TypeScript
function currentWithFade(name: MotionName, visualDuration?: number): Transition
Parameters
NameTypeDescription
nameMotionName

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.

Transition

ui/src/motion/springs.ts:411

fadeTransitionFunction#

The fade curve for opacity / colour: fade, or fade-out for an exit.

TypeScript
function fadeTransition(prefs: MotionPrefs, exit?: boolean): Transition
Parameters
NameTypeDefaultDescription
prefsMotionPrefs

The live motion level and spring switch.

exit?booleanfalse

Use the leaving curve, fade-out, instead of fade.

Transition

The transition for opacity and colour.

ui/src/motion/springs.ts:175

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.

TypeScript
function menuTransition(prefs: MotionPrefs, exit?: boolean): Transition
Parameters
NameTypeDefaultDescription
prefsMotionPrefs

The live motion level and spring switch.

exit?booleanfalse

Use the close transition, menu-exit, instead of menu.

Transition

The transition for a menu's scale and position, with a shorter opacity curve on enter.

ui/src/motion/springs.ts:189

motionTransitionFunction#

The motion transition for name under prefs. visualDuration overrides the spec's duration (seconds; the panel slider), scaling the tween too.

TypeScript
function motionTransition(
  name: MotionName,
  prefs: MotionPrefs,
  visualDuration?: number,
): Transition
Parameters
NameTypeDescription
nameMotionName

The motion to resolve.

prefsMotionPrefs

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.

Transition

A motion transition: instant when off, a short fade when reduced, otherwise a spring or tween.

ui/src/motion/springs.ts:156

motionVarsFunction#

Every motion custom property for prefs: the named curves, hover and the panels.

TypeScript
function motionVars(prefs: MotionPrefs, panelMs?: number): Record<string, string>
Parameters
NameTypeDefaultDescription
prefsMotionPrefs

The live motion level and spring switch.

panelMs?numberDEFAULT_PANEL_MS

The panel spring's perceived duration, in ms.

Record<string, string>

A map of custom property names to values.

ui/src/motion/springs.ts:276

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.

TypeScript
function panelMotionVars(panelMs: number, prefs: MotionPrefs): Record<string, string>
Parameters
NameTypeDescription
panelMsnumber

The panel spring's perceived duration, in ms. Zero or less makes panels instant.

prefsMotionPrefs

The live motion level and spring switch.

Record<string, string>

--zg-panel-ms and --zg-panel-ease.

ui/src/motion/springs.ts:262

useMenuTransitionFunction#

menuTransition under the live preferences.

TypeScript
function useMenuTransition(exit?: boolean): Transition
Parameters
NameTypeDefaultDescription
exit?booleanfalse

Use the close transition instead of the open one.

Transition

ui/src/motion/springs.ts:355

useMotionPrefsFunction#

Both switches, live.

TypeScript
function useMotionPrefs(): MotionPrefs

ui/src/motion/springs.ts:335

useMotionTransitionFunction#

motionTransition(name) under the live preferences.

TypeScript
function useMotionTransition(name: MotionName, visualDuration?: number): Transition
Parameters
NameTypeDescription
nameMotionName

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.

Transition

ui/src/motion/springs.ts:346

useSpringsFunction#

Spring animations on (html[data-springs] is not off).

TypeScript
function useSprings(): boolean
boolean

ui/src/motion/springs.ts:330

useTabExitFunction#

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.

TypeScript
function useTabExit(): TargetAndTransition | undefined
TargetAndTransition | undefined

ui/src/motion/springs.ts:375

useWithFadeFunction#

withFade(name) under the live preferences.

TypeScript
function useWithFade(name: MotionName, visualDuration?: number): Transition
Parameters
NameTypeDescription
nameMotionName

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.

Transition

ui/src/motion/springs.ts:366

withFadeFunction#

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.

TypeScript
function withFade(
  name: MotionName,
  prefs: MotionPrefs,
  visualDuration?: number,
): Transition
Parameters
NameTypeDescription
nameMotionName

The movement motion to use.

prefsMotionPrefs

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.

Transition

The movement transition with opacity and colour keys on the fade curve.

ui/src/motion/springs.ts:206

Constants#

DEFAULT_PANEL_MSConstant#

The panel slider's default (ms): the panel spring's perceived duration.

TypeScript
const DEFAULT_PANEL_MS = 200

ui/src/motion/springs.ts:115

FADE_KEYSConstant#

The values withFade puts on the fade curve: never sprung, whatever moves around them.

TypeScript
const FADE_KEYS: readonly ['opacity', 'color', 'backgroundColor', 'borderColor', 'fill', 'stroke', 'filter', 'backdropFilter']

ui/src/motion/springs.ts:132

HOVER_MOTIONConstant#

Hover / press colour feedback: one short tween, the same with springs on or off.

TypeScript
const HOVER_MOTION: { duration: number; ease: readonly [0.4, 0, 0.2, 1] }

ui/src/motion/springs.ts:112

INSTANTConstant#

Instant: what every motion resolves to with motion off.

TypeScript
const INSTANT: Transition

ui/src/motion/springs.ts:126

A menu's enter opacity lands ahead of its scale: ~100ms of the 140ms menu.

TypeScript
const MENU_FADE_RATIO = 0.7

ui/src/motion/springs.ts:106

MOTION_NAMESConstant#

Every MotionName, in the order of MOTIONS.

TypeScript
const MOTION_NAMES: MotionName[]

ui/src/motion/springs.ts:109

MOTIONSConstant#

The curve of every MotionName: its spring (when it has one), tween duration in seconds and easing.

TypeScript
const MOTIONS: Readonly<Record<MotionName, MotionSpec>>

ui/src/motion/springs.ts:92

REDUCED_FADEConstant#

Reduced motion: a short fade; transforms jump (MotionConfig reducedMotion).

TypeScript
const REDUCED_FADE: Transition

ui/src/motion/springs.ts:129

Interfaces#

ApplyMotionOptionsInterface#

Options of applyMotionVars.

TypeScript
interface ApplyMotionOptions
ApplyMotionOptions properties
NameTypeDescription
attributes?boolean

Also write data-motion / data-springs. Default true; false when the attributes are the input.

panelMs?number

The panel slider (ms). Default DEFAULT_PANEL_MS.

ui/src/motion/springs.ts:281

MotionPrefsInterface#

The two switches that pick what plays: the motion level and whether movement springs.

TypeScript
interface MotionPrefs
MotionPrefs properties
NameTypeDescription
levelMotionLevel

Motion level. off is instant, reduced keeps brief fades, full plays all motion.

springsboolean

Whether movement uses springs. When off, it uses the tween twins.

ui/src/motion/springs.ts:118

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.

TypeScript
type MotionName =
  | 'snap'
  | 'pop'
  | 'panel'
  | 'slide'
  | 'settle'
  | 'exit'
  | 'fade'
  | 'fade-out'
  | 'menu'
  | 'menu-exit'

ui/src/motion/springs.ts:64