Skip to content

motion/presence

import { … } from 'zidane-ui'ui/src/motion/presence.ts

Functions#

readDurationVarFunction#

A duration custom property (200ms, 0.2s) in milliseconds; 0 when unset.

TypeScript
function readDurationVar(name: string, root?: HTMLElement): number
Parameters
NameTypeDefaultDescription
namestring

The custom property, such as --zg-panel-ms.

root?HTMLElementdocument.documentElement

The element to read it from. Defaults to document.documentElement.

number

ui/src/motion/presence.ts:56

readExitMsFunction#

How long a CSS exit plays: the longer of exit (transform) and fade-out (opacity). 0 under off; the brief fade under reduced. What an exitMs waiting on an exit / fade-out animation passes.

TypeScript
function readExitMs(): number
number

ui/src/motion/presence.ts:78

readMenuExitMsFunction#

How long a menu's close plays (menu-exit, opacity and transform alike): what a menu's exitMs passes.

TypeScript
function readMenuExitMs(): number
number

ui/src/motion/presence.ts:81

readMotionMsFunction#

A named motion's CSS duration (--zg-motion-<name>-duration, motion/springs.ts) in ms.

TypeScript
function readMotionMs(name: string): number
Parameters
NameTypeDescription
namestring

The motion name, such as settle or exit.

number

ui/src/motion/presence.ts:71

readPanelMsFunction#

The panel open / close duration token (zeroed by reduced / off motion).

TypeScript
function readPanelMs(): number
number

ui/src/motion/presence.ts:64

transitionStateFunction#

open / closed for [data-state] transitions: everything but open shows the closed look.

TypeScript
function transitionState(state: PresenceState): 'open' | 'closed'
Parameters
NameTypeDescription
statePresenceState

The phase from usePresence.

'open' | 'closed'

ui/src/motion/presence.ts:88

usePresenceFunction#

Keeps a node mounted around a CSS transition. It is mounted on the render that opens it, then goes entering, open, closing for exitMs and closed. A zero exitMs closes at once, as reduced and off motion want.

TypeScript
function usePresence(open: boolean, options?: PresenceOptions): Presence
Parameters
NameTypeDefaultDescription
openboolean

Whether the node should be open.

options?PresenceOptions{}

Whether to mount closed and transition in (enter), and how long the exit lasts (exitMs, in ms or a function read when the close starts), and whose node it is (key).

ui/src/motion/presence.ts:99

useScrollLockFunction#

Locks page scroll while active (menus, dialogs). Counted: with layers stacked, the page stays locked until the last one lets go, whatever order they close in, and gets back the styles it had before the first.

TypeScript
function useScrollLock(active: boolean): void
Parameters
NameTypeDescription
activeboolean

Whether to lock the page scroll.

ui/src/motion/presence.ts:185

Interfaces#

PresenceInterface#

What usePresence returns.

TypeScript
interface Presence
Presence properties
NameTypeDescription
mountedboolean

Whether the node should be in the tree: true from the render that opens it until its exit finishes.

statePresenceState

The current phase. Map it with transitionState to a data-state value.

ui/src/motion/presence.ts:30

PresenceOptionsInterface#

Options of usePresence.

TypeScript
interface PresenceOptions
PresenceOptions properties
NameTypeDescription
enter?boolean

Mount closed and transition in. Default false.

exitMs?number | (() => number)

How long closing lasts. Default 0.

key?string | null

Whose node it is (a scope's key). A change shows the new state at once: no enter, no exit.

ui/src/motion/presence.ts:41

Types#

PresenceStateType#

Phase of a usePresence transition: entering (mounted in its closed look, for two frames), open, closing (playing its exit) or closed (unmounted).

TypeScript
type PresenceState = 'entering' | 'open' | 'closing' | 'closed'

ui/src/motion/presence.ts:27