import classNames from 'classnames'; import React from 'react'; import IconButton from 'Components/Link/IconButton'; import Scroller from 'Components/Scroller/Scroller'; import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper'; import { icons, scrollDirections } from 'Helpers/Props'; import { SortDirection } from 'Helpers/Props/sortDirections'; import { CheckInputChanged } from 'typings/inputs'; import { TableOptionsChangePayload } from 'typings/Table'; import Column from './Column'; import TableHeader from './TableHeader'; import TableHeaderCell from './TableHeaderCell'; import TableSelectAllHeaderCell from './TableSelectAllHeaderCell'; import styles from './Table.css'; interface TableProps { className?: string; horizontalScroll?: boolean; selectAll?: boolean; allSelected?: boolean; allUnselected?: boolean; columns: Column[]; optionsComponent?: React.ElementType; pageSize?: number; canModifyColumns?: boolean; sortKey?: string; sortDirection?: SortDirection; children?: React.ReactNode; onSortPress?: (name: string, sortDirection?: SortDirection) => void; onTableOptionChange?: (payload: TableOptionsChangePayload) => void; onSelectAllChange?: (change: CheckInputChanged) => void; } function Table({ className = styles.table, horizontalScroll = true, selectAll = false, allSelected = false, allUnselected = false, columns, optionsComponent, pageSize, canModifyColumns, sortKey, sortDirection, children, onSortPress, onTableOptionChange, onSelectAllChange, }: TableProps) { return ( {selectAll && onSelectAllChange ? ( ) : null} {columns.map((column) => { const { name, isVisible, isSortable, ...otherColumnProps } = column; if (!isVisible) { return null; } if ( (name === 'actions' || name === 'details') && onTableOptionChange ) { return ( ); } return ( {typeof column.label === 'function' ? column.label() : column.label} ); })} {children}
); } export default Table;