Skip to content

motion/use-flip-list

import { … } from 'zidane-ui'ui/src/motion/use-flip-list.ts

Functions#

useFlipListFunction#

createFlipList on a React list: measures after every commit where layoutKey changed and animates what moved, arrived or left. Give the list element ref; a new element (a remount) starts a fresh controller.

TypeScript
function useFlipList(layoutKey: unknown, options?: UseFlipListOptions): UseFlipList
Parameters
NameTypeDefaultDescription
layoutKeyunknown

Changes whenever the rows may have moved (their ids in order, folded groups).

options?UseFlipListOptions{}

See UseFlipListOptions.

ui/src/motion/use-flip-list.ts:44

Classes#

FlipSnapshotClass#

Records the rows right before each commit changes them (getSnapshotBeforeUpdate, the one moment React offers before the DOM moves), so a glide starts where its row really was: a fold that settled, rows that grew as they painted, an area that resized since the last update all count. Wrap the list's rows in it, inside the element useFlipList's ref is on.

TypeScript
class FlipSnapshot extends Component<FlipSnapshotProps>
TypeScript
new FlipSnapshot(props: FlipSnapshotProps)

Creates the wrapper.

Parameters
NameTypeDescription
propsFlipSnapshotProps

FlipSnapshotProps.

componentDidUpdate()

TypeScript
componentDidUpdate(): void

Called immediately after updating occurs. Not called for the initial render.

The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.

getSnapshotBeforeUpdate()

TypeScript
getSnapshotBeforeUpdate(prev: Readonly<FlipSnapshotProps>): null

Records the rows when the layout key changes, before React moves them.

Parameters
NameTypeDescription
prevReadonly<FlipSnapshotProps>

The props of the commit before.

null

Nothing: React needs a value.

render()

TypeScript
render(): ReactNode

The rows, as given.

ReactNode

ui/src/motion/use-flip-list.ts:103

Interfaces#

FlipPlanInterface#

How a commit's changes play: UseFlipListOptions' animate and mode.

TypeScript
interface FlipPlan
FlipPlan properties
NameTypeDescription
animateboolean

Animate this commit's changes. False records only (a group folding, a search).

modeFlipMode

How this commit's changes play (fold: a group folding around rows that stay).

ui/src/motion/use-flip-list.ts:8

UseFlipListInterface#

What useFlipList returns.

TypeScript
interface UseFlipList
UseFlipList properties
NameTypeDescription
controller{ readonly current: FlipList | null }

The live controller, to suspend / release around a drag.

ref(el: HTMLElement | null) => void | (() => void)

The ref callback for the list element.

ui/src/motion/use-flip-list.ts:29

UseFlipListOptionsInterface#

Options of useFlipList.

TypeScript
interface UseFlipListOptions extends FlipListOptions
UseFlipListOptions properties
NameTypeDescription
animate?boolean

Animate this commit's changes. False records only (a group folding, a search). Default true.

isSticky?from FlipListOptions(el: HTMLElement) => boolean

A sticky header, measured at its unstuck place. Default: it carries data-flip-sticky.

keyOf?from FlipListOptions(el: HTMLElement) => string | null

A row's key, or null to skip it. Default: its data-flip-key.

maxChanges?from FlipListOptionsnumber

Past this many rows entering or leaving in one update, nothing animates. Default 40.

maxTravel?from FlipListOptionsnumber

The most a row travels on enter or exit, in px. Default 40.

mode?FlipMode

How this commit's changes play (fold: a group folding around rows that stay). Default list.

plan?() => FlipPlan

Decides animate and mode as the commit moves the rows, for a list that compares with its commit before (a ref no render reads). Wins over both. Give FlipSnapshot the same.

prefs?from FlipListOptions() => MotionPrefs

The motion switches. Default: read off <html>.

selector?from FlipListOptionsstring

The rows to track. Default [data-flip-key].

ui/src/motion/use-flip-list.ts:16