import React from 'react' import { TableDataItemBase, TableAbstractColumn, TableOnCellClick } from './table-types' interface Props { columns: Array> row: TableDataItem rowIndex: number emptyText: string onCellClick?: TableOnCellClick } export type TableCellData = { row: number column: number rowValue: TableDataItem } type NativeAttrs = Omit, keyof Props> export type TableCellProps = Props & NativeAttrs const TableCell = ({ columns, row, rowIndex, emptyText, onCellClick, }: TableCellProps) => { /* eslint-disable react/jsx-no-useless-fragment */ return ( <> {columns.map((column, index) => { const currentRowValue = row[column.prop] const cellValue = currentRowValue || emptyText const shouldBeRenderElement = column.renderHandler(currentRowValue, row, rowIndex) return ( onCellClick && onCellClick(currentRowValue, rowIndex, index)} className={column.className}>
{shouldBeRenderElement ? shouldBeRenderElement : cellValue}
) })} ) /* eslint-enable */ } export default TableCell