Motion Grid

A frame-based 2D grid animation primitive with active/inactive cell states.

motion-sv

Installation

pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/motion-grid.json

Usage

<script lang="ts">	import { MotionGrid, MotionGridCells, type Frames } from "#lib/components/magic/motion-grid/index.js";
	const frames: Frames = [		[[0, 0], [1, 1]],		[[1, 0], [0, 1]],	];</script>
<MotionGrid gridSize={[2, 2]} {frames} class="w-12 gap-1">	<MotionGridCells class="aspect-square rounded-full bg-muted data-[active=true]:bg-primary" /></MotionGrid>

Examples

Manual State Switcher

Importing

Custom Cell Props

Use activeProps and inactiveProps to style and animate cell states without changing frame data.

Child Render Prop

This uses the child render-prop to customize the outer wrapper.

Props

Motion Grid

Grid container that provides frame state and layout context.

NameTypeDefaultDescription
gridSize[number, number]requiredGrid dimensions as [columns, rows].
framesFramesrequiredFrame sequence of active [x, y] cells.
durationnumber200Frame interval in milliseconds.
animatebooleantrueToggles automatic frame cycling.
childSnippet<[ { props: MotionGridCellMotionProps } ]>-Render-prop wrapper for custom root rendering.
classClassValue""Additional classes for the grid root.

Motion Grid Cells

Renders all cells and applies active/inactive presentation.

NameTypeDefaultDescription
activePropsMotionGridCellMotionProps-Props merged into active cells.
inactivePropsMotionGridCellMotionProps-Props merged into inactive cells.
classClassValue""Base class applied to all cells.