Layout Animations
The 10 effects L01–L10: purpose, API, options, examples, reduced motion and cost.
Experimental and not on npm
Layout animations measure layout boxes once before a change and once in the next read phase, then animate a transform back to the real position (FLIP). Nothing is measured per frame, and text is not distorted unless you ask for layout: "size". <Presence> keeps a removed child mounted, inert and hidden from assistive technology, only until its exit ends; a watchdog removes it if an animation never completes.
L01 · FLIP move
Wrap the list in <LayoutGroup> and each item in <LayoutItem>; when an update changes their boxes they move from the old position. Without React, createLayoutGroup() with snapshot() and play() does the same for flipMove.
- Import
@neshel-ui/animations/layout- API
LayoutGroup, LayoutItem, useLayoutItem, flipMove, createLayoutGroup- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Reads layout boxes once before and once after the change, then animates transforms (FLIP).
Loading the example…
"use client";
import { LayoutGroup, LayoutItem } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function L01Example() {
const [order, setOrder] = useState(["A", "B", "C", "D"]);
return (
<div className="grid justify-items-start gap-3">
<LayoutGroup>
<ul className="flex gap-2">
{order.map((item) => (
<LayoutItem key={item} asChild>
<li className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground">
{item}
</li>
</LayoutItem>
))}
</ul>
</LayoutGroup>
<Button
variant="outline"
onClick={() => setOrder(([head, ...rest]) => [...rest, head as string])}
>
Rotate
</Button>
</div>
);
}Options: FlipMoveOptions
FlipMoveOptions
L01 — FLIP move / reorder (and L04 shared layout with a layoutId).
| Prop | Type | Default | Description |
|---|---|---|---|
| group | LayoutGroup | — | The group whose snapshot/play cycle animates this element (createLayoutGroup(); <LayoutGroup>). |
| layout | LayoutMode | "position" | What is animated (default "position"; "size"/"both" add a non-uniform scale). |
| reducedMotion | ReducedMotion | — | — |
| transition | LayoutTransition | — | — |
L02 · Auto height
<AutoHeight> follows the observed height of its content, including text that grows or asynchronous content. It expects to size to its content: do not stretch it with a grid or flex parent.
- Import
@neshel-ui/animations/layout- API
AutoHeight, autoHeight- Stylesheet
@neshel-ui/animations/layout.css- Reduced motion
instant— the end state appears at once- Performance
- Animates a height, so the content below reflows while it runs; avoid it above very long pages.
Line 1
"use client";
import "@neshel-ui/animations/layout.css";
import { AutoHeight } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function L02Example() {
const [lines, setLines] = useState(1);
return (
<div className="grid max-w-sm gap-3">
<AutoHeight className="rounded-xl border border-neshel-border px-4">
{Array.from({ length: lines }, (_, index) => (
<p key={index} className="py-2">
Line {index + 1}
</p>
))}
</AutoHeight>
<Button variant="outline" onClick={() => setLines(lines === 4 ? 1 : lines + 1)}>
Change the content
</Button>
</div>
);
}Options: AutoHeightOptions
AutoHeightOptions
L02 — Auto-height: the element's height follows its content's observed height.
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | DurationPreset | 280 | ms or preset (default 280). |
| easing | Easing | EasingPreset | — | — |
| reducedMotion | ReducedMotion | — | — |
L03 · List enter and exit
<AnimatedList> combines presence and FLIP: items enter and exit with listItem (or your enter and exit presets) while their siblings move into place. Give every item a stable key.
- Import
@neshel-ui/animations/layout- API
AnimatedList, listItem- Stylesheet
- none needed
- Reduced motion
fade— opacity only, no travel- Performance
- Reads layout boxes once before and once after the change, then animates transforms (FLIP).
Loading the example…
"use client";
import { AnimatedList } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function L03Example() {
const [items, setItems] = useState([1, 2, 3]);
return (
<div className="grid max-w-sm gap-3">
<AnimatedList className="grid gap-2">
{items.map((item) => (
<li key={item} className="rounded-lg bg-neshel-muted p-3">
Item {item}
</li>
))}
</AnimatedList>
<div className="flex gap-2">
<Button variant="outline" onClick={() => setItems([Math.max(0, ...items) + 1, ...items])}>
Add
</Button>
<Button variant="outline" onClick={() => setItems(items.slice(1))}>
Remove first
</Button>
</div>
</div>
);
}Options: ListItemOptions
ListItemOptions
L03 — List item enter / exit (opacity, 4 % scale and 8 px offset; siblings FLIP in a group).
| Prop | Type | Default | Description |
|---|---|---|---|
| appear | boolean | — | Animate the first appearance (default true; <AnimatedList> sets false for initial items). |
| duration | number | DurationPreset | — | — |
| easing | Easing | EasingPreset | — | — |
| onExited | () => void | — | — |
| present | boolean | — | Present (enters) or leaving (exits, then onExited). Default true. |
| reducedMotion | ReducedMotion | — | — |
L04 · Shared layout
A <LayoutItem> with a layoutId that mounts where another one with the same id was animates from that box: moving highlights, cards between containers. Keep both inside one <LayoutGroup>.
- Import
@neshel-ui/animations/layout- API
LayoutItem, sharedLayout- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Reads layout boxes once before and once after the change, then animates transforms (FLIP).
Loading the example…
"use client";
import { LayoutGroup, LayoutItem } from "@neshel-ui/animations/layout";
import { useState } from "react";
export default function L04Example() {
const [selected, setSelected] = useState(0);
return (
<LayoutGroup>
<div className="flex w-fit gap-1 rounded-full bg-neshel-muted p-1">
{["Free", "Pro", "Team"].map((plan, index) => (
<button
key={plan}
type="button"
aria-pressed={selected === index}
onClick={() => setSelected(index)}
className="relative rounded-full px-5 py-2"
>
{selected === index ? (
<LayoutItem
layoutId="docs-plan"
className="absolute inset-0 rounded-full bg-neshel-surface shadow"
/>
) : null}
<span className="relative">{plan}</span>
</button>
))}
</div>
</LayoutGroup>
);
}Options: SharedLayoutOptions
L05 · Grid reflow
<Reflow> animates the children of a grid or flex container whenever it reflows — resize, column change, a child that grows — without React renders.
- Import
@neshel-ui/animations/layout- API
Reflow, gridReflow- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Reads layout boxes once before and once after the change, then animates transforms (FLIP).
Loading the example…
"use client";
import { Reflow } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function L05Example() {
const [columns, setColumns] = useState(4);
return (
<div className="grid gap-3">
<Reflow className="grid gap-2" style={{ gridTemplateColumns: `repeat(${columns}, 1fr)` }}>
{Array.from({ length: 8 }, (_, index) => (
<div key={index} className="rounded-lg bg-neshel-muted p-3 text-center">
{index + 1}
</div>
))}
</Reflow>
<Button
variant="outline"
onClick={() => setColumns(columns === 4 ? 2 : 4)}
className="justify-self-start"
>
Change columns
</Button>
</div>
);
}Options: GridReflowOptions
GridReflowOptions
L05 — Grid reflow.
| Prop | Type | Default | Description |
|---|---|---|---|
| reducedMotion | ReducedMotion | — | — |
| transition | LayoutTransition | — | — |
L06 · Accordion height
<Collapse> opens and closes a panel with open; driver chooses CSS, measured JavaScript or "auto". Wire aria-expanded and aria-controls on your button. For a complete widget use the Components Accordion or Collapsible.
- Import
@neshel-ui/animations/layout- API
Collapse, collapse- Stylesheet
@neshel-ui/animations/layout.css- Reduced motion
instant— the end state appears at once- Performance
- Animates a height, so the content below reflows while it runs; avoid it above very long pages.
Orders leave the warehouse in one working day.
"use client";
import "@neshel-ui/animations/layout.css";
import { Collapse } from "@neshel-ui/animations/layout";
import { useState } from "react";
export default function L06Example() {
const [open, setOpen] = useState(false);
return (
<div className="max-w-sm rounded-xl border border-neshel-border">
<button
type="button"
aria-expanded={open}
aria-controls="docs-l06"
onClick={() => setOpen(!open)}
className="w-full p-4 text-start"
>
Shipping
</button>
<Collapse open={open} id="docs-l06">
<p className="px-4 pb-4">Orders leave the warehouse in one working day.</p>
</Collapse>
</div>
);
}Options: CollapseOptions
CollapseOptions
L06 — Accordion height (collapse / expand a package-rendered panel).
| Prop | Type | Default | Description |
|---|---|---|---|
| driver | "auto" | "css" | "js" | — | "auto" (default): CSS interpolate-size where supported, measured WAAPI otherwise. |
| duration | number | DurationPreset | 280 | ms or preset (default 280). |
| easing | Easing | EasingPreset | — | — |
| onRequestOpen | () => void | — | Find-in-page matched hidden content: ask the consumer to open the panel. |
| open | boolean | — | Expanded state (controlled by the consumer). |
| reducedMotion | ReducedMotion | — | — |
L07 · Tab indicator
<TabIndicator> slides a package-rendered indicator to the active tab, given as an element or an index. It is decoration: your tabs keep their roles, selection state and keyboard behaviour.
- Import
@neshel-ui/animations/layout- API
TabIndicator, tabIndicator- Stylesheet
@neshel-ui/animations/layout.css- Reduced motion
instant— the end state appears at once- Performance
- The package stylesheet renders it on layers owned by the package; your element gets no transition or animation.
Loading the example…
"use client";
import "@neshel-ui/animations/layout.css";
import { TabIndicator } from "@neshel-ui/animations/layout";
import { useState } from "react";
const tabs = ["Overview", "Specs", "Reviews"];
export default function L07Example() {
const [active, setActive] = useState(0);
return (
<div>
<TabIndicator asChild active={active}>
<div
role="tablist"
aria-label="Product"
className="flex gap-1 border-b border-neshel-border text-neshel-foreground"
>
{tabs.map((tab, index) => (
<button
key={tab}
id={`docs-l07-${index}`}
type="button"
role="tab"
aria-selected={active === index}
aria-controls="docs-l07-panel"
tabIndex={active === index ? 0 : -1}
onClick={() => setActive(index)}
className="px-4 py-2"
>
{tab}
</button>
))}
</div>
</TabIndicator>
<div
role="tabpanel"
id="docs-l07-panel"
aria-labelledby={`docs-l07-${active}`}
className="p-4"
>
{tabs[active]}
</div>
</div>
);
}Options: TabIndicatorOptions
TabIndicatorOptions
L07 — Tab indicator slide (a package-rendered indicator inside the tab list).
| Prop | Type | Default | Description |
|---|---|---|---|
| active | Element | number | null | — | The active tab: an element, its index among the tabs ([role="tab"], else children), or null. |
| duration | number | DurationPreset | — | — |
| easing | Easing | EasingPreset | — | — |
| orientation | "horizontal" | "vertical" | — | — |
| reducedMotion | ReducedMotion | — | — |
L08 · Presence
<Presence> runs an exit entrance backwards before a keyed child unmounts, and enter when it arrives; removing it again mid-way continues from the current pose. usePresence and useIsPresent read the state inside.
- Import
@neshel-ui/animations/layout- API
Presence, usePresence, useIsPresent, createPresence- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
"use client";
import { fadeUp } from "@neshel-ui/animations/entrance";
import { Presence } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function L08Example() {
const [shown, setShown] = useState(true);
return (
<div className="grid min-h-36 content-start justify-items-start gap-3">
<Button variant="outline" aria-pressed={shown} onClick={() => setShown(!shown)}>
{shown ? "Remove" : "Add"}
</Button>
<Presence enter={fadeUp} exit={fadeUp}>
{shown ? (
<div
key="card"
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
The exit runs before unmounting
</div>
) : null}
</Presence>
</div>
);
}Options: PresenceProps
PresenceProps
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Keyed elements rendered without a wrapper. Each must accept a ref that reaches its DOM element (host
elements do; components must forward ref), so exiting content can be made inert and lose focus. |
| duration | number | 220 | Built-in fade duration in ms (default 220). |
| enter | AnyPreset | — | Entrance definition or preset for entering children (default: the built-in fade). |
| exit | AnyPreset | — | Entrance definition or preset for exiting children (default: the built-in fade). |
| focusFallback | RefObject<HTMLElement | null> | — | Focus target when focus was inside an exiting child and no present sibling can take it. |
| initial | boolean | — | Animate the children of the first render too (default false: server/hydrated content stays visible). |
| onExitComplete | (key: string) => void | — | Called once per removed key, after its exit. |
L09 · Content cross-fade
<CrossFade> fades between the old and new content when swapKey changes, stacked in one cell while the height follows. The old content is inert during the swap.
- Import
@neshel-ui/animations/layout- API
CrossFade, crossFade- Stylesheet
@neshel-ui/animations/layout.css- Reduced motion
instant— the end state appears at once- Performance
- Animates a height, so the content below reflows while it runs; avoid it above very long pages.
Short.
"use client";
import "@neshel-ui/animations/layout.css";
import { CrossFade } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
const slides = ["Short.", "A longer slide: the height follows the new content.", "Third slide."];
export default function L09Example() {
const [index, setIndex] = useState(0);
return (
<div className="grid max-w-sm gap-3">
<CrossFade swapKey={index} className="rounded-xl border border-neshel-border p-4">
<p>{slides[index]}</p>
</CrossFade>
<Button variant="outline" onClick={() => setIndex((index + 1) % slides.length)}>
Next
</Button>
</div>
);
}Options: CrossFadeOptions
CrossFadeOptions
L09 — Content cross-fade swap (one layer of a swap; <CrossFade> stacks two).
| Prop | Type | Default | Description |
|---|---|---|---|
| appear | boolean | — | Fade in when attached visible (default false: SSR content stays visible). |
| duration | number | DurationPreset | — | — |
| easing | Easing | EasingPreset | — | — |
| onHidden | () => void | — | Called once each time the layer has faded out. |
| reducedMotion | ReducedMotion | — | — |
| visible | boolean | — | Shown (fades in) or hidden (fades out). Default true. |
L10 · Masonry reflow
<Masonry> lays children out in columns of at least minColumnWidth with gap, using grid row spans from observed heights, and animates reflows. Visual order can differ from the DOM order across columns.
- Import
@neshel-ui/animations/layout- API
Masonry, masonry- Stylesheet
@neshel-ui/animations/layout.css- Reduced motion
instant— the end state appears at once- Performance
- Reads layout boxes once before and once after the change, then animates transforms (FLIP).
Loading the example…
"use client";
import "@neshel-ui/animations/layout.css";
import { Masonry } from "@neshel-ui/animations/layout";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function L10Example() {
const [narrow, setNarrow] = useState(false);
return (
<div className="grid gap-3">
<Masonry minColumnWidth={narrow ? 180 : 100} gap={10} style={{ maxWidth: 520 }}>
{[60, 110, 80, 140, 70, 100].map((height) => (
<div key={height} style={{ height }} className="rounded-lg bg-neshel-muted p-3">
{height} px
</div>
))}
</Masonry>
<Button variant="outline" onClick={() => setNarrow(!narrow)} className="justify-self-start">
Change the column width
</Button>
</div>
);
}Options: MasonryOptions
MasonryOptions
L10 — Masonry reflow.
| Prop | Type | Default | Description |
|---|---|---|---|
| columns | number | — | Fixed column count (1–12); omitted: as many columns of minColumnWidth as fit. |
| gap | number | — | Gap in px (0–96, default 16). |
| minColumnWidth | number | — | Minimum column width in px when columns is omitted (80–800, default 220). |
| reducedMotion | ReducedMotion | — | — |
| transition | LayoutTransition | — | — |
| unit | number | — | Row unit in px used for spans (1–32, default 4). |