UNPKG

30.3 kBTypeScriptView Raw
1// tslint:disable:no-empty-interface
2// no-empty-interface is disabled to allow easy extension with declaration merging
3
4/* eslint-disable @definitelytyped/no-unnecessary-generics */
5// no-unnecessary-generics is disabled because many of these definitions are either used in a generic
6// context or the signatures are required to match for declaration merging
7
8// The changelog for the important changes is located in the Readme.md
9
10import {
11 ChangeEvent,
12 ComponentType,
13 CSSProperties,
14 DependencyList,
15 EffectCallback,
16 MouseEvent,
17 ReactElement,
18 ReactNode,
19} from "react";
20
21export {};
22
23/**
24 * The empty definitions of below provides a base definition for the parts used by useTable, that can then be extended in the users code.
25 *
26 * @example
27 * export interface TableOptions<D extends object = {}}>
28 * extends
29 * UseExpandedOptions<D>,
30 * UseFiltersOptions<D> {}
31 * see https://gist.github.com/ggascoigne/646e14c9d54258e40588a13aabf0102d for more details
32 */
33export interface TableOptions<D extends object> extends UseTableOptions<D> {}
34
35export interface TableInstance<D extends object = {}>
36 extends Omit<TableOptions<D>, "columns" | "pageCount">, UseTableInstanceProps<D>
37{}
38
39export interface TableState<D extends object = {}> {
40 hiddenColumns?: Array<IdType<D>> | undefined;
41}
42
43export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}
44
45export interface Cell<D extends object = {}, V = any> extends UseTableCellProps<D, V> {}
46
47export interface ColumnInterface<D extends object = {}> extends UseTableColumnOptions<D> {}
48
49export interface ColumnInterfaceBasedOnValue<D extends object = {}, V = any> {
50 Cell?: Renderer<CellProps<D, V>> | undefined;
51}
52
53export interface ColumnGroupInterface<D extends object> {
54 columns: Array<Column<D>>;
55}
56
57export type ColumnGroup<D extends object = {}> =
58 & ColumnInterface<D>
59 & ColumnGroupInterface<D>
60 & (
61 | { Header: string }
62 | ({ id: IdType<D> } & {
63 Header: Renderer<HeaderProps<D>>;
64 })
65 )
66 // Not used, but needed for backwards compatibility
67 & { accessor?: Accessor<D> | undefined };
68
69type ValueOf<T> = T[keyof T];
70
71// The accessors like `foo.bar` are not supported, use functions instead
72export type ColumnWithStrictAccessor<D extends object = {}> =
73 & ColumnInterface<D>
74 & ValueOf<
75 {
76 [K in keyof D]: {
77 accessor: K;
78 } & ColumnInterfaceBasedOnValue<D, D[K]>;
79 }
80 >;
81
82export type ColumnWithLooseAccessor<D extends object = {}> =
83 & ColumnInterface<D>
84 & ColumnInterfaceBasedOnValue<D>
85 & (
86 | { Header: string }
87 | { id: IdType<D> }
88 | { accessor: keyof D extends never ? IdType<D> : never }
89 )
90 & { accessor?: (keyof D extends never ? IdType<D> | Accessor<D> : Accessor<D>) | undefined };
91
92export type Column<D extends object = {}> =
93 | ColumnGroup<D>
94 | ColumnWithLooseAccessor<D>
95 | ColumnWithStrictAccessor<D>;
96
97export interface ColumnInstance<D extends object = {}>
98 extends Omit<ColumnInterface<D>, "id">, ColumnInterfaceBasedOnValue<D>, UseTableColumnProps<D>
99{}
100
101export interface HeaderGroup<D extends object = {}> extends ColumnInstance<D>, UseTableHeaderGroupProps<D> {}
102
103export interface Row<D extends object = {}> extends UseTableRowProps<D> {}
104
105export interface TableCommonProps {
106 style?: CSSProperties | undefined;
107 className?: string | undefined;
108 role?: string | undefined;
109}
110
111export interface TableProps extends TableCommonProps {}
112
113export interface TableBodyProps extends TableCommonProps {}
114
115export interface TableKeyedProps extends TableCommonProps {
116 key: React.Key;
117}
118
119export interface TableHeaderGroupProps extends TableKeyedProps {}
120
121export interface TableFooterGroupProps extends TableKeyedProps {}
122
123export interface TableHeaderProps extends TableKeyedProps {}
124
125export interface TableFooterProps extends TableKeyedProps {}
126
127export interface TableRowProps extends TableKeyedProps {}
128
129export interface TableCellProps extends TableKeyedProps {}
130
131export interface TableToggleCommonProps extends TableCommonProps {
132 onChange?: ((e: ChangeEvent) => void) | undefined;
133 checked?: boolean | undefined;
134 title?: string | undefined;
135 indeterminate?: boolean | undefined;
136}
137
138export interface MetaBase<D extends object> {
139 instance: TableInstance<D>;
140 userProps: any;
141}
142
143// inspired by ExtendState in https://github.com/reduxjs/redux/blob/master/src/types/store.ts
144export type Meta<D extends object, Extension = never, M = MetaBase<D>> = [Extension] extends [never] ? M
145 : M & Extension;
146
147// #region useTable
148export function useTable<D extends object = {}>(
149 options: TableOptions<D>,
150 ...plugins: Array<PluginHook<D>>
151): TableInstance<D>;
152
153/**
154 * NOTE: To use custom options, use "Interface Merging" to add the custom options
155 */
156export type UseTableOptions<D extends object> =
157 & {
158 columns: ReadonlyArray<Column<D>>;
159 data: readonly D[];
160 }
161 & Partial<{
162 initialState: Partial<TableState<D>>;
163 stateReducer: (
164 newState: TableState<D>,
165 action: ActionType,
166 previousState: TableState<D>,
167 instance?: TableInstance<D>,
168 ) => TableState<D>;
169 useControlledState: (state: TableState<D>, meta: Meta<D>) => TableState<D>;
170 defaultColumn: Partial<Column<D>>;
171 getSubRows: (originalRow: D, relativeIndex: number) => D[];
172 getRowId: (originalRow: D, relativeIndex: number, parent?: Row<D>) => string;
173 autoResetHiddenColumns: boolean;
174 }>;
175
176export type PropGetter<D extends object, Props, T extends object = never, P = Partial<Props>> =
177 | ((props: P, meta: Meta<D, T>) => P | P[])
178 | P
179 | P[];
180
181export type TablePropGetter<D extends object> = PropGetter<D, TableProps>;
182
183export type TableBodyPropGetter<D extends object> = PropGetter<D, TableBodyProps>;
184
185export type HeaderPropGetter<D extends object> = PropGetter<D, TableHeaderProps, { column: HeaderGroup<D> }>;
186
187export type FooterGroupPropGetter<D extends object> = PropGetter<D, TableFooterGroupProps, { column: HeaderGroup<D> }>;
188
189export type HeaderGroupPropGetter<D extends object> = PropGetter<D, TableHeaderGroupProps, { column: HeaderGroup<D> }>;
190
191export type FooterPropGetter<D extends object> = PropGetter<D, TableFooterProps, { column: HeaderGroup<D> }>;
192
193export type RowPropGetter<D extends object> = PropGetter<D, TableRowProps, { row: Row<D> }>;
194
195export type CellPropGetter<D extends object> = PropGetter<D, TableCellProps, { cell: Cell<D> }>;
196
197export interface ReducerTableState<D extends object> extends TableState<D>, Record<string, any> {}
198
199export interface UseTableHooks<D extends object> extends Record<string, any> {
200 useOptions: Array<(options: TableOptions<D>, args: TableOptions<D>) => TableOptions<D>>;
201 stateReducers: Array<
202 (
203 newState: TableState<D>,
204 action: ActionType,
205 previousState?: TableState<D>,
206 instance?: TableInstance<D>,
207 ) => ReducerTableState<D> | undefined
208 >;
209 columns: Array<(columns: Array<Column<D>>, meta: Meta<D>) => Array<Column<D>>>;
210 columnsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
211 allColumns: Array<(allColumns: Array<ColumnInstance<D>>, meta: Meta<D>) => Array<Column<D>>>;
212 allColumnsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
213 visibleColumns: Array<(allColumns: Array<ColumnInstance<D>>, meta: Meta<D>) => Array<Column<D>>>;
214 visibleColumnsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
215 headerGroups: Array<(allColumns: Array<HeaderGroup<D>>, meta: Meta<D>) => Array<HeaderGroup<D>>>;
216 headerGroupsDeps: Array<(deps: any[], meta: Meta<D>) => any[]>;
217 useInstanceBeforeDimensions: Array<(instance: TableInstance<D>) => void>;
218 useInstance: Array<(instance: TableInstance<D>) => void>;
219 prepareRow: Array<(row: Row<D>, meta: Meta<D>) => void>;
220 useControlledState: Array<(state: TableState<D>, meta: Meta<D>) => TableState<D>>;
221
222 getTableProps: Array<TablePropGetter<D>>;
223 getTableBodyProps: Array<TableBodyPropGetter<D>>;
224 getHeaderGroupProps: Array<HeaderGroupPropGetter<D>>;
225 getFooterGroupProps: Array<FooterGroupPropGetter<D>>;
226 getHeaderProps: Array<HeaderPropGetter<D>>;
227 getFooterProps: Array<FooterPropGetter<D>>;
228 getRowProps: Array<RowPropGetter<D>>;
229 getCellProps: Array<CellPropGetter<D>>;
230 useFinalInstance: Array<(instance: TableInstance<D>) => void>;
231}
232
233export interface UseTableColumnOptions<D extends object> {
234 id?: IdType<D> | undefined;
235 Header?: Renderer<HeaderProps<D>> | undefined;
236 Footer?: Renderer<FooterProps<D>> | undefined;
237 width?: number | string | undefined;
238 minWidth?: number | undefined;
239 maxWidth?: number | undefined;
240}
241
242type UpdateHiddenColumns<D extends object> = (oldHidden: Array<IdType<D>>) => Array<IdType<D>>;
243
244export interface TableToggleHideAllColumnProps extends TableToggleCommonProps {}
245
246export interface UseTableInstanceProps<D extends object> {
247 state: TableState<D>;
248 plugins: Array<PluginHook<D>>;
249 dispatch: TableDispatch;
250 columns: Array<ColumnInstance<D>>;
251 allColumns: Array<ColumnInstance<D>>;
252 visibleColumns: Array<ColumnInstance<D>>;
253 headerGroups: Array<HeaderGroup<D>>;
254 footerGroups: Array<HeaderGroup<D>>;
255 headers: Array<ColumnInstance<D>>;
256 flatHeaders: Array<ColumnInstance<D>>;
257 rows: Array<Row<D>>;
258 rowsById: Record<string, Row<D>>;
259 getTableProps: (propGetter?: TablePropGetter<D>) => TableProps;
260 getTableBodyProps: (propGetter?: TableBodyPropGetter<D>) => TableBodyProps;
261 prepareRow: (row: Row<D>) => void;
262 flatRows: Array<Row<D>>;
263 totalColumnsWidth: number;
264 allColumnsHidden: boolean;
265 toggleHideColumn: (columnId: IdType<D>, value?: boolean) => void;
266 setHiddenColumns: (param: Array<IdType<D>> | UpdateHiddenColumns<D>) => void;
267 toggleHideAllColumns: (value?: boolean) => void;
268 getToggleHideAllColumnsProps: (props?: Partial<TableToggleHideAllColumnProps>) => TableToggleHideAllColumnProps;
269 getHooks: () => Hooks<D>;
270}
271
272export interface UseTableHeaderGroupProps<D extends object> {
273 headers: Array<HeaderGroup<D>>;
274 getHeaderGroupProps: (propGetter?: HeaderGroupPropGetter<D>) => TableHeaderProps;
275 getFooterGroupProps: (propGetter?: FooterGroupPropGetter<D>) => TableFooterProps;
276 totalHeaderCount: number; // not documented
277}
278
279export interface UseTableColumnProps<D extends object> {
280 id: IdType<D>;
281 columns?: Array<ColumnInstance<D>> | undefined;
282 isVisible: boolean;
283 render: (type: "Header" | "Footer" | string, props?: object) => ReactNode;
284 totalLeft: number;
285 totalWidth: number;
286 getHeaderProps: (propGetter?: HeaderPropGetter<D>) => TableHeaderProps;
287 getFooterProps: (propGetter?: FooterPropGetter<D>) => TableFooterProps;
288 toggleHidden: (value?: boolean) => void;
289 parent?: ColumnInstance<D> | undefined; // not documented
290 getToggleHiddenProps: (userProps?: any) => any;
291 depth: number; // not documented
292 placeholderOf?: ColumnInstance | undefined;
293}
294
295export interface UseTableRowProps<D extends object> {
296 cells: Array<Cell<D>>;
297 allCells: Array<Cell<D>>;
298 values: Record<IdType<D>, CellValue>;
299 getRowProps: (propGetter?: RowPropGetter<D>) => TableRowProps;
300 index: number;
301 original: D;
302 id: string;
303 subRows: Array<Row<D>>;
304}
305
306export interface UseTableCellProps<D extends object, V = any> {
307 column: ColumnInstance<D>;
308 row: Row<D>;
309 value: CellValue<V>;
310 getCellProps: (propGetter?: CellPropGetter<D>) => TableCellProps;
311 render: (type: "Cell" | string, userProps?: object) => ReactNode;
312}
313
314export type HeaderProps<D extends object> = TableInstance<D> & {
315 column: ColumnInstance<D>;
316};
317
318export type FooterProps<D extends object> = TableInstance<D> & {
319 column: ColumnInstance<D>;
320};
321
322export type CellProps<D extends object, V = any> = TableInstance<D> & {
323 column: ColumnInstance<D>;
324 row: Row<D>;
325 cell: Cell<D, V>;
326 value: CellValue<V>;
327};
328
329export type Accessor<D extends object> = (
330 originalRow: D,
331 index: number,
332 sub: {
333 subRows: D[];
334 depth: number;
335 data: D[];
336 },
337) => CellValue;
338
339// #endregion
340
341// Plugins
342
343// #region useAbsoluteLayout
344export function useAbsoluteLayout<D extends object = {}>(hooks: Hooks<D>): void;
345
346export namespace useAbsoluteLayout {
347 const pluginName = "useAbsoluteLayout";
348}
349// #endregion
350
351// #region useBlockLayout
352export function useBlockLayout<D extends object = {}>(hooks: Hooks<D>): void;
353
354export namespace useBlockLayout {
355 const pluginName = "useBlockLayout";
356}
357// #endregion
358
359// #region useColumnOrder
360export function useColumnOrder<D extends object = {}>(hooks: Hooks<D>): void;
361
362export namespace useColumnOrder {
363 const pluginName = "useColumnOrder";
364}
365
366export interface UseColumnOrderState<D extends object> {
367 columnOrder: Array<IdType<D>>;
368}
369
370export interface UseColumnOrderInstanceProps<D extends object> {
371 setColumnOrder: (updater: ((columnOrder: Array<IdType<D>>) => Array<IdType<D>>) | Array<IdType<D>>) => void;
372}
373
374// #endregion
375
376// #region useExpanded
377export function useExpanded<D extends object = {}>(hooks: Hooks<D>): void;
378
379export namespace useExpanded {
380 const pluginName = "useExpanded";
381}
382
383export interface TableExpandedToggleProps extends TableKeyedProps {}
384
385export type UseExpandedOptions<D extends object> = Partial<{
386 manualExpandedKey: IdType<D>;
387 paginateExpandedRows: boolean;
388 expandSubRows: boolean;
389 autoResetExpanded?: boolean | undefined;
390}>;
391
392export interface UseExpandedHooks<D extends object> {
393 getToggleRowsExpandedProps: Array<PropGetter<D, TableCommonProps>>;
394 getToggleAllRowsExpandedProps: Array<PropGetter<D, TableCommonProps>>;
395}
396
397export interface UseExpandedState<D extends object> {
398 expanded: Record<IdType<D>, boolean>;
399}
400
401export interface UseExpandedInstanceProps<D extends object> {
402 preExpandedRows: Array<Row<D>>;
403 expandedRows: Array<Row<D>>;
404 rows: Array<Row<D>>;
405 expandedDepth: number;
406 isAllRowsExpanded: boolean;
407 toggleRowExpanded: (id: Array<IdType<D>>, value?: boolean) => void;
408 toggleAllRowsExpanded: (value?: boolean) => void;
409}
410
411export interface UseExpandedRowProps<D extends object> {
412 isExpanded: boolean;
413 canExpand: boolean;
414 subRows: Array<Row<D>>;
415 toggleRowExpanded: (value?: boolean) => void;
416 getToggleRowExpandedProps: (props?: Partial<TableExpandedToggleProps>) => TableExpandedToggleProps;
417 depth: number;
418}
419
420// #endregion
421
422// #region useFilters
423export function useFilters<D extends object = {}>(hooks: Hooks<D>): void;
424
425export namespace useFilters {
426 const pluginName = "useFilters";
427}
428
429export type UseFiltersOptions<D extends object> = Partial<{
430 manualFilters: boolean;
431 disableFilters: boolean;
432 defaultCanFilter: boolean;
433 filterTypes: FilterTypes<D>;
434 autoResetFilters?: boolean | undefined;
435}>;
436
437export interface UseFiltersState<D extends object> {
438 filters: Filters<D>;
439}
440
441export type UseFiltersColumnOptions<D extends object> = Partial<{
442 Filter: Renderer<FilterProps<D>>;
443 disableFilters: boolean;
444 defaultCanFilter: boolean;
445 filter: FilterType<D> | DefaultFilterTypes | string;
446}>;
447
448export interface UseFiltersInstanceProps<D extends object> {
449 preFilteredRows: Array<Row<D>>;
450 preFilteredFlatRows: Array<Row<D>>;
451 preFilteredRowsById: Record<string, Row<D>>;
452 filteredRows: Array<Row<D>>;
453 filteredFlatRows: Array<Row<D>>;
454 filteredRowsById: Record<string, Row<D>>;
455 rows: Array<Row<D>>;
456 flatRows: Array<Row<D>>;
457 rowsById: Record<string, Row<D>>;
458 setFilter: (columnId: IdType<D>, updater: ((filterValue: FilterValue) => FilterValue) | FilterValue) => void;
459 setAllFilters: (updater: Filters<D> | ((filters: Filters<D>) => Filters<D>)) => void;
460}
461
462export interface UseFiltersColumnProps<D extends object> {
463 canFilter: boolean;
464 setFilter: (updater: ((filterValue: FilterValue) => FilterValue) | FilterValue) => void;
465 filterValue: FilterValue;
466 preFilteredRows: Array<Row<D>>;
467 filteredRows: Array<Row<D>>;
468}
469
470export type FilterProps<D extends object> = HeaderProps<D>;
471export type FilterValue = any;
472export type Filters<D extends object> = Array<{ id: IdType<D>; value: FilterValue }>;
473export type FilterTypes<D extends object> = Record<string, FilterType<D>>;
474
475export type DefaultFilterTypes =
476 | "text"
477 | "exactText"
478 | "exactTextCase"
479 | "includes"
480 | "includesAll"
481 | "exact"
482 | "equals"
483 | "between";
484
485export interface FilterType<D extends object> {
486 (rows: Array<Row<D>>, columnIds: Array<IdType<D>>, filterValue: FilterValue): Array<Row<D>>;
487
488 autoRemove?: ((filterValue: FilterValue) => boolean) | undefined;
489}
490
491// #endregion
492
493// #region useFlexLayout
494export function useFlexLayout<D extends object = {}>(hooks: Hooks<D>): void;
495
496export namespace useFlexLayout {
497 const pluginName = "useFlexLayout";
498}
499// #endregion
500
501// #region useGridLayout
502export function useGridLayout<D extends object = {}>(hooks: Hooks<D>): void;
503
504export namespace useGridLayout {
505 const pluginName = "useGridLayout";
506}
507// #endregion
508
509// #region useGlobalFilter
510export function useGlobalFilter<D extends object = {}>(hooks: Hooks<D>): void;
511
512export namespace useGlobalFilter {
513 const pluginName = "useGlobalFilter";
514}
515
516export type UseGlobalFiltersOptions<D extends object> = Partial<{
517 globalFilter: ((rows: Array<Row<D>>, columnIds: Array<IdType<D>>, filterValue: any) => Array<Row<D>>) | string;
518 manualGlobalFilter: boolean;
519 filterTypes: FilterTypes<D>;
520 autoResetGlobalFilter?: boolean | undefined;
521 disableGlobalFilter?: boolean | undefined;
522}>;
523
524export interface UseGlobalFiltersState<D extends object> {
525 globalFilter: any;
526}
527
528export type UseGlobalFiltersColumnOptions<D extends object> = Partial<{
529 disableGlobalFilter?: boolean | undefined;
530}>;
531
532export interface UseGlobalFiltersInstanceProps<D extends object> {
533 preGlobalFilteredRows: Array<Row<D>>;
534 preGlobalFilteredFlatRows: Array<Row<D>>;
535 preGlobalFilteredRowsById: Record<string, Row<D>>;
536 globalFilteredRows: Array<Row<D>>;
537 globalFilteredFlatRows: Array<Row<D>>;
538 globalFilteredRowsById: Record<string, Row<D>>;
539 rows: Array<Row<D>>;
540 flatRows: Array<Row<D>>;
541 rowsById: Record<string, Row<D>>;
542 setGlobalFilter: (filterValue: FilterValue) => void;
543}
544
545// #endregion
546
547// #region useGroupBy
548export function useGroupBy<D extends object = {}>(hooks: Hooks<D>): void;
549
550export namespace useGroupBy {
551 const pluginName = "useGroupBy";
552}
553
554export interface TableGroupByToggleProps {
555 title?: string | undefined;
556 style?: CSSProperties | undefined;
557 onClick?: ((e: MouseEvent) => void) | undefined;
558}
559
560export type UseGroupByOptions<D extends object> = Partial<{
561 manualGroupBy: boolean;
562 disableGroupBy: boolean;
563 defaultCanGroupBy: boolean;
564 aggregations: Record<string, AggregatorFn<D>>;
565 groupByFn: (rows: Array<Row<D>>, columnId: IdType<D>) => Record<string, Array<Row<D>>>;
566 autoResetGroupBy?: boolean | undefined;
567}>;
568
569export interface UseGroupByHooks<D extends object> {
570 getGroupByToggleProps: Array<HeaderGroupPropGetter<D>>;
571}
572
573export interface UseGroupByState<D extends object> {
574 groupBy: Array<IdType<D>>;
575}
576
577export type UseGroupByColumnOptions<D extends object> = Partial<{
578 aggregate: Aggregator<D>;
579 Aggregated: Renderer<CellProps<D>>;
580 disableGroupBy: boolean;
581 defaultCanGroupBy: boolean;
582}>;
583
584export interface UseGroupByInstanceProps<D extends object> {
585 preGroupedRows: Array<Row<D>>;
586 preGroupedFlatRows: Array<Row<D>>;
587 preGroupedRowsById: Record<string, Row<D>>;
588 groupedRows: Array<Row<D>>;
589 groupedFlatRows: Array<Row<D>>;
590 groupedRowsById: Record<string, Row<D>>;
591 onlyGroupedFlatRows: Array<Row<D>>;
592 onlyGroupedRowsById: Record<string, Row<D>>;
593 nonGroupedFlatRows: Array<Row<D>>;
594 nonGroupedRowsById: Record<string, Row<D>>;
595 rows: Array<Row<D>>;
596 flatRows: Array<Row<D>>;
597 rowsById: Record<string, Row<D>>;
598 toggleGroupBy: (columnId: IdType<D>, value?: boolean) => void;
599}
600
601export interface UseGroupByColumnProps<D extends object> {
602 canGroupBy: boolean;
603 isGrouped: boolean;
604 groupedIndex: number;
605 toggleGroupBy: () => void;
606 getGroupByToggleProps: (props?: Partial<TableGroupByToggleProps>) => TableGroupByToggleProps;
607}
608
609export interface UseGroupByRowProps<D extends object> {
610 isGrouped: boolean;
611 groupByID: IdType<D>;
612 groupByVal: string;
613 values: Record<IdType<D>, AggregatedValue>;
614 subRows: Array<Row<D>>;
615 leafRows: Array<Row<D>>;
616 depth: number;
617 id: string;
618 index: number;
619}
620
621export interface UseGroupByCellProps<D extends object> {
622 isGrouped: boolean;
623 isPlaceholder: boolean;
624 isAggregated: boolean;
625}
626
627export type DefaultAggregators = "sum" | "average" | "median" | "uniqueCount" | "count";
628
629export type AggregatorFn<D extends object> = (
630 columnValues: CellValue[],
631 rows: Array<Row<D>>,
632 isAggregated: boolean,
633) => AggregatedValue;
634export type Aggregator<D extends object> = AggregatorFn<D> | DefaultAggregators | string;
635export type AggregatedValue = any;
636// #endregion
637
638// #region usePagination
639export function usePagination<D extends object = {}>(hooks: Hooks<D>): void;
640
641export namespace usePagination {
642 const pluginName = "usePagination";
643}
644
645export type UsePaginationOptions<D extends object> = Partial<{
646 pageCount: number;
647 manualPagination: boolean;
648 autoResetPage?: boolean | undefined;
649 paginateExpandedRows: boolean;
650}>;
651
652export interface UsePaginationState<D extends object> {
653 pageSize: number;
654 pageIndex: number;
655}
656
657export interface UsePaginationInstanceProps<D extends object> {
658 page: Array<Row<D>>;
659 pageCount: number;
660 pageOptions: number[];
661 canPreviousPage: boolean;
662 canNextPage: boolean;
663 gotoPage: (updater: ((pageIndex: number) => number) | number) => void;
664 previousPage: () => void;
665 nextPage: () => void;
666 setPageSize: (pageSize: number) => void;
667}
668
669// #endregion
670
671// #region useResizeColumns
672export function useResizeColumns<D extends object = {}>(hooks: Hooks<D>): void;
673
674export namespace useResizeColumns {
675 const pluginName = "useResizeColumns";
676}
677
678export interface UseResizeColumnsOptions<D extends object> {
679 disableResizing?: boolean | undefined;
680 autoResetResize?: boolean | undefined;
681}
682
683export interface UseResizeColumnsState<D extends object> {
684 columnResizing: {
685 startX?: number | undefined;
686 columnWidth: number;
687 headerIdWidths: Record<string, number>;
688 columnWidths: any;
689 isResizingColumn?: string | undefined;
690 };
691}
692
693export interface UseResizeColumnsColumnOptions<D extends object> {
694 disableResizing?: boolean | undefined;
695}
696
697export interface TableResizerProps {}
698
699export interface UseResizeColumnsColumnProps<D extends object> {
700 getResizerProps: (props?: Partial<TableResizerProps>) => TableResizerProps;
701 canResize: boolean;
702 isResizing: boolean;
703}
704
705// #endregion
706
707// #region useRowSelect
708export function useRowSelect<D extends object = {}>(hooks: Hooks<D>): void;
709
710export namespace useRowSelect {
711 const pluginName = "useRowSelect";
712}
713
714export interface TableToggleAllRowsSelectedProps extends TableToggleCommonProps {}
715
716export interface TableToggleRowsSelectedProps extends TableToggleCommonProps {}
717
718export type UseRowSelectOptions<D extends object> = Partial<{
719 manualRowSelectedKey: IdType<D>;
720 autoResetSelectedRows: boolean;
721 selectSubRows: boolean;
722}>;
723
724export interface UseRowSelectHooks<D extends object> {
725 getToggleRowSelectedProps: Array<PropGetter<D, TableToggleRowsSelectedProps>>;
726 getToggleAllRowsSelectedProps: Array<PropGetter<D, TableToggleAllRowsSelectedProps>>;
727 getToggleAllPageRowsSelectedProps: Array<PropGetter<D, TableToggleAllRowsSelectedProps>>;
728}
729
730export interface UseRowSelectState<D extends object> {
731 selectedRowIds: Record<IdType<D>, boolean>;
732}
733
734export interface UseRowSelectInstanceProps<D extends object> {
735 toggleRowSelected: (rowId: IdType<D>, set?: boolean) => void;
736 toggleAllRowsSelected: (value?: boolean) => void;
737 getToggleAllRowsSelectedProps: (
738 props?: Partial<TableToggleAllRowsSelectedProps>,
739 ) => TableToggleAllRowsSelectedProps;
740 getToggleAllPageRowsSelectedProps: (
741 props?: Partial<TableToggleAllRowsSelectedProps>,
742 ) => TableToggleAllRowsSelectedProps;
743 isAllRowsSelected: boolean;
744 selectedFlatRows: Array<Row<D>>;
745}
746
747export interface UseRowSelectRowProps<D extends object> {
748 isSelected: boolean;
749 isSomeSelected: boolean;
750 toggleRowSelected: (set?: boolean) => void;
751 getToggleRowSelectedProps: (props?: Partial<TableToggleRowsSelectedProps>) => TableToggleRowsSelectedProps;
752}
753
754// #endregion
755
756// #region useRowState
757export function useRowState<D extends object = {}>(hooks: Hooks<D>): void;
758
759export namespace useRowState {
760 const pluginName = "useRowState";
761}
762
763export type UseRowStateOptions<D extends object> = Partial<{
764 initialRowStateAccessor: (row: Row<D>) => UseRowStateLocalState<D>;
765 getResetRowStateDeps: (instance: TableInstance<D>) => any[];
766 autoResetRowState?: boolean | undefined;
767}>;
768
769export interface UseRowStateState<D extends object> {
770 rowState: Record<string, { cellState: UseRowStateLocalState<D> }>;
771}
772
773export interface UseRowStateInstanceProps<D extends object> {
774 setRowState: (rowPath: string[], updater: UseRowUpdater) => void;
775 setCellState: (rowPath: string[], columnId: IdType<D>, updater: UseRowUpdater) => void;
776}
777
778export interface UseRowStateRowProps<D extends object> {
779 state: UseRowStateLocalState<D>;
780 setState: (updater: UseRowUpdater) => void;
781}
782
783export interface UseRowStateCellProps<D extends object> {
784 state: UseRowStateLocalState<D>;
785 setState: (updater: UseRowUpdater) => void;
786}
787
788export type UseRowUpdater<T = unknown> = T | ((prev: T) => T);
789export type UseRowStateLocalState<D extends object, T = unknown> = Record<IdType<D>, T>;
790// #endregion
791
792// #region useSortBy
793export function useSortBy<D extends object = {}>(hooks: Hooks<D>): void;
794
795export namespace useSortBy {
796 const pluginName = "useSortBy";
797}
798
799export interface TableSortByToggleProps {
800 title?: string | undefined;
801 style?: CSSProperties | undefined;
802 onClick?: ((e: MouseEvent) => void) | undefined;
803}
804
805export type UseSortByOptions<D extends object> = Partial<{
806 manualSortBy: boolean;
807 disableSortBy: boolean;
808 defaultCanSort: boolean;
809 disableMultiSort: boolean;
810 isMultiSortEvent: (e: MouseEvent) => boolean;
811 maxMultiSortColCount: number;
812 disableSortRemove: boolean;
813 disabledMultiRemove: boolean;
814 orderByFn: (rows: Array<Row<D>>, sortFns: Array<OrderByFn<D>>, directions: boolean[]) => Array<Row<D>>;
815 sortTypes: Record<string, SortByFn<D>>;
816 autoResetSortBy?: boolean | undefined;
817}>;
818
819export interface UseSortByHooks<D extends object> {
820 getSortByToggleProps: Array<PropGetter<D, TableCommonProps>>;
821}
822
823export interface UseSortByState<D extends object> {
824 sortBy: Array<SortingRule<D>>;
825}
826
827export type UseSortByColumnOptions<D extends object> = Partial<{
828 defaultCanSort: boolean;
829 disableSortBy: boolean;
830 sortDescFirst: boolean;
831 sortInverted: boolean;
832 sortType: SortByFn<D> | DefaultSortTypes | string;
833}>;
834
835export interface UseSortByInstanceProps<D extends object> {
836 rows: Array<Row<D>>;
837 preSortedRows: Array<Row<D>>;
838 setSortBy: (sortBy: Array<SortingRule<D>>) => void;
839 toggleSortBy: (columnId: IdType<D>, descending?: boolean, isMulti?: boolean) => void;
840}
841
842export interface UseSortByColumnProps<D extends object> {
843 canSort: boolean;
844 toggleSortBy: (descending?: boolean, multi?: boolean) => void;
845 getSortByToggleProps: (props?: Partial<TableSortByToggleProps>) => TableSortByToggleProps;
846 clearSortBy: () => void;
847 isSorted: boolean;
848 sortedIndex: number;
849 isSortedDesc: boolean | undefined;
850}
851
852export type OrderByFn<D extends object> = (rowA: Row<D>, rowB: Row<D>) => number;
853export type SortByFn<D extends object> = (rowA: Row<D>, rowB: Row<D>, columnId: IdType<D>, desc?: boolean) => number;
854
855export type DefaultSortTypes = "alphanumeric" | "datetime" | "basic" | "string" | "number";
856
857export interface SortingRule<D> {
858 id: IdType<D>;
859 desc?: boolean | undefined;
860}
861
862// #endregion
863
864// Additional API
865export const actions: Record<string, string>;
866export type ActionType = { type: string } & Record<string, any>;
867export const defaultColumn: Partial<Column> & Record<string, any>;
868
869// Helpers
870export type StringKey<D> = Extract<keyof D, string>;
871export type IdType<D> = StringKey<D> | string;
872export type CellValue<V = any> = V;
873
874export type Renderer<Props> = ComponentType<Props> | ReactElement | string | number | readonly ReactNode[];
875
876export interface PluginHook<D extends object> {
877 (hooks: Hooks<D>): void;
878 pluginName?: string | undefined;
879}
880
881export type TableDispatch<A = any> = (action: A) => void;
882
883// utils
884export function defaultOrderByFn<D extends object = {}>(
885 arr: Array<Row<D>>,
886 funcs: Array<OrderByFn<D>>,
887 dirs: boolean[],
888): Array<Row<D>>;
889
890export function defaultGroupByFn<D extends object = {}>(
891 rows: Array<Row<D>>,
892 columnId: IdType<D>,
893): Record<string, Array<Row<D>>>;
894
895export function makePropGetter(hooks: Hooks, ...meta: any[]): any;
896
897export function reduceHooks<T extends object = {}>(hooks: Hooks, initial: T, ...args: any[]): T;
898
899export function loopHooks(hooks: Hooks, ...args: any[]): void;
900
901export function ensurePluginOrder<D extends object = {}>(
902 plugins: Array<PluginHook<D>>,
903 befores: string[],
904 pluginName: string,
905): void;
906
907export function functionalUpdate<D extends object = {}>(
908 updater: any,
909 old: Partial<TableState<D>>,
910): Partial<TableState<D>>;
911
912export function useGetLatest<T>(obj: T): () => T;
913
914export function safeUseLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
915
916export function useMountedLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
917
918export function useAsyncDebounce<F extends (...args: any[]) => any>(defaultFn: F, defaultWait?: number): F;
919
920export function makeRenderer(instance: TableInstance, column: ColumnInstance, meta?: any): ReactElement;