import { ColumnDef, RowSelectionState } from "@tanstack/react-table"; import { Dispatch, SetStateAction } from "react"; export type SelectableTableData = object; export interface TableSelectionProps { /** * The data that is displayed in the table. */ data: Array; /** * The key in TData that should be used as the unique identifier * Example: 'id', 'assetId', 'userId', etc. */ idKey: keyof TData & string; /** * An array of ids of the rows that should be selected by default. */ defaultSelectedIds?: Array; /** * Whether or not to enable row selection. */ enableRowSelection?: boolean; } export interface TableSelectionReturn { /** * An array of the ids of the currently selected rows. */ selectedIds: Array; /** * The current state of row selection. * Pass this to the `state` prop of the `useTable` Hook. */ selectionTableState: { rowSelection?: RowSelectionState | undefined; }; /** * Props to pass to the `useTable` Hook. */ selectionTableProps: { onRowSelectionChange: Dispatch>; getRowId: (row: TData) => string; enableRowSelection: boolean; }; /** * A function to update the row selection state. * Pass this to the `onRowSelectionChange` prop of the `useTable` Hook. */ setRowSelection: Dispatch>; /** * A `ColumnDef` object for the selection column, which includes a checkbox in each cell and header. */ selectionColumn: ColumnDef; /** * A function to toggle the selection state of a single row. * This is usefull for example when you want to select a row when clicking on it, instead of the checkbox. */ toggleRowSelectionState: (id: TData[keyof TData]) => void; } /** * `useTableSelection` provides row selection state management for the Table component. * It returns a selection checkbox column definition, row selection state, and props to spread onto `useTable`. * * ### When to use * Use useTableSelection when your Table needs checkbox-based row selection — for example, bulk actions on selected assets. * * ### When not to use * Do not use useTableSelection if your table does not need row selection. For single-row actions, use `onRowClick` on the Table instead. * * @template TData - The type of data in the table. It must extend `SelectableTableData`. * @param {TableSelectionProps} props - Configuration for selection behavior including data, idKey, and defaults * @returns {TableSelectionReturn} Selection column, state, setters, and props to spread onto useTable * @example * const { * selectionColumn, * rowSelection, * setRowSelection, * } = useTableSelection(); * * const columns = [selectionColumn, ...otherColumns] * * const tableProps = useTable({ * ...selectionTableProps, * state: { * ...selectionTableState, * }, * data, * columns, * }); */ export declare const useTableSelection: ({ data, idKey, defaultSelectedIds, enableRowSelection, }: TableSelectionProps) => TableSelectionReturn;