asafefe.dev
Lab

Lab/01

Interactive Dot Grid

A field of dots that move aside and turn vermilion as the cursor passes. Drawn every frame with a soft falloff radius.

  • Canvas
  • Interaction
Move across the field

Installation

Add Dot Grid to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-dot-grid

Or by URL: https://asafefe.dev/r/lab-dot-grid.json

Brings along

  • utils
  • @soultel/lab-canvas

Usage

example.tsx10 lines
import { DotGrid } from "@/components/lab/dot-grid"

export function Hero() {
  return (
    <section className="relative h-96">
      <DotGrid className="absolute inset-0" />
      <h1 className="relative">Hello</h1>
    </section>
  )
}

Props

PropTypeDefaultDescription
gapnumber24Distance between dots in px.
radiusnumber130Cursor influence radius in px.
pushnumber14How far dots move aside at the cursor, in px.
dotSizenumber1.1Idle dot radius in px.
colorstring"var(--foreground)"Idle dot color. Any CSS color.
activeColorstring"var(--primary)"Color near the cursor.
opacitynumber0.16Idle dot opacity.