Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/motion-grid.jsonFirst component? Set up your project first
Frameworks
The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.
"use client";
import * as React from "react";
import { motion, useInView } from "motion/react";
import { cn } from "@/lib/utils";
import { useReduceMotion } from "./motion";
export type MotionGridProps = Omit<React.ComponentProps<"div">, "onChange"> & {
count?: number;
columns?: number;
dotSize?: number;
gap?: number;
speed?: number;
stagger?: number;
pauseOnHover?: boolean;
dotClassName?: string;
};
export function MotionGrid({
count = 35,
columns = 7,
dotSize = 8,
gap = 10,
speed = 1.4,
stagger = 0.07,
pauseOnHover = true,
dotClassName,
className,
onPointerEnter,
onPointerLeave,
style,
...props
}: MotionGridProps) {
const reduce = useReduceMotion();
const ref = React.useRef<HTMLDivElement>(null);
const inView = useInView(ref, { margin: "120px 0px" });
const [paused, setPaused] = React.useState(false);
const total = Math.max(1, Math.round(count));
const cols = Math.max(1, Math.round(columns));
return (
<div
ref={ref}
data-slot="motion-grid"
aria-hidden="true"
className={cn("grid w-fit", className)}
style={{
gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`,
gap,
...style,
}}
onPointerEnter={(event) => {
onPointerEnter?.(event);
if (pauseOnHover) setPaused(true);
}}
onPointerLeave={(event) => {
onPointerLeave?.(event);
if (pauseOnHover) setPaused(false);
}}
{...props}
>
{Array.from({ length: total }, (_, index) => {
const row = Math.floor(index / cols);
const column = index % cols;
const delay = (row + column) * stagger;
const resting = reduce || paused || !inView;
return (
<motion.span
key={index}
className={cn("rounded-full bg-foreground", dotClassName)}
style={{ width: dotSize, height: dotSize }}
animate={
resting
? { scale: 1, opacity: paused ? 0.35 : 0.55 }
: {
scale: [0.65, 1, 0.65],
opacity: [0.3, 1, 0.3],
}
}
transition={
resting
? { duration: reduce ? 0 : 0.2 }
: {
duration: speed,
repeat: Infinity,
delay,
ease: "easeInOut",
}
}
/>
);
})}
</div>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/motion-grid.jsonDependencies
motion lucide-reactThe registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { MotionGrid } from "@/components/prequelui/motion-grid";
export default function Demo() {
return <MotionGrid className="rounded-xl border p-5" />;
}import { MotionGrid } from "@/components/prequelui/motion-grid";
export function Variant() {
return (
<MotionGrid tempo={1.2}>
…
</MotionGrid>
);
}Animation
A field of dots ripples in a diagonal wave. Each dot waits for its row and column before starting, so the eye reads a single travelling front instead of noise.
- Wave: each dot repeats every 1.4 s with easeInOut.
- Stagger: 70 ms per row plus column step.
- Hover settles the whole field at 35% opacity.
- Reduced motion holds a static, evenly lit grid.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
MotionGrid
| Prop | Type | Default |
|---|---|---|
| count | number | 35 |
| columns | number | 7 |
| dotSize | number | 8 |
| gap | number | 10 |
| speed | number | 1.4 |
| stagger | number | 0.07 |
| pauseOnHover | boolean | true |