import type React from 'react'; import { useTranslation } from '#hooks'; import { cn } from '#utils'; import { DataTableEmptyState } from './DataTableEmptyState.tsx'; import { useDataTableHandle } from './hooks.ts'; import { flexRender } from './utils.tsx'; import type { DataTableContentProps } from './types.ts'; export const DataTableBody: React.FC< Pick, 'emptyStateProps' | 'onRowClick' | 'onRowDoubleClick'> > = ({ emptyStateProps, onRowClick, onRowDoubleClick }) => { const rows = useDataTableHandle('rows'); const { t } = useTranslation(); return (
{rows.length === 0 ? (
) : ( rows.map((row) => ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
void onRowClick(row.original) : undefined} onDoubleClick={onRowDoubleClick ? () => void onRowDoubleClick(row.original) : undefined} > {row.getVisibleCells().map((cell) => { const style: React.CSSProperties = { width: `calc(var(--col-${cell.column.id}-size) * 1px)` }; if (cell.column.getIsPinned() === 'left') { style.left = `${cell.column.getStart('left')}px`; style.position = 'sticky'; style.zIndex = 20; } else if (cell.column.getIsPinned() === 'right') { style.right = `${cell.column.getAfter('right')}px`; style.position = 'sticky'; style.zIndex = 20; } // no border with actions on right // TODO - consider resizing toggle in this case if (cell.column.getIsLastColumn('center')) { style.borderRight = 'none'; } const content = flexRender(cell.column.columnDef.cell, cell.getContext()); return (
{content && typeof content === 'object' ? content : {content}}
); })}
)) )}
); };