import { ArrowSmDownIcon, ArrowSmUpIcon } from '@heroicons/react/solid'; import React, { useEffect } from 'react'; import { useTable, useRowSelect, Column, IdType, useSortBy } from 'react-table'; export interface ReactTableProps> { columns: Column[]; data: T[]; onRowClick?(row: T): void; pagination?: boolean; getSelectedRowIds?(rows: Record, boolean>): void; selectable?: boolean; } const IndeterminateCheckbox = React.forwardRef(({ indeterminate, ...rest }: any, ref) => { const defaultRef = React.useRef(null); const resolvedRef: any = ref || defaultRef; React.useEffect(() => { resolvedRef.current.indeterminate = indeterminate; }, [resolvedRef, indeterminate]); return ( <> ); }); export const Table = >({ columns, data, pagination = false, onRowClick, getSelectedRowIds, selectable = false, }: ReactTableProps) => { const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, pageCount, state: { selectedRowIds }, } = useTable( { columns, data, }, useSortBy, useRowSelect, selectable ? (hooks) => { hooks.visibleColumns.push((columns2) => [ { id: 'selection', Header: ({ getToggleAllRowsSelectedProps }: { getToggleAllRowsSelectedProps: any }) => (
), Cell: ({ row }: { row: any }) => (
), width: 16, }, ...columns2, ]); } : () => {}, ); useEffect(() => { if (selectedRowIds && getSelectedRowIds) { getSelectedRowIds(selectedRowIds); } }, [selectedRowIds, getSelectedRowIds]); return ( <> {headerGroups.map((headerGroup: any, index: any) => ( {headerGroup.headers.map((column: any) => ( ))} ))} {rows.map((row: any, rowIndex) => { prepareRow(row); return ( onRowClick(row.original as T) : () => {}} > {row.cells.map((cell: any) => { return ( ); })} ); })}
{column.render('Header')} {(column as any).isSorted ? ( (column as any).isSortedDesc ? ( ) : ( ) ) : ( '' )}
{cell.render('Cell')}
{pagination && pageCount > 1 && (

Showing 1 to 3 of{' '} 3 results

)} ); };