'use client'; import * as React from 'react'; import { cn } from '@workspace/ui/lib/utils'; type HexagonBackgroundProps = React.ComponentProps<'div'> & { children?: React.ReactNode; hexagonProps?: React.ComponentProps<'div'>; hexagonSize?: number; // value greater than 50 hexagonMargin?: number; }; function HexagonBackground({ className, children, hexagonProps, hexagonSize = 75, hexagonMargin = 3, ...props }: HexagonBackgroundProps) { const hexagonWidth = hexagonSize; const hexagonHeight = hexagonSize * 1.1; const rowSpacing = hexagonSize * 0.8; const baseMarginTop = -36 - 0.275 * (hexagonSize - 100); const computedMarginTop = baseMarginTop + hexagonMargin; const oddRowMarginLeft = -(hexagonSize / 2); const evenRowMarginLeft = hexagonMargin / 2; const [gridDimensions, setGridDimensions] = React.useState({ rows: 0, columns: 0, }); const updateGridDimensions = React.useCallback(() => { const rows = Math.ceil(window.innerHeight / rowSpacing); const columns = Math.ceil(window.innerWidth / hexagonWidth) + 1; setGridDimensions({ rows, columns }); }, [rowSpacing, hexagonWidth]); React.useEffect(() => { updateGridDimensions(); window.addEventListener('resize', updateGridDimensions); return () => window.removeEventListener('resize', updateGridDimensions); }, [updateGridDimensions]); return (
{Array.from({ length: gridDimensions.rows }).map((_, rowIndex) => (
{Array.from({ length: gridDimensions.columns }).map( (_, colIndex) => (
), )}
))}
{children}
); } export { HexagonBackground, type HexagonBackgroundProps };