import React, { useState } from 'react'; import type { Grid, GridCell } from '@/types/grid'; import { Cell } from '@/components/grid/Cell'; interface GridProps { grid: Grid; onCellInteract?: (cell: GridCell) => void; onDragStart?: () => void; onDragEnd?: () => void; } export const GridComponent: React.FC = ({ grid, onCellInteract, onDragStart, onDragEnd, }) => { const [isDragging, setIsDragging] = useState(false); const handleMouseDown = (e: React.MouseEvent) => { e.preventDefault(); // Prevent text selection setIsDragging(true); onDragStart?.(); }; const handleMouseUp = () => { setIsDragging(false); onDragEnd?.(); }; const handleMouseLeave = () => { if (isDragging) { setIsDragging(false); onDragEnd?.(); } }; return (
{grid.map((row, i) => (
{row.map((cell, j) => ( onCellInteract(cell) : undefined} onMouseEnter={isDragging && onCellInteract ? () => onCellInteract(cell) : undefined} /> ))}
))}
); };