Skip to content
WANCRAFT

E.111Backgrounds & Effects

Warp Grid

Grid lines that bend around the pointer like a gravitational lens and spring back when it leaves.

NewReactCanvasTailwindadvanced

Overview

Warp Grid draws a line grid on one canvas where every intersection is a damped spring chasing a target displacement: a smooth falloff that pinches the lines toward the pointer like a lens (attract) or pushes them away (repel). Both mappings are monotonic, so lines bend but never fold over each other. When the pointer leaves, the grid eases back with a slight wobble. Optional idle ripples — and a ripple from every click or tap — roll through the mesh. A second stroke pass with a radial gradient tints the lines near the pointer in the accent colour. The loop runs on fixed 60Hz steps, sleeps once every node has settled, pauses offscreen and in hidden tabs, and reduced motion shows a flat, still grid.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/warp-grid.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/warp-grid.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/warp-grid.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { WarpGrid } from "@/components/ui/warp-grid";

export function WarpGridExample() {
  return (
    <div className="relative h-80 w-full overflow-hidden rounded-xl">
      <WarpGrid />
    </div>
  );
}

03Props

PropTypeDefaultDescription
spacingnumber36Distance between grid lines in px (min 8).
strengthnumber0.5Bend amount, 0–1. Attract pulls up to 55% of each node's distance; repel pushes up to 28% of the radius.
radiusnumber180Pointer influence radius in px.
mode"attract" | "repel""attract"Pinch the lines toward the pointer, or push them away.
ripplesbooleantrueSend a soft ripple through the grid every ~3.6s.
accentstring"#FF7448"Tint of the lines near the pointer (any CSS colour).
lineWidthnumber1Grid line width in px.
childrenReactNode—Optional content layered above the grid.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Spring-per-node displacement with a smooth (1 − d²/r²)² falloff — eases in, wobbles back
  • 02Monotonic attract/repel mappings: lines bend but never cross
  • 03Idle ripples plus a ripple from every click or tap
  • 04Accent highlight via a second stroke pass with a radial gradient
  • 05Rows and columns stroked as one Path2D per pass; loop sleeps once settled
  • 06DPR-aware canvas (capped at 2), ResizeObserver, pauses offscreen and in hidden tabs, theme-aware ink
motion · springmotion · continuousinput · pointerinput · clickinput · viewport

05Accessibility

  • The canvas is aria-hidden and ignores pointer events; layered content stays fully interactive.
  • prefers-reduced-motion renders a flat, still grid with no pointer bending or ripples.
  • Bending follows mouse and pen pointers only, so touch scrolling never distorts the grid; taps send a single ripple.