import * as React from "react" import { motion } from "framer-motion" function Block({ x, y, ...props }: Omit, "x" | "y"> & { x: number y: number }) { return ( ) } export function GridPattern({ yOffset = 0, interactive = false, ...props }: React.ComponentPropsWithoutRef<"svg"> & { yOffset?: number interactive?: boolean }) { let id = React.useId() let ref = React.useRef>(null) let currentBlock = React.useRef<[x: number, y: number]>() let counter = React.useRef(0) let [hoveredBlocks, setHoveredBlocks] = React.useState< Array<[x: number, y: number, key: number]> >([]) let staticBlocks = [ [1, 1], [2, 2], [4, 3], [6, 2], [7, 4], [5, 5], ] React.useEffect(() => { if (!interactive) { return } function onMouseMove(event: MouseEvent) { if (!ref.current) { return } let rect = ref.current.getBoundingClientRect() let x = event.clientX - rect.left let y = event.clientY - rect.top if (x < 0 || y < 0 || x > rect.width || y > rect.height) { return } x = x - rect.width / 2 - 32 y = y - yOffset x += Math.tan(32 / 160) * y x = Math.floor(x / 96) y = Math.floor(y / 160) if (currentBlock.current?.[0] === x && currentBlock.current?.[1] === y) { return } currentBlock.current = [x, y] setHoveredBlocks((blocks) => { let key = counter.current++ let block = [x, y, key] as (typeof hoveredBlocks)[number] return [...blocks, block].filter( (block) => !(block[0] === x && block[1] === y && block[2] !== key) ) }) } window.addEventListener("mousemove", onMouseMove) return () => { window.removeEventListener("mousemove", onMouseMove) } }, [yOffset, interactive]) return ( ) }