Modus UI

Cursor Grid

Web (React)

An interactive canvas grid that reacts to cursor proximity and clicks.

A highly optimized <canvas> implementation of a grid that lights up based on cursor proximity and triggers ripples on click. Since it uses requestAnimationFrame and canvas 2D, it has a negligible impact on DOM performance, easily running at 60fps on huge containers.

Hover over the grid

Installation

CLI

npx @modus-ui/cli add cursor-grid

Manual

  1. Copy the code from the component tab.
  2. Create a file at components/ui/cursor-grid.tsx.
  3. Paste the code.

Usage

tsx
import { CursorGrid } from "@/components/ui/cursor-grid";

export default function Example() {
  return (
    <div className="relative h-screen w-full bg-black">
      <CursorGrid color="hsl(var(--primary))" cellSize={25} radius={150} />
    </div>
  );
}

Props

PropTypeDefaultDescription
colorstring"hsl(var(--primary))"Colour of highlighted cells.
cellSizenumber32Size of each grid cell in pixels.
radiusnumber120Radius in pixels of the cursor's influence.
falloff"linear" | "exponential" | "gaussian""gaussian"How the highlight fades with distance from the cursor.
holdTimenumber0Milliseconds a cell stays lit before fading.
fadeDurationnumber600Milliseconds a cell takes to fade out.
lineWidthnumber1Width of the grid lines in pixels.
maxOpacitynumber1Maximum opacity of a highlighted cell.
fillOpacitynumber0.1Opacity of the fill of highlighted cells.
gridOpacitynumber0.05Opacity of the resting grid lines.
cellRadiusnumber4Corner radius of each cell in pixels.
clickPulsebooleantrueSends a ripple across the grid on click.
pulseSpeednumber800Duration in milliseconds of the click ripple.

Comments

  • No comments yet.