Dot Grid Spotlight
ncdai/dot-grid-spotlightUnverifiedComponent
Interactive dot grid with a cursor-tracking spotlight effect.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/srirae/iamsri/main/public/r/dot-grid-spotlight.jsonSource
1"use client"23import React, { useEffect, useRef } from "react"45import { cn } from "@/lib/utils"67export type DotGridSpotlightProps = {8 /**9 * The base color of the default/inactive dots.10 * @default "rgba(255, 255, 255, 0.05)"11 */12 dotColor?: string1314 /**15 * The color of the active dots when illuminated by the cursor's spotlight.16 * @default "rgba(255, 255, 255, 0.1)"17 */18 activeDotColor?: string1920 /**21 * The distance (in pixels) between each dot in the grid.22 * @default 1023 */24 spacing?: number2526 /**27 * The default radius of the dots when they are outside the interaction area.28 * @default 129 */30 baseRadius?: number3132 /**33 * The maximum radius of a dot when it is at the exact center of the cursor.34 * @default 235 */36 activeRadius?: number3738 /**39 * The radius (in pixels) of the interaction area (spotlight) around the cursor.40 * @default 12841 */42 interactionRadius?: number4344 /**45 * The maximum opacity (alpha) at the exact center of the spotlight.46 * Accepts a value between `0` and `1` (e.g., `1` for full opacity).47 * @default 1.048 */49 activeMaxAlpha?: number5051 /**52 * The minimum opacity (alpha) at the outer edge of the spotlight.53 * Accepts a value between `0` and `1` (e.g., a low value for a soft, subtle fade).54 * @default 0.555 */56 activeMinAlpha?: number5758 /**59 * Optional CSS class name to apply to the canvas or its wrapper.60 */61 className?: string62}6364export function DotGridSpotlight({65 dotColor = "rgba(255, 255, 255, 0.05)",66 activeDotColor = "rgba(255, 255, 255, 0.1)",67 spacing = 10,68 baseRadius = 1,69 activeRadius = 2,70 interactionRadius = 128,71 activeMaxAlpha = 1.0,72 activeMinAlpha = 0.5,73 className,74}: DotGridSpotlightProps) {75 const canvasRef = useRef<HTMLCanvasElement>(null)76 const mouse = useRef({ x: -1000, y: -1000, isActive: false })7778 useEffect(() => {79 const canvas = canvasRef.current80 if (!canvas) return8182 const ctx = canvas.getContext("2d")83 if (!ctx) return8485 let width = 086 let height = 087 let renderFrameId: number | null = null8889 const draw = () => {90 ctx.clearRect(0, 0, width, height)9192 const offsetX = (width % spacing) / 293 const offsetY = (height % spacing) / 29495 for (let x = offsetX; x <= width; x += spacing) {96 for (let y = offsetY; y <= height; y += spacing) {97 const dx = x - mouse.current.x98 const dy = y - mouse.current.y99 const distance = Math.sqrt(dx * dx + dy * dy)100101// … truncated
Files it writes
More from ncdai
All 48 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Apple Hello Effectapple-hello-effect | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Hindiapple-hello-effect-hindi | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Spanishapple-hello-effect-spanish | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Vietnameseapple-hello-effect-vietnamese | ncdai | Components | Unverified | 1 dep | |
| Brand Assets Menubrand-assets-menu | ncdai | Components | Unverified | 1 dep | |
| chevrons-up-down-iconchevrons-up-down-icon | ncdai | Components | Unverified | 1 dep | |
| Code Block Commandcode-block-command | ncdai | Components | Unverified | 4 deps · 2 files | |
| Consent Managerconsent-manager | ncdai | Components | Unverified | 1 dep |
