A grid of dots that plays frame-by-frame animations, for loading and status indicators.
Installation
Usage
import {
MotionGrid,
MotionGridCells,
type Frames,
} from '@animate-ui/react/primitives/motion-grid';
// Each frame lists the active cells as [column, row].
const frames: Frames = [
[[1, 1]],
[
[0, 1],
[1, 0],
[1, 2],
[2, 1],
],
[
[0, 0],
[0, 2],
[2, 0],
[2, 2],
],
[],
];
export function Loader() {
return (
<MotionGrid gridSize={[3, 3]} frames={frames} className="gap-0.5">
<MotionGridCells className="size-1 rounded-full bg-foreground/20 data-[active=true]:bg-foreground" />
</MotionGrid>
);
}Active cells have data-active="true": style them with it, or pass activeProps and inactiveProps.
Animation
- The grid shows one frame every
durationmilliseconds, looping. - Cells change with your own CSS transitions or Motion props (
activeProps). Motion props takedurationwith an ease-in-out; CSS transitions keep their own timing. - The loop pauses while the grid is off screen or the tab is hidden.
API Reference
MotionGrid
| Prop | Type | Default |
|---|---|---|
asChild? | boolean | false |
gridSize | [number, number] | - |
frames | [number, number][][] | - |
duration? | number | 200 |
animate? | boolean | true |
...props? | HTMLMotionProps<'div'> | - |
MotionGridCells
Renders every cell of the grid.
| Prop | Type | Default |
|---|---|---|
activeProps? | HTMLMotionProps<'div'> | - |
inactiveProps? | HTMLMotionProps<'div'> | - |
...props? | HTMLMotionProps<'div'> | - |
Credits
- Inspired by Adrien Griveau's post.