import React from 'react'; import classNames from 'classnames'; import { DataTable } from './data-table'; import { withHeader } from '../columns/with-header'; import { TableCell } from '../elements'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPencilAlt, faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import { FlexTable } from '../..'; import { combineChildren, getItemRenderer, getFooter } from './editing-functions'; export function EditableTable(props: FlexTable.EditableTableProps) { const { children, getId, isEditing, onEdit, onDelete, disableInsert, editID, row, nonEditableRow, footerClassName, form, insertItem, ...attrs } = props; const attr = { getId, isEditing, onEdit, onDelete, editID, nonEditableRow }; const renderer = getItemRenderer(props); return ( getFooter(props)} footerClassName={classNames({ 'editing': isEditing && editID === null }, footerClassName)} row={row} {...attrs}> {combineChildren(children, ) as FlexTable.TableChildNodes} ); }; interface ActionColumn extends FlexTable.ColumnProps { nonEditableRow?: FlexTable.NonEditableRowHandler, itemId: ID, children?: never; } type ActionColumnProps = FlexTable.ColumnProps & ActionColumn & FlexTable.Editable & FlexTable.Updatable & { nonEditableRow?: FlexTable.NonEditableRowHandler, getId: (item: T) => ID, children?: never; }; const ActionColumn = withHeader>(({ item, onRender, children, onAction, cellClassName, hideHeader, getId, ...attrs }) => { const className = (cellClassName && typeof cellClassName === 'function') ? cellClassName(item) : cellClassName; const { nonEditableRow, onDelete, isEditing, onEdit } = attrs; if (nonEditableRow && nonEditableRow(item)) { return null; } const itemId = getId(item); return ( ); });