{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "hexagon-background", "type": "registry:ui", "title": "Hexagon Background", "description": "A background component featuring an interactive hexagon grid.", "files": [ { "path": "registry/backgrounds/hexagon/index.tsx", "content": "'use client';\n\nimport * as React from 'react';\n\nimport { cn } from '@/lib/utils';\n\ntype HexagonBackgroundProps = React.ComponentProps<'div'> & {\n children?: React.ReactNode;\n hexagonProps?: React.ComponentProps<'div'>;\n hexagonSize?: number; // value greater than 50\n hexagonMargin?: number;\n};\n\nfunction HexagonBackground({\n className,\n children,\n hexagonProps,\n hexagonSize = 75,\n hexagonMargin = 3,\n ...props\n}: HexagonBackgroundProps) {\n const hexagonWidth = hexagonSize;\n const hexagonHeight = hexagonSize * 1.1;\n const rowSpacing = hexagonSize * 0.8;\n const baseMarginTop = -36 - 0.275 * (hexagonSize - 100);\n const computedMarginTop = baseMarginTop + hexagonMargin;\n const oddRowMarginLeft = -(hexagonSize / 2);\n const evenRowMarginLeft = hexagonMargin / 2;\n\n const [gridDimensions, setGridDimensions] = React.useState({\n rows: 0,\n columns: 0,\n });\n\n const updateGridDimensions = React.useCallback(() => {\n const rows = Math.ceil(window.innerHeight / rowSpacing);\n const columns = Math.ceil(window.innerWidth / hexagonWidth) + 1;\n setGridDimensions({ rows, columns });\n }, [rowSpacing, hexagonWidth]);\n\n React.useEffect(() => {\n updateGridDimensions();\n window.addEventListener('resize', updateGridDimensions);\n return () => window.removeEventListener('resize', updateGridDimensions);\n }, [updateGridDimensions]);\n\n return (\n \n \n
\n {Array.from({ length: gridDimensions.rows }).map((_, rowIndex) => (\n \n {Array.from({ length: gridDimensions.columns }).map(\n (_, colIndex) => (\n \n ),\n )}\n
\n ))}\n \n {children}\n \n );\n}\n\nexport { HexagonBackground, type HexagonBackgroundProps };\n", "type": "registry:ui", "target": "components/animate-ui/backgrounds/hexagon.tsx" } ] }