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.
function useFlipList(layoutKey: unknown, options?: UseFlipListOptions): UseFlipListParameters
| Name | Type | Default | Description |
|---|---|---|---|
| layoutKey | unknown | Changes whenever the rows may have moved (their ids in order, folded groups). | |
| options? | UseFlipListOptions | {} | See |
Returns
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.
class FlipSnapshot extends Component<FlipSnapshotProps>Constructor
new FlipSnapshot(props: FlipSnapshotProps)Creates the wrapper.
Parameters
| Name | Type | Description |
|---|---|---|
| props | FlipSnapshotProps |
|
Returns
Methods
componentDidUpdate()
componentDidUpdate(): voidCalled immediately after updating occurs. Not called for the initial render.
The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
getSnapshotBeforeUpdate()
getSnapshotBeforeUpdate(prev: Readonly<FlipSnapshotProps>): nullRecords the rows when the layout key changes, before React moves them.
Parameters
| Name | Type | Description |
|---|---|---|
| prev | Readonly<FlipSnapshotProps> | The props of the commit before. |
Returns
nullNothing: React needs a value.
render()
render(): ReactNodeThe rows, as given.
Returns
ReactNodeInterfaces#
FlipPlanInterface#
How a commit's changes play: UseFlipListOptions' animate and mode.
interface FlipPlanProperties
| Name | Type | Description |
|---|---|---|
| animate | boolean | Animate this commit's changes. False records only (a group folding, a search). |
| mode | FlipMode | How this commit's changes play ( |
UseFlipListInterface#
What useFlipList returns.
interface UseFlipListProperties
| Name | Type | Description |
|---|---|---|
| controller | { readonly current: FlipList | null } | The live controller, to |
| ref | (el: HTMLElement | null) => void | (() => void) | The ref callback for the list element. |
UseFlipListOptionsInterface#
Options of useFlipList.
interface UseFlipListOptions extends FlipListOptionsProperties
| Name | Type | Description |
|---|---|---|
| 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 |
keyOf?from FlipListOptions | (el: HTMLElement) => string | null | A row's key, or null to skip it. Default: its |
maxChanges?from FlipListOptions | number | Past this many rows entering or leaving in one update, nothing animates. Default 40. |
maxTravel?from FlipListOptions | number | The most a row travels on enter or exit, in px. Default 40. |
| mode? | FlipMode | How this commit's changes play ( |
| plan? | () => FlipPlan | Decides |
prefs?from FlipListOptions | () => MotionPrefs | The motion switches. Default: read off |
selector?from FlipListOptions | string | The rows to track. Default |