Skip to content
WANCRAFT

E.18Backgrounds & Effects

Dot Matrix Field

A halftone dot grid that swells and lights up around the pointer, drawn on one canvas.

ReactCanvasTailwindadvanced

Overview

Dot Matrix Field renders a centred grid of dots on a single DPR-aware canvas. Near a mouse pointer, dots grow and brighten with a smoothstep falloff and can shift toward an accent colour or sample a two-colour gradient. An optional idle wave keeps the field quietly alive. The render loop runs only while something changes, stops offscreen and in hidden tabs, follows light/dark themes, and falls back to a static or gently waving field on touch.

01Installation

Method 01 · Registry

CLI verified

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

npx shadcn@latest add https://wancraft.my/r/dot-matrix-field.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/dot-matrix-field.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
1 Oct 2026
Updated
—

02Usage

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

example.tsx
import { DotMatrixField } from "@/components/ui/dot-matrix-field";

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

03Props

PropTypeDefaultDescription
spacingnumber18Distance between dot centres in px (min 4).
dotSizenumber1.4Resting dot radius in px.
influencenumber140Pointer influence radius in px.
colorMode"mono" | "accent" | "gradient""accent"Mono uses the inherited text colour; accent tints lit dots; gradient spans accent → secondary across the field.
accentstring"#FF7448"Accent colour (any CSS colour).
secondarystring"#B6F3D1"Second gradient colour (any CSS colour).
animatebooleantrueEnables the subtle idle wave.
childrenReactNode—Optional content layered above the field.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Single canvas, devicePixelRatio-aware (capped at 2), resized with ResizeObserver
  • 02Demand-driven render loop: idles when nothing changes, stops offscreen and in hidden tabs
  • 03Frame-rate independent pointer smoothing with fade in/out
  • 04Mono colour follows light/dark themes (media query or class-based)
  • 05Works layered behind or around content — pointer tracking does not need to sit on top
motion · continuousinput · pointerinput · hoverinput · viewport

05Accessibility

  • The canvas is aria-hidden and ignores pointer events; overlaid content stays fully interactive.
  • prefers-reduced-motion disables the idle wave; the pointer highlight remains as direct feedback.
  • Touch and pen input never trigger the highlight, avoiding flashes while scrolling.