Dot Matrix
wise-ui/dot-matrixFreeComponent
An animated dot matrix background pattern.
Live preview
live · rendered by the registry
Rendered by wise-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://wise-ui.com/r/dot-matrix.jsonSource
1"use client"23import * as React from "react"4import { cn } from "@/registry/wise-ui/lib/utils"56interface DotMatrixProps extends React.HTMLAttributes<HTMLDivElement> {7 gap?: number8 dotSize?: number9 color?: string10 activeColor?: string11 influence?: number12 maxScale?: number13}1415function parseColor(color: string): [number, number, number] | null {16 const ctx = typeof document !== "undefined"17 ? document.createElement("canvas").getContext("2d")18 : null19 if (!ctx) return null20 ctx.fillStyle = color21 ctx.fillRect(0, 0, 1, 1)22 const d = ctx.getImageData(0, 0, 1, 1).data23 return [d[0], d[1], d[2]]24}2526const DotMatrix = React.forwardRef<HTMLDivElement, DotMatrixProps>(27 (28 {29 gap = 24,30 dotSize = 2,31 color = "currentColor",32 activeColor,33 influence = 100,34 maxScale = 3,35 className,36 children,37 ...props38 },39 ref40 ) => {41 const canvasRef = React.useRef<HTMLCanvasElement>(null)42 const containerRef = React.useRef<HTMLDivElement>(null)43 const mouseRef = React.useRef({ x: -9999, y: -9999 })4445 React.useImperativeHandle(ref, () => containerRef.current!)4647 React.useEffect(() => {48 const canvas = canvasRef.current49 const container = containerRef.current50 if (!canvas || !container) return5152 const ctx = canvas.getContext("2d")53 if (!ctx) return5455 let w = 056 let h = 057 let rafId = 058 let baseRgb: [number, number, number] = [128, 128, 128]59 let activeRgb: [number, number, number] = [128, 128, 128]6061 function resolveColors() {62 const computed = getComputedStyle(container!)63 const resolvedColor = color === "currentColor" ? computed.color : color64 const resolvedActive = activeColor65 ? (activeColor === "currentColor" ? computed.color : activeColor)66 : resolvedColor67 baseRgb = parseColor(resolvedColor) ?? [128, 128, 128]68 activeRgb = parseColor(resolvedActive) ?? baseRgb69 }7071 function resize() {72 const rect = container!.getBoundingClientRect()73 const dpr = Math.min(window.devicePixelRatio, 2)74 w = rect.width75 h = rect.height76 canvas!.width = w * dpr77 canvas!.height = h * dpr78 canvas!.style.width = `${w}px`79 canvas!.style.height = `${h}px`80 ctx!.setTransform(dpr, 0, 0, dpr, 0, 0)81 resolveColors()82 }8384 function draw() {85 ctx!.clearRect(0, 0, w, h)86 const mx = mouseRef.current.x87// … truncated
What it pulls in
npm packages
Files it writes
More from wise-ui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Tabsanimated-tabs | wise-ui | Components | Free | 3 deps | |
| Border Beamborder-beam | wise-ui | Components | Free | 3 deps | |
| Data Tabledata-table | wise-ui | Components | Free | 3 deps | |
| Dockdock | wise-ui | Components | Free | 3 deps | |
| Editable Texteditable-text | wise-ui | Components | Free | 4 deps | |
| Gradient Sidebargradient-sidebar | wise-ui | Components | Free | 3 deps | |
| Kanban Boardkanban-board | wise-ui | Components | Free | 6 deps | |
| Magnetic Buttonmagnetic-button | wise-ui | Components | Free | 3 deps |
