# motion/flip-list (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/motion/flip-list.ts](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts).

## Functions

### `createFlipList`

Function.

Create a FLIP controller for `container` (the scrolling list element; it must be positioned,
as the stand-ins are placed in it).

```ts
function createFlipList(container: HTMLElement, options?: FlipListOptions): FlipList
```

**Parameters**

- `container` (`HTMLElement`): The list element whose rows to animate.
- `options?` (`FlipListOptions`, default `{}`): See [`FlipListOptions`](https://zidane.si/docs/reference/ui-motion-flip-list.md#FlipListOptions).

**Returns** `FlipList`

Source: [ui/src/motion/flip-list.ts:169](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts#L169)

## Constants

### `FLIP_CLIP_ATTR`

Constant.

Put on a box that clips its rows (a fold): a row leaving it for another flies over both, as between scroll areas.

```ts
const FLIP_CLIP_ATTR = 'data-flip-clip'
```

Source: [ui/src/motion/flip-list.ts:44](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts#L44)

## Interfaces

### `FlipLanding`

Interface.

The row a drag carried, landing: see `FlipList.release`.

```ts
interface FlipLanding
```

**Properties**

- `className` (`string`): The class that makes a row look lifted; removed a frame into the landing.
- `from` (`HTMLElement`): The dragged row's element when the drag ends (its key says which row lands).

Source: [ui/src/motion/flip-list.ts:76](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts#L76)

### `FlipList`

Interface.

A FLIP controller over one list element.

```ts
interface FlipList
```

**Properties**

- `dispose` (`() => void`): Stop every animation and remove the stand-ins.
- `recordLater` (`() => void`): Drop the record and take a new one once the list has painted: a commit with nothing to show (no measure in its frame).
- `release` (`(prepare?: () => void, landing?: FlipLanding) => void`): Resume after `suspend`, recording where the rows show now, so the next update glides them from there.
  `prepare` (a drag's: drop its transforms) runs right before that update measures, so no frame paints the
  rows at their old places in between. With no commit by the next frame, the update runs then on its own.
  `landing`: the row the drag carried (`from`, its element then), still lifted (`className`, the look of a
  dragged row): whatever carries it in that update (the row, or the copy flying it) starts with that class,
  which goes the next frame, so the row settles from lifted to resting by its own CSS transition.
- `snapshot` (`(mode?: FlipMode) => void`): Record the rows where they are now: right before a commit changes them (`FlipSnapshot`), so the next
  update starts each glide from where its row really was, whatever moved it since the last update.
  Skipped while a drag's release waits for its update (that record is the drag's). `swap`: the commit
  shows another view; an image of the list is taken too, for the update's fade-through.
- `suspend` (`() => void`): Stop animating (a drag moves the rows itself); updates only record until `release`.
- `update` (`(animate?: boolean, mode?: FlipMode) => void`): Measure the rows after a commit and animate what changed (`animate: false` only records). With nothing
  recorded yet (a list that just mounted), an animated update records once the list has painted instead.

Source: [ui/src/motion/flip-list.ts:84](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts#L84)

### `FlipListOptions`

Interface.

Options of [`createFlipList`](https://zidane.si/docs/reference/ui-motion-flip-list.md#createFlipList).

```ts
interface FlipListOptions
```

**Properties**

- `isSticky?` (`(el: HTMLElement) => boolean`): A sticky header, measured at its unstuck place. Default: it carries `data-flip-sticky`.
- `keyOf?` (`(el: HTMLElement) => string | null`): A row's key, or null to skip it. Default: its `data-flip-key`.
- `maxChanges?` (`number`): Past this many rows entering or leaving in one update, nothing animates. Default 40.
- `maxTravel?` (`number`): The most a row travels on enter or exit, in px. Default 40.
- `prefs?` (`() => MotionPrefs`): The motion switches. Default: read off `<html>`.
- `selector?` (`string`): The rows to track. Default `[data-flip-key]`.

Source: [ui/src/motion/flip-list.ts:54](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts#L54)

## Types

### `FlipMode`

Type.

How an update plays: a list that changed (rows travel with their neighbours), a group folding around rows
that stay, or a swap of what the list shows (a layout, a grouping, a filter: the whole list fades through).

```ts
type FlipMode = 'list' | 'fold' | 'swap'
```

Source: [ui/src/motion/flip-list.ts:73](https://github.com/Tahul/zidane/blob/main/ui/src/motion/flip-list.ts#L73)
