import React from 'react'; import { Cell, ColumnDef, Row, RowData, Table, TableOptions, } from '@tanstack/react-table'; /** LeafyGreen extension of `useReactTable` {@link RowData}*/ export type LGRowData = RowData; export type LGTableDataType = T & { renderExpandedContent?: (row: LeafyGreenTableRow) => JSX.Element; subRows?: Array>; }; /** LeafyGreen extension of `useReactTable` {@link Cell}*/ export type LeafyGreenTableCell = Cell< LGTableDataType, unknown >; /** LeafyGreen extension of `useReactTable` {@link Row}*/ export interface LeafyGreenTableRow extends Row> { isExpandedContent?: boolean; } export type LGColumnDef< T extends LGRowData, V extends unknown = unknown, > = ColumnDef, V> & { align?: React.ComponentProps<'td'>['align']; }; /** * Options argument for the LeafyGreen extension of `useReactTable` * * See: {@link TableOptions} */ export type LeafyGreenTableOptions< T extends LGRowData, V extends unknown = unknown, > = Omit>, 'getCoreRowModel' | 'columns'> & { /** * Setting this prop will inject a new column containing a checkbox into all rows. * * @default `false` */ hasSelectableRows?: boolean; /** * The column definitions for the table */ columns: Array>; /** * Setting this prop will indicate that the Table component is being used with the Pagination component. This will expose various pagination utilities from `table.getState().pagination`. * * @default `false` */ withPagination?: boolean; /** * This prop controls whether a 'select all' checkbox will be rendered in the header row. This will be set to `true` by default. * * @default `true` */ allowSelectAll?: boolean; }; /** * LeafyGreen extension of `useReactTable` {@link Table} */ export interface LeafyGreenTable extends Table> { /** * Whether the table will have selectable rows. */ hasSelectableRows: boolean; /** * Available [properties and methods](https://tanstack.com/virtual/latest/docs/api/virtualizer#virtualizer-instance) return from the Virtualizer instance. */ virtual: never; /** * Whether the rows should be memoized. This is determined by comparing changes in the column definitions passed to the `useLeafyGreenTable`/ `useLeafyGreenVirtualTable` hook. * * - If `true`, rows are memoized and only re-render when their data/props change, excluding children. * - If `false`, all rows re-render (when column definitions change). This bypasses memoization and ensures that rows pick up new configurations immediately. */ shouldMemoizeRows: boolean; }