import { ColumnDef, ColumnFiltersState, ColumnPinningState, ExpandedState, FilterFn, PaginationState, Row, RowData, RowSelectionState, SortingState, VisibilityState } from '@tanstack/react-table'; import { default as React } from 'react'; import { IntentionalAny } from '../../types'; import { CardProps } from '../card'; import { ChoiceGroupItemProps } from '../form/choice-group'; import { PlaceholderProps } from '../placeholder/placeholder'; import { PickerOverridableProps } from './components/table-filter/components/table-date-filter'; declare module '@tanstack/table-core' { interface FilterFns { /** * To filter out from text */ text: FilterFn; /** * To filter out from select options */ select: FilterFn; /** * To filter out from multi-select options */ 'multi-select': FilterFn; /** * To filter out from date range (to - from) */ 'date-range': FilterFn; /** * To filter out period from date range (to - from) */ 'date-range-period': FilterFn; } } declare module '@tanstack/react-table' { interface ColumnMeta { /** * Pass your own custom filterOptions to column.meta.filterOptions to override the default values. * Used only when filterFn: 'select' */ filterOptions?: ChoiceGroupItemProps[] | string[]; /** * Pass selection of props to the start DatePicker. * Used only when filterFn: 'date-range' | 'date-range-period' */ startDatePicker?: PickerOverridableProps; /** * Pass selection of props to the end DatePicker. * Used only when filterFn: 'date-range' | 'date-range-period' */ endDatePicker?: PickerOverridableProps; /** * Unknown parameters */ [key: string]: IntentionalAny; } } export interface DefaultTData { [key: string]: IntentionalAny; /** * All row Subrows */ subRows?: TData[]; /** * Rows are grouped by this key */ rowGroupKey?: string; /** * Added to Row */ rowClassName?: string; /** * Custom row Component to render this row */ CustomRowComponent?: React.ComponentType>; /** * Called when row is clicked */ onClick?: (row: TData) => void; } export interface TableProps> { /** * ID of table */ id: string; /** * Default table data. * Should be memoized array * @default [] */ data: TData[]; /** * Column object created with columnHelper * https://tanstack.com/table/v8/docs/guide/column-defs */ columns: ColumnDef[]; /** * Table title for screen-readers */ caption?: string; /** * Additional classname */ className?: string; /** * Hide pagination */ hidePagination?: boolean; /** * Card props */ cardProps?: CardProps; /** * If internal pagination logic is ignored. If true, then pagination must be handled in the app. * If omitted, then the value is inherited from `!!pagination` prop. */ manualPagination?: boolean; /** * If internal sorting logic is ignored. If true, then sorting must be handled in the app. * If omitted, then the value is inherited from `!!sorting` prop. */ manualSorting?: boolean; /** * If internal filtering logic is ignored. If true, then filtering must be handled in the app. * If omitted, then the value is inherited from `!!columnFilters` prop. */ manualFiltering?: boolean; /** * If set to true, pagination will be reset to the first page when page-altering state changes eg. data is updated, filters change, grouping changes, etc. * This option defaults to false if manualPagination is set to true * @default true */ autoResetPageIndex?: boolean; /** * Initial internal pagination state on render. This only applies when `pagination` prop is not defined. */ defaultPagination?: PaginationState; /** * Pagination data to server-side pagination use with `onPaginationChange` and `totalRows` */ pagination?: PaginationState; /** * Callback on Pagination data change. Use combined with `pagination` and `totalRows` props to make server-side pagination */ onPaginationChange?: (state: PaginationState) => void; /** * Initial internal sorting state on render. This only applies when `sorting` prop is not defined. */ defaultSorting?: SortingState; /** * Sorting data to server-side pagination use with onSortingChange */ sorting?: SortingState; /** * Callback on Sorting data change. Use combined with sorting prop to make server-side sorting. */ onSortingChange?: (state: SortingState) => void; /** * Sorting data to server-side pagination use with `onColumnFiltersChange` */ columnFilters?: ColumnFiltersState; /** * Callback on Sorting data change. Use combined with `columnFilters` prop to make server-side sorting. */ onColumnFiltersChange?: (state: ColumnFiltersState) => void; /** * Default selected rows */ defaultRowSelection?: RowSelectionState; /** * Row selection data use with `onRowSelectionChange`. */ rowSelection?: RowSelectionState; /** * Callback on row selection data change */ onRowSelectionChange?: (state: RowSelectionState) => void; /** * Enables/disables row selection for all rows in the table OR * A function that given a row, returns whether to enable/disable row selection for that row */ enableRowSelection?: boolean | ((row: Row) => boolean); /** * Initial internal columnVisibility state on render. This only applies when `columnVisibility` prop is not defined. */ defaultColumnVisibility?: VisibilityState; /** * ColumnVisibility state, use with onColumnVisbilityChange */ columnVisibility?: VisibilityState; /** * Callback on column visibility change. Use combined with `columnVisibility` prop to hide/show columns. */ onColumnVisibilityChange?: (state: VisibilityState) => void; /** * Column pinning state, used to stick columns to the left or right side of the table */ columnPinning?: ColumnPinningState; /** * Callback on column pinning change */ onColumnPinningChange?: (state: ColumnPinningState) => void; /** * Called when row is clicked */ onRowClick?: (row: TData) => void; /** * This optional function is used to derive a unique ID for any given row. If not provided the rows index is used (nested rows join together with . using their grandparents' index eg. index.index.index). * Its recommended to use Row ID when using row selection */ getRowId?: (originalRow: TData, index: number, parent?: Row) => string; /** * TotalRows - only needed to pass when server-side pagination is used. */ totalRows?: number; /** * Callback to render subComponent to expanded row. * Component will be rendered inside `` and spanned to whole row. */ renderSubComponent?: (row: Row) => React.ReactElement; /** * Initial internal expanding state on render. */ defaultExpanded?: ExpandedState; /** * Check if row can expand */ getRowCanExpand?: (row: Row) => boolean; /** * Is the table currently loading */ isLoading?: boolean; /** * Is the table currently in error state * When true errorPlaceholder is displayed */ isError?: boolean; /** * Props for the `` that is displayed when table is empty */ placeholder?: PlaceholderProps; /** * Props for the `` that is displayed when table is in error state */ errorPlaceholder?: PlaceholderProps; /** * Label for the table loader skeleton */ loadingLabel?: string; /** * Controls cell padding to conserve space. * Useful when nesting tables. */ size?: 'small' | 'medium'; /** * Group rows by key or comparison function that returns a group key. */ groupRowsBy?: Extract | ((row: TData) => string); /** * Callback to render row groups header. * Component will be rendered inside group headers ``. * If omitted, then the `rowGroupKey` (inferred from `groupRowsBy`) value is rendered by default */ renderGroupHeading?: (row: Row, 'rowGroupKey'>>) => React.ReactElement; /** * Vertical align of columns * @default 'middle */ verticalAlign?: 'base-line' | 'middle'; /** * Should table allow filtering columns. * Defaults to false, because TableFilter is not yet final, and we cant add filtering to every table. * @default false */ enableFilters?: boolean; /** * Should table allow sorting columns. * When false then `enableSorting` in column props are ignored * @default true */ enableSorting?: boolean; /** * Should show borders between rows. * @default false */ hideRowBorder?: boolean; /** * Should hide card border. Over-ridden with `cardProps` */ hideCardBorder?: boolean; }