import type { DatesRangeValue, DateStringValue } from '@mantine/dates'; import { type ExpandedState, type Row, type SortingState } from '@tanstack/table-core'; import { Dispatch, SetStateAction } from 'react'; type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; export interface PaginationState { /** * Zero-based page index. */ page: number; /** * Number of items per page. */ perPage: number; } /** * Enables or disables row selection globally, or determines whether each row can be selected. */ export type EnableRowSelection = boolean | ((row: Row) => boolean); /** * Enables or disables multi-row selection globally, or determines whether each row can be bulk selected. */ export type EnableMultiRowSelection = boolean | ((row: Row) => boolean); export interface TableState { /** * Current pagination state * * @default { page: 0, perPage: 50 } */ pagination: PaginationState; /** * Total number of entries in the table. * This number is used to calculate the number of pages in the pagination. * When null, the number of pages is calculated using the current data length. * * @default null */ totalEntries: number | null; /** * Current sorting state * * @default [] */ sorting: SortingState; /** * Current global filter value * * @default '' */ globalFilter: string; /** * Current expanded state * * @default {} */ expanded: ExpandedState; /** * Predicates and their current value * * @default {} */ predicates: Record; /** * Layout currently selected. When null, the first layout is used. * * @default null */ layout: string | null; /** * Currently selected date range * * @default [null, null] */ dateRange: DatesRangeValue; /** * Currently selected rows * * @default {} */ rowSelection: Record; /** * Columns that are currently visible * * @default {} */ columnVisibility: Record; } export interface TableStore { /** * Current state of the table. */ state: TableState; /** * Allows to change the pagination state. */ setPagination: Dispatch['pagination']>>; /** * Allows to change the total number of entries. */ setTotalEntries: Dispatch['totalEntries']>>; /** * Allows to change the sorting state. */ setSorting: Dispatch['sorting']>>; /** * Allows to change the global filter value. */ setGlobalFilter: Dispatch['globalFilter']>>; /** * Allows to change the rows expanded state. */ setExpanded: Dispatch['expanded']>>; /** * Allows to change the predicates values. */ setPredicates: Dispatch['predicates']>>; /** * Allows to change the selected layout. */ setLayout: Dispatch['layout']>>; /** * Allows to change the selected date range. */ setDateRange: Dispatch['dateRange']>>; /** * Allows to change the current row selection. */ setRowSelection: Dispatch['rowSelection']>>; /** * Allows to change the visible columns. */ setColumnVisibility: Dispatch['columnVisibility']>>; /** * Whether the table is currently filtered. */ isFiltered: boolean; /** * Whether the table has data when unfiltered. * * This is derived from the totalEntries so make sure you set that number correctly, even if you're using a client side table. */ isVacant: boolean; /** * Clear currently applied filters. */ clearFilters: () => void; /** * Deselects all currently selected rows. */ clearRowSelection: () => void; /** * Get currently selected rows. */ getSelectedRows: () => TData[]; /** * Get currently selected row */ getSelectedRow: () => TData | null; /** * The multi-row selection configuration currently used by the table. */ multiRowSelectionEnabled: EnableMultiRowSelection; /** * The row selection configuration currently used by the table. * * Reflects the `enableRowSelection` option passed to `useTable`, defaulting to `true` when omitted. */ rowSelectionEnabled: EnableRowSelection; /** * Whether row selection is forced. */ rowSelectionForced: boolean; } export interface UseTableOptions { /** * Initial state of the table. */ initialState?: DeepPartial>; /** * Configures which rows users can select. * * Set to `true` to allow selecting every row, `false` to disable row selection, or provide a predicate to determine * whether each row can be selected. * Rows rejected by the predicate are displayed with reduced opacity and do not render a selection checkbox. * * @default true */ enableRowSelection?: EnableRowSelection; /** * Configures which rows can be selected as part of a multi-row selection. * * Set to `true` to allow bulk-selecting every row, `false` to disable multi-row selection, or provide a predicate * to determine whether each row can be bulk selected. Rows rejected by the predicate remain single-selectable, * but are displayed with reduced opacity and excluded from checkboxes, select-all, and range selection. * * @default false */ enableMultiRowSelection?: EnableMultiRowSelection; /** * Forces the user to always have one row selected. * When activating that setting, a good practice is to have a row already selected in the initial state. * * @default false */ forceSelection?: boolean; /** * Whether to sync the table state with the URL. * * @default false */ syncWithUrl?: boolean; /** * Unique identifier for the table. When provided, column visibility preferences are persisted to localStorage. */ tableId?: string; /** * Maximum number of columns that can be visible when restoring persisted visibility from localStorage. * This only affects the initial column visibility resolved on mount when `tableId` is set. * It does not enforce a runtime limit on `setColumnVisibility` — use `TableColumnsSelector` for UI enforcement. * * @default Infinity */ maxSelectableColumns?: number; } export declare const useTable: (userOptions?: UseTableOptions) => TableStore; export {}; //# sourceMappingURL=use-table.d.ts.map