'use client'; import * as React from 'react'; import { cn } from '@djangocfg/ui-core/lib'; import { TableRow, TableCell } from '@djangocfg/ui-core/components'; import { useDataTableContext } from '../context/DataTableContext'; interface DataTableRowProps { row: T; index: number; } export function DataTableRow({ row, index }: DataTableRowProps) { const { columns, getRowId, selectionMode, select, isSelected, getRowClassName, onRowClick, onRowDoubleClick, } = useDataTableContext(); const id = getRowId(row); const selected = isSelected(id); const handleClick = React.useCallback(() => { if (selectionMode !== 'none') { select(id); } onRowClick?.(row); }, [id, selectionMode, select, onRowClick, row]); const handleDoubleClick = React.useCallback(() => { onRowDoubleClick?.(row); }, [onRowDoubleClick, row]); return ( {selectionMode === 'multiple' && ( select(id)} className="h-4 w-4 rounded border-border accent-primary" aria-label={`Select row ${String(id)}`} onClick={(e) => e.stopPropagation()} /> )} {selectionMode === 'single' && ( select(id)} className="h-4 w-4 border-border accent-primary" aria-label={`Select row ${String(id)}`} onClick={(e) => e.stopPropagation()} /> )} {columns.map((col) => ( ))} ); } DataTableRow.displayName = 'DataTableRow'; function DataTableCell({ column, row }: { column: { key: string; cell?: (row: T) => React.ReactNode; align?: 'left' | 'center' | 'right' }; row: T }) { const value = (row as Record)[column.key]; const content = column.cell ? column.cell(row) : value != null ? String(value) : null; return ( {content} ); }