import React from 'react' import useTheme from '../use-theme' import TableCell from './table-cell' import { useTableContext } from './table-context' import { TableDataItemBase, TableOnCellClick, TableOnRowClick, TableRowClassNameHandler, } from './table-types' interface Props { hover: boolean emptyText: string onRow?: TableOnRowClick onCell?: TableOnCellClick data: Array className?: string rowClassName: TableRowClassNameHandler } const defaultProps = { className: '', } type NativeAttrs = Omit, keyof Props> export type TableBodyProps = Props & NativeAttrs const TableBody = ({ data, hover, emptyText, onRow, onCell, rowClassName, }: TableBodyProps & typeof defaultProps) => { const theme = useTheme() const { columns } = useTableContext() const rowClickHandler = (row: TableDataItem, index: number) => { onRow && onRow(row, index) } return ( {data.map((row, index) => { const className = rowClassName(row, index) return ( rowClickHandler(row, index)}> columns={columns} row={row} rowIndex={index} emptyText={emptyText} onCellClick={onCell} /> ) })} ) } TableBody.defaultProps = defaultProps TableBody.displayName = 'GeistTableBody' export default TableBody