A field of points that behaves like a grid of tiny magnets, snapping to the nearest cell under the pointer.
Installation
The registry item ships the component, the shared moment primitives and the reduced-motion hook. Nothing else is pulled in.
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/snap-grid.jsonInstalls to components/prequelui/moments/snap-grid.tsx.
Usage
The component owns its state and its keyboard handling. Drop it in anywhere; pass preview only when another surface, like the gallery card, should drive the gesture for a moment.
import { SnapGrid } from "@/components/prequelui/moments/snap-grid";
export default function Demo() {
return <SnapGrid />;
}Gesture and motion
Gesture
Move the pointer or use arrow keys
Reaction
The nearest points snap toward the cursor, then click back to the lattice.
- Only transform, opacity, clip-path and filter are animated; the layout is never measured on every frame.
- The pointer and keyboard share the same state, so a drag can be continued with arrow keys.
- Releasing retargets the running spring instead of restarting it.
- With reduced motion, the state still changes but nothing travels or loops.
API Reference
Every moment exposes the same two props plus its own internal state. The root carries the right ARIA role: switch, slider, tab, checkbox, progressbar, dialog or button.
SnapGrid
| Prop | Type | Default |
|---|---|---|
| className | string | — |
| preview | boolean | false |