mantine-datatable 9.3.1 → 9.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,1046 +1,1010 @@
1
- import * as react from 'react';
2
- import { JSX, Ref, RefObject } from 'react';
3
- import { PopoverProps, MantineTheme, MantineStyleProp, TableTrProps, MantineSize, TextProps, PaginationProps, MantineColor, MantineLoader, CollapseProps, CheckboxProps, StylesRecord, MantineShadow, ScrollAreaProps, TableProps } from '@mantine/core';
4
- import { DropResult } from '@hello-pangea/dnd';
5
-
6
- type DataTableColumnTextAlign = 'left' | 'center' | 'right';
7
-
8
- type DataTableColumn<T = Record<string, unknown>> = {
9
- /**
10
- * Column accessor.
11
- * You can use dot-notation for nested objects property drilling.
12
- * (i.e. `department.name` or `department.company.name`)
13
- */
14
- accessor: keyof T | (string & NonNullable<unknown>);
15
- /**
16
- * Optional column header title.
17
- * If not present, one will be generated by "humanizing" the provided column accessor.
18
- * (i.e. `firstName` -> `First name`; `user.firstName` -> `User first name`)
19
- */
20
- title?: React.ReactNode;
21
- /**
22
- * Custom cell data render function.
23
- * Accepts the current record and its index in `records` as arguments and returns a React node
24
- * (remember that a string is a valid React node too).
25
- */
26
- render?: (record: T, index: number) => React.ReactNode;
27
- /**
28
- * Column text alignment.
29
- * @default `left`
30
- */
31
- textAlign?: DataTableColumnTextAlign;
32
- /**
33
- * If true, column will be sortable.
34
- */
35
- sortable?: boolean;
36
- sortKey?: string;
37
- /**
38
- * If set to true, the column can be dragged.
39
- */
40
- draggable?: boolean;
41
- /**
42
- * If set to true, the column can be toggled.
43
- */
44
- toggleable?: boolean;
45
- /**
46
- * If set to true, the column can be resized.
47
- */
48
- resizable?: boolean;
49
- /**
50
- * If set, the column will be pinned to the specified side of the table.
51
- * If `pinnable` is false or undefined, this is a static pin (not changeable by user).
52
- * If `pinnable` is true, this is the initial pinning state (user can change it).
53
- */
54
- pinned?: 'left' | 'right';
55
- /**
56
- * If set to true, the column can be pinned/unpinned by the user via UI.
57
- * When true, `pinned` acts as the initial pinning state.
58
- */
59
- pinnable?: boolean;
60
- /**
61
- * If set to true, the column will be toggled by default.
62
- */
63
- defaultToggle?: boolean;
64
- /**
65
- * Optional node providing the user with filtering options.
66
- * If present, a filter button will be added to the column's header. Upon clicking that button,
67
- * a pop-over showing the provided node will be opened.
68
- *
69
- * Alternatively, a function returning a node can be provided. The function receives props with a `close`
70
- * method which allows programmatically closing the pop-over.
71
- *
72
- * ```tsx
73
- * // …
74
- * columns={[
75
- * {
76
- * accessor: 'name',
77
- * filter: ({ close }) => {
78
- * return <Stack>
79
- * <Button onClick={() => { setFilter(undefined); close(); }}>Reset</Button>
80
- * </Stack>
81
- * },
82
- * }
83
- * ]}
84
- * // …
85
- * ```
86
- *
87
- * Note: this property only takes care of rendering the node which provides the filtering options.
88
- * It is assumed that the actual filtering is performed somewhere in user code.
89
- */
90
- filter?: React.ReactNode | ((params: {
91
- close: () => void;
92
- }) => React.ReactNode);
93
- /**
94
- * Filter popover props; override if necessary.
95
- */
96
- filterPopoverProps?: PopoverProps;
97
- /**
98
- * Disables the use of the Mantine useClickOutside hook inside the filter popover
99
- */
100
- filterPopoverDisableClickOutside?: boolean;
101
- /**
102
- * If true, filter icon will be styled differently to indicate the filter is in effect.
103
- */
104
- filtering?: boolean;
105
- /**
106
- * Desired column width.
107
- */
108
- width?: string | number;
109
- /**
110
- * If true, column will not be visible.
111
- */
112
- hidden?: boolean;
113
- /**
114
- * If true, tbody cells will not be visible.
115
- */
116
- hiddenContent?: boolean;
117
- /**
118
- * If set, the column will only be visible according to the specified media query.
119
- * Can be a string, or a function receiving the current theme and returning a string.
120
- */
121
- visibleMediaQuery?: string | ((theme: MantineTheme) => string);
122
- /**
123
- * Optional class name passed to the column title
124
- */
125
- titleClassName?: string;
126
- /**
127
- * Optional style passed to the column title.
128
- * Either a style object, or a function receiving the current theme and returning a style object.
129
- */
130
- titleStyle?: MantineStyleProp;
131
- /**
132
- * Optional class name passed to each data cell in the column.
133
- * Can be a string, or a function receiving the current record and its index
134
- * as arguments and returning a string.
135
- */
136
- cellsClassName?: string | ((record: T, index: number) => string | undefined);
137
- /**
138
- * Optional style passed to each data cell in the column.
139
- * A function that receives the current record and its index as arguments and returns either
140
- * a style object, or a function that accepts theme and returns a style object.
141
- */
142
- cellsStyle?: (record: T, index: number) => MantineStyleProp | undefined;
143
- /**
144
- * Optional function returning an object of custom attributes to be applied to each cell in the column.
145
- * Receives the current record and its index as arguments.
146
- * Useful for adding data attributes, handling middle-clicks, etc.
147
- */
148
- customCellAttributes?: (record: T, index: number) => Record<string, unknown>;
149
- /**
150
- * Optional column footer content.
151
- * If at least one column has a footer, the table will display a footer row.
152
- */
153
- footer?: React.ReactNode;
154
- /**
155
- * Optional class name passed to the column footer.
156
- */
157
- footerClassName?: string;
158
- /**
159
- * Optional style passed to the column footer.
160
- */
161
- footerStyle?: MantineStyleProp;
1
+ import { CheckboxProps, CollapseProps, MantineColor, MantineLoader, MantineShadow, MantineSize, MantineStyleProp, MantineTheme, PaginationProps, PopoverProps, ScrollAreaProps, StylesRecord, TableProps, TableTrProps, TextProps } from "@mantine/core";
2
+ import { JSX, Ref, RefObject } from "react";
3
+ import { DropResult } from "@hello-pangea/dnd";
4
+ export type DataTableColumnTextAlign = "left" | "center" | "right";
5
+ export type DataTableColumn<T = Record<string, unknown>> = {
6
+ /**
7
+ * Column accessor.
8
+ * You can use dot-notation for nested objects property drilling.
9
+ * (i.e. `department.name` or `department.company.name`)
10
+ */
11
+ accessor: keyof T | (string & NonNullable<unknown>);
12
+ /**
13
+ * Optional column header title.
14
+ * If not present, one will be generated by "humanizing" the provided column accessor.
15
+ * (i.e. `firstName` -> `First name`; `user.firstName` -> `User first name`)
16
+ */
17
+ title?: React.ReactNode;
18
+ /**
19
+ * Custom cell data render function.
20
+ * Accepts the current record and its index in `records` as arguments and returns a React node
21
+ * (remember that a string is a valid React node too).
22
+ */
23
+ render?: (record: T, index: number) => React.ReactNode;
24
+ /**
25
+ * Column text alignment.
26
+ * @default `left`
27
+ */
28
+ textAlign?: DataTableColumnTextAlign;
29
+ /**
30
+ * If true, column will be sortable.
31
+ */
32
+ sortable?: boolean;
33
+ sortKey?: string;
34
+ /**
35
+ * If set to true, the column can be dragged.
36
+ */
37
+ draggable?: boolean;
38
+ /**
39
+ * If set to true, the column can be toggled.
40
+ */
41
+ toggleable?: boolean;
42
+ /**
43
+ * If set to true, the column can be resized.
44
+ */
45
+ resizable?: boolean;
46
+ /**
47
+ * If set, the column will be pinned to the specified side of the table.
48
+ * If `pinnable` is false or undefined, this is a static pin (not changeable by user).
49
+ * If `pinnable` is true, this is the initial pinning state (user can change it).
50
+ */
51
+ pinned?: "left" | "right";
52
+ /**
53
+ * If set to true, the column can be pinned/unpinned by the user via UI.
54
+ * When true, `pinned` acts as the initial pinning state.
55
+ */
56
+ pinnable?: boolean;
57
+ /**
58
+ * If set to true, the column will be toggled by default.
59
+ */
60
+ defaultToggle?: boolean;
61
+ /**
62
+ * Optional node providing the user with filtering options.
63
+ * If present, a filter button will be added to the column's header. Upon clicking that button,
64
+ * a pop-over showing the provided node will be opened.
65
+ *
66
+ * Alternatively, a function returning a node can be provided. The function receives props with a `close`
67
+ * method which allows programmatically closing the pop-over.
68
+ *
69
+ * ```tsx
70
+ * // …
71
+ * columns={[
72
+ * {
73
+ * accessor: 'name',
74
+ * filter: ({ close }) => {
75
+ * return <Stack>
76
+ * <Button onClick={() => { setFilter(undefined); close(); }}>Reset</Button>
77
+ * </Stack>
78
+ * },
79
+ * }
80
+ * ]}
81
+ * // …
82
+ * ```
83
+ *
84
+ * Note: this property only takes care of rendering the node which provides the filtering options.
85
+ * It is assumed that the actual filtering is performed somewhere in user code.
86
+ */
87
+ filter?: React.ReactNode | ((params: {
88
+ close: () => void;
89
+ }) => React.ReactNode);
90
+ /**
91
+ * Filter popover props; override if necessary.
92
+ */
93
+ filterPopoverProps?: PopoverProps;
94
+ /**
95
+ * Disables the use of the Mantine useClickOutside hook inside the filter popover
96
+ */
97
+ filterPopoverDisableClickOutside?: boolean;
98
+ /**
99
+ * If true, filter icon will be styled differently to indicate the filter is in effect.
100
+ */
101
+ filtering?: boolean;
102
+ /**
103
+ * Desired column width.
104
+ */
105
+ width?: string | number;
106
+ /**
107
+ * If true, column will not be visible.
108
+ */
109
+ hidden?: boolean;
110
+ /**
111
+ * If true, tbody cells will not be visible.
112
+ */
113
+ hiddenContent?: boolean;
114
+ /**
115
+ * If set, the column will only be visible according to the specified media query.
116
+ * Can be a string, or a function receiving the current theme and returning a string.
117
+ */
118
+ visibleMediaQuery?: string | ((theme: MantineTheme) => string);
119
+ /**
120
+ * Optional class name passed to the column title
121
+ */
122
+ titleClassName?: string;
123
+ /**
124
+ * Optional style passed to the column title.
125
+ * Either a style object, or a function receiving the current theme and returning a style object.
126
+ */
127
+ titleStyle?: MantineStyleProp;
128
+ /**
129
+ * Optional class name passed to each data cell in the column.
130
+ * Can be a string, or a function receiving the current record and its index
131
+ * as arguments and returning a string.
132
+ */
133
+ cellsClassName?: string | ((record: T, index: number) => string | undefined);
134
+ /**
135
+ * Optional style passed to each data cell in the column.
136
+ * A function that receives the current record and its index as arguments and returns either
137
+ * a style object, or a function that accepts theme and returns a style object.
138
+ */
139
+ cellsStyle?: (record: T, index: number) => MantineStyleProp | undefined;
140
+ /**
141
+ * Optional function returning an object of custom attributes to be applied to each cell in the column.
142
+ * Receives the current record and its index as arguments.
143
+ * Useful for adding data attributes, handling middle-clicks, etc.
144
+ */
145
+ customCellAttributes?: (record: T, index: number) => Record<string, unknown>;
146
+ /**
147
+ * Optional column footer content.
148
+ * If at least one column has a footer, the table will display a footer row.
149
+ */
150
+ footer?: React.ReactNode;
151
+ /**
152
+ * Optional class name passed to the column footer.
153
+ */
154
+ footerClassName?: string;
155
+ /**
156
+ * Optional style passed to the column footer.
157
+ */
158
+ footerStyle?: MantineStyleProp;
162
159
  } & ({
163
- /**
164
- * If true, cell content in this column will be truncated with ellipsis as needed and will not wrap
165
- * to multiple lines (i.e. `overflow: hidden; text-overflow: ellipsis`; `white-space: nowrap`).
166
- * On a column, you can either set this property or `noWrap`, but not both.
167
- */
168
- ellipsis?: boolean;
169
- noWrap?: never;
160
+ /**
161
+ * If true, cell content in this column will be truncated with ellipsis as needed and will not wrap
162
+ * to multiple lines (i.e. `overflow: hidden; text-overflow: ellipsis`; `white-space: nowrap`).
163
+ * On a column, you can either set this property or `noWrap`, but not both.
164
+ */
165
+ ellipsis?: boolean;
166
+ noWrap?: never;
170
167
  } | {
171
- ellipsis?: never;
172
- /**
173
- * If true, cell content in this column will not wrap to multiple lines (i.e. `white-space: nowrap`).
174
- * This is useful for columns containing long strings.
175
- * On a column, you can either set this property or `ellipsis`, but not both.
176
- */
177
- noWrap?: boolean;
168
+ ellipsis?: never;
169
+ /**
170
+ * If true, cell content in this column will not wrap to multiple lines (i.e. `white-space: nowrap`).
171
+ * This is useful for columns containing long strings.
172
+ * On a column, you can either set this property or `ellipsis`, but not both.
173
+ */
174
+ noWrap?: boolean;
178
175
  });
179
-
180
- type DataTableCellClickHandler<T = Record<string, unknown>> = (params: {
181
- /**
182
- * Click event.
183
- */
184
- event: React.MouseEvent;
185
- /**
186
- * Clicked record.
187
- */
188
- record: T;
189
- /**
190
- * Clicked record index.
191
- */
192
- index: number;
193
- /**
194
- * Clicked column information.
195
- */
196
- column: DataTableColumn<T>;
197
- /**
198
- * Clicked column index.
199
- */
200
- columnIndex: number;
176
+ export type DataTableCellClickHandler<T = Record<string, unknown>> = (params: {
177
+ /**
178
+ * Click event.
179
+ */
180
+ event: React.MouseEvent;
181
+ /**
182
+ * Clicked record.
183
+ */
184
+ record: T;
185
+ /**
186
+ * Clicked record index.
187
+ */
188
+ index: number;
189
+ /**
190
+ * Clicked column information.
191
+ */
192
+ column: DataTableColumn<T>;
193
+ /**
194
+ * Clicked column index.
195
+ */
196
+ columnIndex: number;
201
197
  }) => void;
202
-
203
- type DataTableColumnGroup<T = Record<string, unknown>> = {
204
- /**
205
- * Used as the `key` prop for the created `<th />`.
206
- */
207
- id: string;
208
- /**
209
- * Component to render inside the column group header.
210
- */
211
- title?: React.ReactNode;
212
- /**
213
- * Text alignment of the column group header.
214
- * @default `left`
215
- */
216
- textAlign?: DataTableColumnTextAlign;
217
- /**
218
- * Columns which are part of the group.
219
- * Optional when groups are provided for multilevel grouping.
220
- */
221
- columns?: DataTableColumn<T>[];
222
- /**
223
- * Nested column groups for multilevel grouping.
224
- * When provided, columns should be omitted.
225
- */
226
- groups?: DataTableColumnGroup<T>[];
227
- /**
228
- * Optional className to apply to the column group header.
229
- */
230
- className?: string;
231
- /**
232
- * Optional style to apply to the column group header.
233
- * Can be a style object or a function which receives the current theme and
234
- * returns a style object.
235
- */
236
- style?: MantineStyleProp;
198
+ export type DataTableColumnGroup<T = Record<string, unknown>> = {
199
+ /**
200
+ * Used as the `key` prop for the created `<th />`.
201
+ */
202
+ id: string;
203
+ /**
204
+ * Component to render inside the column group header.
205
+ */
206
+ title?: React.ReactNode;
207
+ /**
208
+ * Text alignment of the column group header.
209
+ * @default `left`
210
+ */
211
+ textAlign?: DataTableColumnTextAlign;
212
+ /**
213
+ * Columns which are part of the group.
214
+ * Optional when groups are provided for multilevel grouping.
215
+ */
216
+ columns?: DataTableColumn<T>[];
217
+ /**
218
+ * Nested column groups for multilevel grouping.
219
+ * When provided, columns should be omitted.
220
+ */
221
+ groups?: DataTableColumnGroup<T>[];
222
+ /**
223
+ * Optional className to apply to the column group header.
224
+ */
225
+ className?: string;
226
+ /**
227
+ * Optional style to apply to the column group header.
228
+ * Can be a style object or a function which receives the current theme and
229
+ * returns a style object.
230
+ */
231
+ style?: MantineStyleProp;
237
232
  };
238
-
239
- type DataTableDefaultColumnProps<T = Record<string, unknown>> = Omit<DataTableColumn<T>, 'accessor' | 'hidden' | 'visibleMediaQuery' | 'render'>;
240
-
241
- type DataTableDraggableRowProps = {
242
- /**
243
- * Optional class name.
244
- */
245
- className?: string;
246
- /**
247
- * Current dragging status.
248
- */
249
- isDragging?: boolean;
233
+ export type DataTableDefaultColumnProps<T = Record<string, unknown>> = Omit<DataTableColumn<T>, "accessor" | "hidden" | "visibleMediaQuery" | "render">;
234
+ export type DataTableDraggableRowProps = {
235
+ /**
236
+ * Optional class name.
237
+ */
238
+ className?: string;
239
+ /**
240
+ * Current dragging status.
241
+ */
242
+ isDragging?: boolean;
250
243
  } & TableTrProps;
251
-
252
- type DataTableEmptyStateProps = {
253
- /**
254
- * Content to show when no records are available.
255
- * The provided content will be overlaid and centered automatically.
256
- * You can either provide this property or `noRecordsIcon`, but not both.
257
- */
258
- emptyState?: React.ReactNode;
259
- noRecordsIcon?: never;
244
+ export type DataTableEmptyStateProps = {
245
+ /**
246
+ * Content to show when no records are available.
247
+ * The provided content will be overlaid and centered automatically.
248
+ * You can either provide this property or `noRecordsIcon`, but not both.
249
+ */
250
+ emptyState?: React.ReactNode;
251
+ noRecordsIcon?: never;
260
252
  } | {
261
- emptyState?: never;
262
- /**
263
- * Icon to show when no records are available.
264
- * The provided icon will be overlaid and centered automatically.
265
- * You can either provide this property or `emptyState`, but not both.
266
- */
267
- noRecordsIcon?: React.ReactNode;
253
+ emptyState?: never;
254
+ /**
255
+ * Icon to show when no records are available.
256
+ * The provided icon will be overlaid and centered automatically.
257
+ * You can either provide this property or `emptyState`, but not both.
258
+ */
259
+ noRecordsIcon?: React.ReactNode;
268
260
  };
269
-
270
- type DataTableOuterBorderProps = {
271
- withTableBorder?: never;
272
- borderRadius?: never;
261
+ export type DataTableOuterBorderProps = {
262
+ withTableBorder?: never;
263
+ borderRadius?: never;
273
264
  } | {
274
- /**
275
- * If true, table will have border.
276
- */
277
- withTableBorder: boolean;
278
- /**
279
- * Table border radius.
280
- */
281
- borderRadius?: MantineSize | (string & NonNullable<unknown>) | number;
265
+ /**
266
+ * If true, table will have border.
267
+ */
268
+ withTableBorder: boolean;
269
+ /**
270
+ * Table border radius.
271
+ */
272
+ borderRadius?: MantineSize | (string & NonNullable<unknown>) | number;
282
273
  };
283
-
284
274
  type DataTablePageSizeSelectorProps = {
285
- onRecordsPerPageChange?: never;
286
- recordsPerPageOptions?: never;
287
- recordsPerPageLabel?: never;
275
+ onRecordsPerPageChange?: never;
276
+ recordsPerPageOptions?: never;
277
+ recordsPerPageLabel?: never;
288
278
  } | {
289
- /**
290
- * Callback fired a new page size is selected.
291
- * Receives new page size as argument.
292
- */
293
- onRecordsPerPageChange: (recordsPerPage: number) => void;
294
- /**
295
- * Array of page sizes (numbers) to show in records per page selector.
296
- */
297
- recordsPerPageOptions: number[];
298
- /**
299
- * Label for records per page selector.
300
- */
301
- recordsPerPageLabel?: string;
302
- };
303
-
304
- type DataTablePaginationRenderContext = {
305
- state: {
306
- paginationSize: MantineSize;
307
- page: number;
308
- totalPages: number;
309
- totalRecords: number | undefined;
310
- recordsPerPage: number | undefined;
311
- recordsLength: number | undefined;
312
- fetching: boolean | undefined;
313
- from?: number;
314
- to?: number;
315
- isWrapped: boolean;
316
- };
317
- actions: {
318
- setPage: (page: number) => void;
319
- setRecordsPerPage?: (n: number) => void;
320
- };
321
- Controls: {
322
- Text: (props?: Partial<TextProps>) => JSX.Element;
323
- PageSizeSelector: (props?: Partial<DataTablePageSizeSelectorProps>) => JSX.Element | null;
324
- Pagination: (props?: Partial<PaginationProps>) => JSX.Element;
325
- };
279
+ /**
280
+ * Callback fired a new page size is selected.
281
+ * Receives new page size as argument.
282
+ */
283
+ onRecordsPerPageChange: (recordsPerPage: number) => void;
284
+ /**
285
+ * Array of page sizes (numbers) to show in records per page selector.
286
+ */
287
+ recordsPerPageOptions: number[];
288
+ /**
289
+ * Label for records per page selector.
290
+ */
291
+ recordsPerPageLabel?: string;
326
292
  };
327
-
328
- type DataTablePaginationProps = ({
329
- paginationWithEdges?: never;
330
- paginationWithControls?: never;
331
- page?: never;
332
- onPageChange?: never;
333
- totalRecords?: never;
334
- recordsPerPage?: never;
335
- paginationActiveTextColor?: never;
336
- paginationActiveBackgroundColor?: never;
337
- paginationSize?: never;
338
- loadingText?: never;
339
- paginationText?: never;
340
- paginationWrapBreakpoint?: never;
341
- getPaginationControlProps?: never;
342
- getPaginationItemProps?: never;
343
- renderPagination?: never;
344
- } | {
345
- /**
346
- * Whether to show first and last page navigation buttons.
347
- */
348
- paginationWithEdges?: boolean;
349
- /**
350
- * Whether to show next and previous page navigation buttons.
351
- */
352
- paginationWithControls?: boolean;
353
- /**
354
- * Current page number (1-based).
355
- * If provided, a pagination component is shown.
356
- */
293
+ export type DataTablePaginationRenderContext = {
294
+ state: {
295
+ paginationSize: MantineSize;
357
296
  page: number;
358
- /**
359
- * Callback fired after page change.
360
- * Receives the new page number as argument.
361
- */
362
- onPageChange: (page: number) => void;
363
- /**
364
- * Total number of records in the dataset.
365
- */
297
+ totalPages: number;
366
298
  totalRecords: number | undefined;
367
- /**
368
- * Number of records per page.
369
- */
370
- recordsPerPage: number;
371
- /**
372
- * Pagination component size.
373
- * @default `sm`
374
- */
375
- paginationSize?: MantineSize;
376
- /**
377
- * Color applied to active page button text.
378
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
379
- * or an object with `light` and `dark` keys and `MantineColor` values.
380
- * Defaults to white.
381
- */
382
- paginationActiveTextColor?: MantineColor | {
383
- light: MantineColor;
384
- dark: MantineColor;
385
- };
386
- /**
387
- * Color applied to active page button background.
388
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
389
- * or an object with `light` and `dark` keys and `MantineColor` values.
390
- * Defaults to primary theme color.
391
- */
392
- paginationActiveBackgroundColor?: MantineColor | {
393
- light: MantineColor;
394
- dark: MantineColor;
395
- };
396
- /**
397
- * Text to show while records are loading.
398
- */
399
- loadingText?: string;
400
- /**
401
- * Pagination text. Defaults to ```({ from, to, totalRecords }) => `${from}-${to}/${totalRecords}`
402
- * ```
403
- */
404
- paginationText?: (params: {
405
- from: number;
406
- to: number;
407
- totalRecords: number;
408
- }) => React.ReactNode;
409
- /**
410
- * Pagination wrap breakpoints.
411
- * Below this breakpoint the content will be displayed on multiple lines,
412
- * above it the content will be displayed on a single line.
413
- * @default `sm`
414
- */
415
- paginationWrapBreakpoint?: MantineSize | (string & NonNullable<unknown>) | number;
416
- /**
417
- * Function that returns props object for pagination control.
418
- * Useful for improving accessibility.
419
- */
420
- getPaginationControlProps?: (control: 'first' | 'last' | 'previous' | 'next') => Record<string, unknown>;
421
- /**
422
- * Function that returns props object for pagination item (page number button).
423
- */
424
- getPaginationItemProps?: (page: number) => Record<string, unknown>;
425
- /**
426
- * Optional render function to replace the entire pagination component.
427
- */
428
- renderPagination?: (ctx: DataTablePaginationRenderContext) => React.ReactNode;
299
+ recordsPerPage: number | undefined;
300
+ recordsLength: number | undefined;
301
+ fetching: boolean | undefined;
302
+ from?: number;
303
+ to?: number;
304
+ isWrapped: boolean;
305
+ };
306
+ actions: {
307
+ setPage: (page: number) => void;
308
+ setRecordsPerPage?: (n: number) => void;
309
+ };
310
+ Controls: {
311
+ Text: (props?: Partial<TextProps>) => JSX.Element;
312
+ PageSizeSelector: (props?: Partial<DataTablePageSizeSelectorProps>) => JSX.Element | null;
313
+ Pagination: (props?: Partial<PaginationProps>) => JSX.Element;
314
+ };
315
+ };
316
+ export type DataTablePaginationProps = ({
317
+ paginationWithEdges?: never;
318
+ paginationWithControls?: never;
319
+ page?: never;
320
+ onPageChange?: never;
321
+ totalRecords?: never;
322
+ recordsPerPage?: never;
323
+ paginationActiveTextColor?: never;
324
+ paginationActiveBackgroundColor?: never;
325
+ paginationSize?: never;
326
+ loadingText?: never;
327
+ paginationText?: never;
328
+ paginationWrapBreakpoint?: never;
329
+ getPaginationControlProps?: never;
330
+ getPaginationItemProps?: never;
331
+ renderPagination?: never;
332
+ } | {
333
+ /**
334
+ * Whether to show first and last page navigation buttons.
335
+ */
336
+ paginationWithEdges?: boolean;
337
+ /**
338
+ * Whether to show next and previous page navigation buttons.
339
+ */
340
+ paginationWithControls?: boolean;
341
+ /**
342
+ * Current page number (1-based).
343
+ * If provided, a pagination component is shown.
344
+ */
345
+ page: number;
346
+ /**
347
+ * Callback fired after page change.
348
+ * Receives the new page number as argument.
349
+ */
350
+ onPageChange: (page: number) => void;
351
+ /**
352
+ * Total number of records in the dataset.
353
+ */
354
+ totalRecords: number | undefined;
355
+ /**
356
+ * Number of records per page.
357
+ */
358
+ recordsPerPage: number;
359
+ /**
360
+ * Pagination component size.
361
+ * @default `sm`
362
+ */
363
+ paginationSize?: MantineSize;
364
+ /**
365
+ * Color applied to active page button text.
366
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
367
+ * or an object with `light` and `dark` keys and `MantineColor` values.
368
+ * Defaults to white.
369
+ */
370
+ paginationActiveTextColor?: MantineColor | {
371
+ light: MantineColor;
372
+ dark: MantineColor;
373
+ };
374
+ /**
375
+ * Color applied to active page button background.
376
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
377
+ * or an object with `light` and `dark` keys and `MantineColor` values.
378
+ * Defaults to primary theme color.
379
+ */
380
+ paginationActiveBackgroundColor?: MantineColor | {
381
+ light: MantineColor;
382
+ dark: MantineColor;
383
+ };
384
+ /**
385
+ * Text to show while records are loading.
386
+ */
387
+ loadingText?: string;
388
+ /**
389
+ * Pagination text. Defaults to ```({ from, to, totalRecords }) => `${from}-${to}/${totalRecords}`
390
+ * ```
391
+ */
392
+ paginationText?: (params: {
393
+ from: number;
394
+ to: number;
395
+ totalRecords: number;
396
+ }) => React.ReactNode;
397
+ /**
398
+ * Pagination wrap breakpoints.
399
+ * Below this breakpoint the content will be displayed on multiple lines,
400
+ * above it the content will be displayed on a single line.
401
+ * @default `sm`
402
+ */
403
+ paginationWrapBreakpoint?: MantineSize | (string & NonNullable<unknown>) | number;
404
+ /**
405
+ * Function that returns props object for pagination control.
406
+ * Useful for improving accessibility.
407
+ */
408
+ getPaginationControlProps?: (control: "first" | "last" | "previous" | "next") => Record<string, unknown>;
409
+ /**
410
+ * Function that returns props object for pagination item (page number button).
411
+ */
412
+ getPaginationItemProps?: (page: number) => Record<string, unknown>;
413
+ /**
414
+ * Optional render function to replace the entire pagination component.
415
+ */
416
+ renderPagination?: (ctx: DataTablePaginationRenderContext) => React.ReactNode;
429
417
  }) & DataTablePageSizeSelectorProps;
430
-
431
418
  type DataTableColorProps<T> = {
432
- /**
433
- * Data table text color.
434
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
435
- * or an object with `light` and `dark` keys and `MantineColor` values.
436
- */
437
- c?: MantineColor | {
438
- light: MantineColor;
439
- dark: MantineColor;
440
- };
441
- /**
442
- * Data table background color.
443
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
444
- * or an object with `light` and `dark` keys and `MantineColor` values.
445
- */
446
- backgroundColor?: MantineColor | {
447
- light: MantineColor;
448
- dark: MantineColor;
449
- };
450
- /**
451
- * Color of table borders, applied to all borders except row borders.
452
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
453
- * or an object with `light` and `dark` keys and `MantineColor` values.
454
- */
455
- borderColor?: MantineColor | {
456
- light: MantineColor;
457
- dark: MantineColor;
458
- };
459
- /**
460
- * Color of row borders.
461
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
462
- * or an object with `light` and `dark` keys and `MantineColor` values.
463
- */
464
- rowBorderColor?: MantineColor | {
465
- light: MantineColor;
466
- dark: MantineColor;
467
- };
468
- /**
469
- * Background color of striped rows.
470
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
471
- * or an object with `light` and `dark` keys and `MantineColor` values.
472
- */
473
- stripedColor?: MantineColor | {
474
- light: MantineColor;
475
- dark: MantineColor;
476
- };
477
- /**
478
- * Background color of hover-highlighted row.
479
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
480
- * or an object with `light` and `dark` keys and `MantineColor` values.
481
- */
482
- highlightOnHoverColor?: MantineColor | {
483
- light: MantineColor;
484
- dark: MantineColor;
485
- };
486
- /**
487
- * Data table row text color.
488
- * A function that accepts row data and returns color.
489
- * The returned color can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
490
- * or an object with `light` and `dark` keys and `MantineColor` values.
491
- */
492
- rowColor?: (record: T, index: number) => MantineColor | undefined | {
493
- light: MantineColor;
494
- dark: MantineColor;
495
- };
496
- /**
497
- * Data table row background color.
498
- * A function that accepts row data and returns background color color.
499
- * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
500
- * or an object with `light` and `dark` keys and `MantineColor` values.
501
- */
502
- rowBackgroundColor?: (record: T, index: number) => MantineColor | undefined | {
503
- light: MantineColor;
504
- dark: MantineColor;
505
- };
419
+ /**
420
+ * Data table text color.
421
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
422
+ * or an object with `light` and `dark` keys and `MantineColor` values.
423
+ */
424
+ c?: MantineColor | {
425
+ light: MantineColor;
426
+ dark: MantineColor;
427
+ };
428
+ /**
429
+ * Data table background color.
430
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
431
+ * or an object with `light` and `dark` keys and `MantineColor` values.
432
+ */
433
+ backgroundColor?: MantineColor | {
434
+ light: MantineColor;
435
+ dark: MantineColor;
436
+ };
437
+ /**
438
+ * Color of table borders, applied to all borders except row borders.
439
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
440
+ * or an object with `light` and `dark` keys and `MantineColor` values.
441
+ */
442
+ borderColor?: MantineColor | {
443
+ light: MantineColor;
444
+ dark: MantineColor;
445
+ };
446
+ /**
447
+ * Color of row borders.
448
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
449
+ * or an object with `light` and `dark` keys and `MantineColor` values.
450
+ */
451
+ rowBorderColor?: MantineColor | {
452
+ light: MantineColor;
453
+ dark: MantineColor;
454
+ };
455
+ /**
456
+ * Background color of striped rows.
457
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
458
+ * or an object with `light` and `dark` keys and `MantineColor` values.
459
+ */
460
+ stripedColor?: MantineColor | {
461
+ light: MantineColor;
462
+ dark: MantineColor;
463
+ };
464
+ /**
465
+ * Background color of hover-highlighted row.
466
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
467
+ * or an object with `light` and `dark` keys and `MantineColor` values.
468
+ */
469
+ highlightOnHoverColor?: MantineColor | {
470
+ light: MantineColor;
471
+ dark: MantineColor;
472
+ };
473
+ /**
474
+ * Data table row text color.
475
+ * A function that accepts row data and returns color.
476
+ * The returned color can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
477
+ * or an object with `light` and `dark` keys and `MantineColor` values.
478
+ */
479
+ rowColor?: (record: T, index: number) => MantineColor | undefined | {
480
+ light: MantineColor;
481
+ dark: MantineColor;
482
+ };
483
+ /**
484
+ * Data table row background color.
485
+ * A function that accepts row data and returns background color color.
486
+ * Can be a `MantineColor` (key of `theme.colors` or any valid CSS color string),
487
+ * or an object with `light` and `dark` keys and `MantineColor` values.
488
+ */
489
+ rowBackgroundColor?: (record: T, index: number) => MantineColor | undefined | {
490
+ light: MantineColor;
491
+ dark: MantineColor;
492
+ };
506
493
  };
507
-
508
494
  type DataTableColumnProps<T = Record<string, unknown>> = {
509
- /**
510
- * Grouped columns.
511
- */
512
- groups: DataTableColumnGroup<T>[];
513
- columns?: never;
495
+ /**
496
+ * Grouped columns.
497
+ */
498
+ groups: DataTableColumnGroup<T>[];
499
+ columns?: never;
514
500
  } | {
515
- groups?: never;
516
- /**
517
- * Visible columns.
518
- */
519
- columns: DataTableColumn<T>[];
501
+ groups?: never;
502
+ /**
503
+ * Visible columns.
504
+ */
505
+ columns: DataTableColumn<T>[];
520
506
  };
521
-
522
507
  type DataTableLoaderProps = {
523
- /**
524
- * Loader background blur (in pixels).
525
- */
526
- loaderBackgroundBlur?: number;
508
+ /**
509
+ * Loader background blur (in pixels).
510
+ */
511
+ loaderBackgroundBlur?: number;
527
512
  } & ({
528
- loaderSize?: never;
529
- loaderType?: never;
530
- loaderColor?: never;
531
- /**
532
- * Custom loader component to use instead of default one.
533
- */
534
- customLoader?: React.ReactNode;
513
+ loaderSize?: never;
514
+ loaderType?: never;
515
+ loaderColor?: never;
516
+ /**
517
+ * Custom loader component to use instead of default one.
518
+ */
519
+ customLoader?: React.ReactNode;
535
520
  } | {
536
- /**
537
- * Loader size.
538
- * @default `lg`.
539
- */
540
- loaderSize?: MantineSize | (string & NonNullable<unknown>) | number;
541
- /**
542
- * Loader type.
543
- */
544
- loaderType?: MantineLoader;
545
- /**
546
- * Loader color.
547
- */
548
- loaderColor?: MantineColor;
549
- customLoader?: never;
521
+ /**
522
+ * Loader size.
523
+ * @default `lg`.
524
+ */
525
+ loaderSize?: MantineSize | (string & NonNullable<unknown>) | number;
526
+ /**
527
+ * Loader type.
528
+ */
529
+ loaderType?: MantineLoader;
530
+ /**
531
+ * Loader color.
532
+ */
533
+ loaderColor?: MantineColor;
534
+ customLoader?: never;
550
535
  });
551
-
552
- type DataTableRowClickHandler<T = Record<string, unknown>> = (params: {
553
- /**
554
- * Click event.
555
- */
556
- event: React.MouseEvent;
557
- /**
558
- * Clicked record.
559
- */
536
+ export type DataTableRowClickHandler<T = Record<string, unknown>> = (params: {
537
+ /**
538
+ * Click event.
539
+ */
540
+ event: React.MouseEvent;
541
+ /**
542
+ * Clicked record.
543
+ */
544
+ record: T;
545
+ /**
546
+ * Clicked record index.
547
+ */
548
+ index: number;
549
+ }) => void;
550
+ export type DataTableRowExpansionCollapseProps = Pick<CollapseProps, "animateOpacity" | "transitionDuration" | "transitionTimingFunction">;
551
+ export type DataTableRowExpansionProps<T = Record<string, unknown>> = {
552
+ /**
553
+ * Function defining which records can be expanded.
554
+ * Accepts an object with `record` and `index` properties and returns a boolean specifying
555
+ * whether the row should be expandable.
556
+ */
557
+ expandable?: (params: {
560
558
  record: T;
561
- /**
562
- * Clicked record index.
563
- */
564
559
  index: number;
565
- }) => void;
566
-
567
- type DataTableRowExpansionCollapseProps = Pick<CollapseProps, 'animateOpacity' | 'transitionDuration' | 'transitionTimingFunction'>;
568
-
569
- type DataTableRowExpansionProps<T = Record<string, unknown>> = {
570
- /**
571
- * Function defining which records can be expanded.
572
- * Accepts an object with `record` and `index` properties and returns a boolean specifying
573
- * whether the row should be expandable.
574
- */
575
- expandable?: (params: {
576
- record: T;
577
- index: number;
578
- }) => boolean;
579
- /**
580
- * Defines when rows should expand.
581
- * @default `click`
582
- */
583
- trigger?: 'click' | 'always' | 'never';
584
- /**
585
- * If true, multiple rows can be expanded at the same time.
586
- */
587
- allowMultiple?: boolean;
588
- /**
589
- * Function defining which records will be initially expanded.
590
- * Accepts an object with `record` and `index` properties and returns a boolean specifying
591
- * whether the row should be expanded initially.
592
- * Does nothing if `trigger === 'always'`.
593
- */
594
- initiallyExpanded?: (options: {
595
- record: T;
596
- index: number;
597
- }) => boolean;
598
- /**
599
- * Additional properties passed to the Mantine Collapse component wrapping the custom content.
600
- */
601
- collapseProps?: DataTableRowExpansionCollapseProps;
602
- /**
603
- * An object defining the row expansion behavior in controlled mode.
604
- */
605
- expanded?: {
606
- /**
607
- * Currently expanded record IDs.
608
- */
609
- recordIds: unknown[];
610
- /**
611
- * Callback fired when expanded records change.
612
- * Receives an array containing the newly expanded record IDs.
613
- */
614
- onRecordIdsChange?: React.Dispatch<React.SetStateAction<any[]>> | ((recordIds: unknown[]) => void);
615
- };
616
- /**
617
- * Function returning the custom content to be lazily rendered for an expanded row.
618
- * Accepts an object with properties containing the current record, its index,
619
- * and a `collapse()` callback that can be used to collapse the expanded row.
620
- * Must return a React node.
621
- */
622
- content: (params: {
623
- record: T;
624
- index: number;
625
- collapse: () => void;
626
- }) => React.ReactNode;
560
+ }) => boolean;
561
+ /**
562
+ * Defines when rows should expand.
563
+ * @default `click`
564
+ */
565
+ trigger?: "click" | "always" | "never";
566
+ /**
567
+ * If true, multiple rows can be expanded at the same time.
568
+ */
569
+ allowMultiple?: boolean;
570
+ /**
571
+ * Function defining which records will be initially expanded.
572
+ * Accepts an object with `record` and `index` properties and returns a boolean specifying
573
+ * whether the row should be expanded initially.
574
+ * Does nothing if `trigger === 'always'`.
575
+ */
576
+ initiallyExpanded?: (options: {
577
+ record: T;
578
+ index: number;
579
+ }) => boolean;
580
+ /**
581
+ * Additional properties passed to the Mantine Collapse component wrapping the custom content.
582
+ */
583
+ collapseProps?: DataTableRowExpansionCollapseProps;
584
+ /**
585
+ * An object defining the row expansion behavior in controlled mode.
586
+ */
587
+ expanded?: {
588
+ /**
589
+ * Currently expanded record IDs.
590
+ */
591
+ recordIds: unknown[];
592
+ /**
593
+ * Callback fired when expanded records change.
594
+ * Receives an array containing the newly expanded record IDs.
595
+ */
596
+ onRecordIdsChange?: React.Dispatch<React.SetStateAction<any[]>> | ((recordIds: unknown[]) => void);
597
+ };
598
+ /**
599
+ * Function returning the custom content to be lazily rendered for an expanded row.
600
+ * Accepts an object with properties containing the current record, its index,
601
+ * and a `collapse()` callback that can be used to collapse the expanded row.
602
+ * Must return a React node.
603
+ */
604
+ content: (params: {
605
+ record: T;
606
+ index: number;
607
+ collapse: () => void;
608
+ }) => React.ReactNode;
627
609
  };
628
-
629
610
  type DataTableScrollProps = {
630
- /**
631
- * Function to call when the DataTable is scrolled.
632
- */
633
- onScroll?: (position: {
634
- x: number;
635
- y: number;
636
- }) => void;
637
- /**
638
- * Function to call when the DataTable is scrolled to top.
639
- */
640
- onScrollToTop?: () => void;
641
- /**
642
- * Function to call when the DataTable is scrolled to bottom.
643
- */
644
- onScrollToBottom?: () => void;
645
- /**
646
- * Function to call when the DataTable is scrolled to left.
647
- */
648
- onScrollToLeft?: () => void;
649
- /**
650
- * Function to call when the DataTable is scrolled to right.
651
- */
652
- onScrollToRight?: () => void;
611
+ /**
612
+ * Function to call when the DataTable is scrolled.
613
+ */
614
+ onScroll?: (position: {
615
+ x: number;
616
+ y: number;
617
+ }) => void;
618
+ /**
619
+ * Function to call when the DataTable is scrolled to top.
620
+ */
621
+ onScrollToTop?: () => void;
622
+ /**
623
+ * Function to call when the DataTable is scrolled to bottom.
624
+ */
625
+ onScrollToBottom?: () => void;
626
+ /**
627
+ * Function to call when the DataTable is scrolled to left.
628
+ */
629
+ onScrollToLeft?: () => void;
630
+ /**
631
+ * Function to call when the DataTable is scrolled to right.
632
+ */
633
+ onScrollToRight?: () => void;
653
634
  };
654
-
655
- type DataTableSelectionTrigger = 'cell' | 'checkbox';
656
-
657
- type DataTableSelectionProps<T = Record<string, unknown>> = {
658
- selectionTrigger?: never;
659
- selectedRecords?: never;
660
- onSelectedRecordsChange?: never;
661
- isRecordSelectable?: never;
662
- selectionCheckboxProps?: never;
663
- getRecordSelectionCheckboxProps?: never;
664
- allRecordsSelectionCheckboxProps?: never;
665
- selectionColumnClassName?: never;
666
- selectionColumnStyle?: never;
635
+ export type DataTableSelectionTrigger = "cell" | "checkbox";
636
+ export type DataTableSelectionProps<T = Record<string, unknown>> = {
637
+ selectionTrigger?: never;
638
+ selectedRecords?: never;
639
+ onSelectedRecordsChange?: never;
640
+ isRecordSelectable?: never;
641
+ selectionCheckboxProps?: never;
642
+ getRecordSelectionCheckboxProps?: never;
643
+ allRecordsSelectionCheckboxProps?: never;
644
+ selectionColumnClassName?: never;
645
+ selectionColumnStyle?: never;
667
646
  } | {
668
- /**
669
- * Defines how selection is triggered.
670
- * @default 'checkbox'
671
- */
672
- selectionTrigger?: DataTableSelectionTrigger;
673
- /**
674
- * Currently-selected records.
675
- */
676
- selectedRecords?: T[];
677
- /**
678
- * Callback fired when selected records change.
679
- * Receives and array of selected records as argument.
680
- */
681
- onSelectedRecordsChange?: (selectedRecords: T[]) => void;
682
- /**
683
- * Optional class name applied to selection column.
684
- */
685
- selectionColumnClassName?: string;
686
- /**
687
- * Optional style applied to selection column.
688
- */
689
- selectionColumnStyle?: MantineStyleProp;
690
- /**
691
- * A function used to determine whether a certain record is selectable.
692
- * if the function returns false, the row selection checkbox is disabled.
693
- * Accepts the current recors and index as arguments and returns a boolean.
694
- */
695
- isRecordSelectable?: (record: T, index: number) => boolean;
696
- /**
697
- * Props for the selection checkboxes, applied to header and all rows.
698
- */
699
- selectionCheckboxProps?: CheckboxProps;
700
- /**
701
- * A function used to determine additional props of the row selection checkboxes.
702
- * Accepts the current record and its index as arguments and returns an object.
703
- */
704
- getRecordSelectionCheckboxProps?: (record: T, index: number) => CheckboxProps;
705
- /**
706
- * Additional props for the header checkbox that toggles selection of all records.
707
- */
708
- allRecordsSelectionCheckboxProps?: CheckboxProps;
647
+ /**
648
+ * Defines how selection is triggered.
649
+ * @default 'checkbox'
650
+ */
651
+ selectionTrigger?: DataTableSelectionTrigger;
652
+ /**
653
+ * Currently-selected records.
654
+ */
655
+ selectedRecords?: T[];
656
+ /**
657
+ * Callback fired when selected records change.
658
+ * Receives and array of selected records as argument.
659
+ */
660
+ onSelectedRecordsChange?: (selectedRecords: T[]) => void;
661
+ /**
662
+ * Optional class name applied to selection column.
663
+ */
664
+ selectionColumnClassName?: string;
665
+ /**
666
+ * Optional style applied to selection column.
667
+ */
668
+ selectionColumnStyle?: MantineStyleProp;
669
+ /**
670
+ * A function used to determine whether a certain record is selectable.
671
+ * if the function returns false, the row selection checkbox is disabled.
672
+ * Accepts the current recors and index as arguments and returns a boolean.
673
+ */
674
+ isRecordSelectable?: (record: T, index: number) => boolean;
675
+ /**
676
+ * Props for the selection checkboxes, applied to header and all rows.
677
+ */
678
+ selectionCheckboxProps?: CheckboxProps;
679
+ /**
680
+ * A function used to determine additional props of the row selection checkboxes.
681
+ * Accepts the current record and its index as arguments and returns an object.
682
+ */
683
+ getRecordSelectionCheckboxProps?: (record: T, index: number) => CheckboxProps;
684
+ /**
685
+ * Additional props for the header checkbox that toggles selection of all records.
686
+ */
687
+ allRecordsSelectionCheckboxProps?: CheckboxProps;
709
688
  };
710
-
711
- type DataTableSortStatus<T = Record<string, unknown>> = {
712
- /**
713
- * Sort column key for nested values.
714
- * @type {string}
715
- */
716
- sortKey?: string;
717
- /**
718
- * Sort column accessor.
719
- * You can use dot-notation for nested objects property drilling
720
- * (i.e. `department.name` or `department.company.name`).
721
- */
722
- columnAccessor: keyof T | (string & NonNullable<unknown>);
723
- /**
724
- * Sort direction - `asc` for ascending, `desc` for descending.
725
- */
726
- direction: 'asc' | 'desc';
689
+ export type DataTableSortStatus<T = Record<string, unknown>> = {
690
+ /**
691
+ * Sort column key for nested values.
692
+ * @type {string}
693
+ */
694
+ sortKey?: string;
695
+ /**
696
+ * Sort column accessor.
697
+ * You can use dot-notation for nested objects property drilling
698
+ * (i.e. `department.name` or `department.company.name`).
699
+ */
700
+ columnAccessor: keyof T | (string & NonNullable<unknown>);
701
+ /**
702
+ * Sort direction - `asc` for ascending, `desc` for descending.
703
+ */
704
+ direction: "asc" | "desc";
727
705
  };
728
-
729
- type DataTableSortProps<T = Record<string, unknown>> = ({
730
- sortStatus?: never;
731
- onSortStatusChange?: never;
706
+ export type DataTableSortProps<T = Record<string, unknown>> = ({
707
+ sortStatus?: never;
708
+ onSortStatusChange?: never;
732
709
  } | {
733
- /**
734
- * Current sort status (sort column accessor & direction).
735
- */
736
- sortStatus: DataTableSortStatus<T>;
737
- /**
738
- * Callback fired after change of sort status.
739
- * Receives the new sort status as argument.
740
- */
741
- onSortStatusChange?: (sortStatus: DataTableSortStatus<T>) => void;
710
+ /**
711
+ * Current sort status (sort column accessor & direction).
712
+ */
713
+ sortStatus: DataTableSortStatus<T>;
714
+ /**
715
+ * Callback fired after change of sort status.
716
+ * Receives the new sort status as argument.
717
+ */
718
+ onSortStatusChange?: (sortStatus: DataTableSortStatus<T>) => void;
742
719
  }) & {
720
+ /**
721
+ * Custom sort icons.
722
+ */
723
+ sortIcons?: {
743
724
  /**
744
- * Custom sort icons.
745
- */
746
- sortIcons?: {
747
- /**
748
- * Icon to display when column is sorted ascending.
749
- * Will be rotated 180deg for descending sort
750
- */
751
- sorted: React.ReactNode;
752
- /**
753
- * Icon to display when column is not sorted.
754
- */
755
- unsorted: React.ReactNode;
756
- };
757
- };
758
-
759
- type DataTableVerticalAlign = 'top' | 'center' | 'bottom';
760
-
761
- type DataTableProps<T = Record<string, unknown>> = {
762
- /**
763
- * Data table container class name.
764
- */
765
- className?: string;
766
- /**
767
- * Data table container style.
768
- * Either a style object or a function that accepts current theme and returns a style object.
769
- */
770
- style?: MantineStyleProp;
771
- /**
772
- * Data table elements class names.
773
- * An object with `root`, `table`, `header`, `footer` and `pagination` keys and class names
774
- * as values.
775
- */
776
- classNames?: Partial<Record<'root' | 'table' | 'header' | 'footer' | 'pagination', string>>;
777
- /**
778
- * Data table elements styles.
779
- * An object with `root`, `table`, `header`, `footer` and `pagination` keys and
780
- * either style objects, or functions that accept current theme and return style objects, as values.
781
- */
782
- styles?: StylesRecord<'root' | 'table' | 'header' | 'footer' | 'pagination', MantineStyleProp>;
783
- /**
784
- * Table height.
785
- * @default '100%'
786
- */
787
- height?: string | number;
788
- /**
789
- * Minimum table height.
790
- */
791
- minHeight?: string | number;
792
- /**
793
- * Maximum table height.
794
- */
795
- maxHeight?: string | number;
796
- /**
797
- * DataTable component shadow.
798
- */
799
- shadow?: MantineShadow;
800
- /**
801
- * If true, the user will not be able to select text.
802
- */
803
- textSelectionDisabled?: boolean;
804
- /**
805
- * Vertical alignment for row cells.
806
- * @default `center`
807
- */
808
- verticalAlign?: DataTableVerticalAlign;
809
- /**
810
- * If true, will show a loader with semi-transparent background, centered over the table.
811
- */
812
- fetching?: boolean;
813
- /**
814
- * If true, the first column will be pinned to the left side of the table.
815
- */
816
- pinFirstColumn?: boolean;
817
- /**
818
- * If true, the last column will be pinned to the right side of the table.
819
- */
820
- pinLastColumn?: boolean;
821
- /**
822
- * Default column props; will be merged with column props provided to each column
823
- */
824
- defaultColumnProps?: DataTableDefaultColumnProps<T>;
825
- /**
826
- * If you want to use drag and drop as well as toggle to reorder and toggle columns
827
- * provide a unique key which will be used to store the column order in localStorage.
828
- */
829
- storeColumnsKey?: string | undefined;
830
- /**
831
- * A default render function for all columns.
832
- * Accepts the current record, its index in `records` and the column `accessor` as
833
- * arguments and returns a React node (remember that a string is a valid React node too).
834
- */
835
- defaultColumnRender?: (record: T, index: number, accessor: keyof T | (string & NonNullable<unknown>)) => React.ReactNode;
836
- /**
837
- * Accessor to use as unique record key.
838
- * Can be a string representing a property name or a function receiving the current record
839
- * and returning a unique value.
840
- * If you're providing a string, you can use dot-notation for nested objects property drilling
841
- * (i.e. `department.name` or `department.company.name`).
842
- * @default `id`
843
- */
844
- idAccessor?: (keyof T | (string & NonNullable<unknown>)) | ((record: T) => React.Key);
845
- /**
846
- * Visible records.
847
- * The component will try to infer its row type from here.
848
- */
849
- records?: T[];
850
- /**
851
- * Text to show on empty state and pagination footer when no records are available.
852
- */
853
- noRecordsText?: string;
854
- /**
855
- * If true, the table will not show the header with column titles.
856
- */
857
- noHeader?: boolean;
858
- /**
859
- * Function to call when a row cell is clicked.
860
- * Receives an object with the current record, its index in `records`, the current column,
861
- * its index in `columns` and the click event as properties.
725
+ * Icon to display when column is sorted ascending.
726
+ * Will be rotated 180deg for descending sort
862
727
  */
863
- onCellClick?: DataTableCellClickHandler<T>;
728
+ sorted: React.ReactNode;
864
729
  /**
865
- * Function to call when a row cell is double-clicked.
866
- * Receives an object with the current record, its index in `records`, the current column,
867
- * its index in `columns` and the click event as properties.
730
+ * Icon to display when column is not sorted.
868
731
  */
869
- onCellDoubleClick?: DataTableCellClickHandler<T>;
870
- /**
871
- * Function to call when the user right-clicks on a row cell.
872
- * Receives an object with the current record, its index in `records`, the current column,
873
- * its index in `columns` and the click event as properties.
874
- */
875
- onCellContextMenu?: DataTableCellClickHandler<T>;
876
- /**
877
- * Function to call when a row is clicked.
878
- * Receives an object with the current record, its index in `records` and the click event
879
- * as properties.
880
- */
881
- onRowClick?: DataTableRowClickHandler<T>;
882
- /**
883
- * Function to call when a row is double-clicked.
884
- * Receives an object with the current record, its index in `records` and the click event
885
- * as properties.
886
- */
887
- onRowDoubleClick?: DataTableRowClickHandler<T>;
888
- /**
889
- * Function to call when the user right-clicks on a row.
890
- * Receives an object with the current record, its index in `records` and the click event
891
- * as properties.
892
- */
893
- onRowContextMenu?: DataTableRowClickHandler<T>;
894
- /**
895
- * Defines the row expansion behavior.
896
- */
897
- rowExpansion?: DataTableRowExpansionProps<T>;
898
- /**
899
- * Optional class name passed to each row.
900
- * Can be a string or a function receiving the current record and its index as arguments and returning a string.
901
- */
902
- rowClassName?: string | ((record: T, index: number) => string | undefined);
903
- /**
904
- * Optional style passed to each row.
905
- * A function receiving the current record and its index as arguments and returning either
906
- * a style object, or a function that accepts theme and returns a style object.
907
- */
908
- rowStyle?: (record: T, index: number) => MantineStyleProp | undefined;
909
- /**
910
- * Optional style passed to each row.
911
- * a function that receives the current record, its index, default row props and expanded element as arguments
912
- * and returns a React node representing the row.
913
- */
914
- rowFactory?: (props: {
915
- record: T;
916
- index: number;
917
- children: React.ReactNode;
918
- rowProps: TableTrProps;
919
- expandedElement?: React.ReactNode;
920
- }) => React.ReactNode;
921
- /**
922
- * Optional function returning a React node representing the table wrapper.
923
- * If not provided, no wrapper will be used.
924
- *
925
- * examplle: This function can be used with rowFactory if using drag and drop to pass context
926
- */
927
- tableWrapper?: ({ children }: {
928
- children: React.ReactNode;
929
- }) => React.ReactNode;
930
- /**
931
- * Optional function returning an object of custom attributes to be applied to each row in the table.
932
- * Receives the current record and its index as arguments.
933
- * Useful for adding data attributes, handling middle-clicks, etc.
934
- */
935
- customRowAttributes?: (record: T, index: number) => Record<string, unknown>;
936
- /**
937
- * Ref pointing to the scrollable viewport element.
938
- * Useful for imperative scrolling.
939
- */
940
- scrollViewportRef?: React.RefObject<HTMLDivElement | null>;
941
- /**
942
- * Additional props passed to the underlying `ScrollArea` element.
943
- */
944
- scrollAreaProps?: Omit<ScrollAreaProps, 'classNames' | 'styles' | 'onScrollPositionChange'>;
945
- /**
946
- * Ref pointing to the table element.
947
- */
948
- tableRef?: ((instance: HTMLTableElement | null) => void) | React.RefObject<HTMLTableElement>;
949
- /**
950
- * Ref pointing to the table body element.
951
- */
952
- bodyRef?: ((instance: HTMLTableSectionElement | null) => void) | React.RefObject<HTMLTableSectionElement>;
953
- } & Omit<TableProps, 'onScroll' | 'className' | 'classNames' | 'style' | 'styles' | 'p' | 'px' | 'py' | 'pt' | 'pb' | 'layout' | 'captionSide' | 'c' | 'color' | 'borderColor' | 'stripedColor' | 'highlightOnHoverColor' | 'stickyHeader' | 'stickyHeaderOffset' | 'onDragEnd'> & DataTableColorProps<T> & DataTableColumnProps<T> & DataTableOuterBorderProps & DataTableLoaderProps & DataTableEmptyStateProps & DataTablePaginationProps & DataTableSortProps<T> & DataTableScrollProps & DataTableSelectionProps<T>;
954
-
955
- type WithOptionalProperty<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
956
- type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
957
- [Property in Key]-?: Type[Property];
732
+ unsorted: React.ReactNode;
733
+ };
958
734
  };
959
-
960
- declare function DataTable<T>({ withTableBorder, borderRadius, textSelectionDisabled, height, minHeight, maxHeight, shadow, verticalAlign, fetching, columns, storeColumnsKey, groups, pinFirstColumn, pinLastColumn, defaultColumnProps, defaultColumnRender, idAccessor, records, selectionTrigger, selectedRecords, onSelectedRecordsChange, selectionColumnClassName, selectionColumnStyle, isRecordSelectable, selectionCheckboxProps, allRecordsSelectionCheckboxProps, getRecordSelectionCheckboxProps, sortStatus, sortIcons, onSortStatusChange, horizontalSpacing, page, onPageChange, totalRecords, recordsPerPage, onRecordsPerPageChange, recordsPerPageOptions, recordsPerPageLabel, paginationWithEdges, paginationWithControls, paginationActiveTextColor, paginationActiveBackgroundColor, paginationSize, paginationText, paginationWrapBreakpoint, getPaginationControlProps, getPaginationItemProps, renderPagination, loaderBackgroundBlur, customLoader, loaderSize, loaderType, loaderColor, loadingText, emptyState, noRecordsText, noRecordsIcon, highlightOnHover, striped, noHeader, onRowClick, onRowDoubleClick, onRowContextMenu, onCellClick, onCellDoubleClick, onCellContextMenu, onScroll, onScrollToTop, onScrollToBottom, onScrollToLeft, onScrollToRight, c, backgroundColor, borderColor, rowBorderColor, stripedColor, highlightOnHoverColor, rowColor, rowBackgroundColor, rowExpansion, rowClassName, rowStyle, customRowAttributes, scrollViewportRef, scrollAreaProps, tableRef, bodyRef, m, my, mx, mt, mb, ml, mr, className, classNames, style, styles, rowFactory, tableWrapper, ...otherProps }: DataTableProps<T>): react.JSX.Element;
961
-
962
- declare function DataTableDraggableRow({ className, children, isDragging, ref: refProp, ...otherProps }: DataTableDraggableRowProps & {
963
- ref?: Ref<HTMLTableRowElement>;
964
- }): react.JSX.Element;
965
-
735
+ export type DataTableVerticalAlign = "top" | "center" | "bottom";
736
+ export type DataTableProps<T = Record<string, unknown>> = {
737
+ /**
738
+ * Data table container class name.
739
+ */
740
+ className?: string;
741
+ /**
742
+ * Data table container style.
743
+ * Either a style object or a function that accepts current theme and returns a style object.
744
+ */
745
+ style?: MantineStyleProp;
746
+ /**
747
+ * Data table elements class names.
748
+ * An object with `root`, `table`, `header`, `footer` and `pagination` keys and class names
749
+ * as values.
750
+ */
751
+ classNames?: Partial<Record<"root" | "table" | "header" | "footer" | "pagination", string>>;
752
+ /**
753
+ * Data table elements styles.
754
+ * An object with `root`, `table`, `header`, `footer` and `pagination` keys and
755
+ * either style objects, or functions that accept current theme and return style objects, as values.
756
+ */
757
+ styles?: StylesRecord<"root" | "table" | "header" | "footer" | "pagination", MantineStyleProp>;
758
+ /**
759
+ * Table height.
760
+ * @default '100%'
761
+ */
762
+ height?: string | number;
763
+ /**
764
+ * Minimum table height.
765
+ */
766
+ minHeight?: string | number;
767
+ /**
768
+ * Maximum table height.
769
+ */
770
+ maxHeight?: string | number;
771
+ /**
772
+ * DataTable component shadow.
773
+ */
774
+ shadow?: MantineShadow;
775
+ /**
776
+ * If true, the user will not be able to select text.
777
+ */
778
+ textSelectionDisabled?: boolean;
779
+ /**
780
+ * Vertical alignment for row cells.
781
+ * @default `center`
782
+ */
783
+ verticalAlign?: DataTableVerticalAlign;
784
+ /**
785
+ * If true, will show a loader with semi-transparent background, centered over the table.
786
+ */
787
+ fetching?: boolean;
788
+ /**
789
+ * If true, the first column will be pinned to the left side of the table.
790
+ */
791
+ pinFirstColumn?: boolean;
792
+ /**
793
+ * If true, the last column will be pinned to the right side of the table.
794
+ */
795
+ pinLastColumn?: boolean;
796
+ /**
797
+ * Default column props; will be merged with column props provided to each column
798
+ */
799
+ defaultColumnProps?: DataTableDefaultColumnProps<T>;
800
+ /**
801
+ * If you want to use drag and drop as well as toggle to reorder and toggle columns
802
+ * provide a unique key which will be used to store the column order in localStorage.
803
+ */
804
+ storeColumnsKey?: string | undefined;
805
+ /**
806
+ * A default render function for all columns.
807
+ * Accepts the current record, its index in `records` and the column `accessor` as
808
+ * arguments and returns a React node (remember that a string is a valid React node too).
809
+ */
810
+ defaultColumnRender?: (record: T, index: number, accessor: keyof T | (string & NonNullable<unknown>)) => React.ReactNode;
811
+ /**
812
+ * Accessor to use as unique record key.
813
+ * Can be a string representing a property name or a function receiving the current record
814
+ * and returning a unique value.
815
+ * If you're providing a string, you can use dot-notation for nested objects property drilling
816
+ * (i.e. `department.name` or `department.company.name`).
817
+ * @default `id`
818
+ */
819
+ idAccessor?: (keyof T | (string & NonNullable<unknown>)) | ((record: T) => React.Key);
820
+ /**
821
+ * Visible records.
822
+ * The component will try to infer its row type from here.
823
+ */
824
+ records?: T[];
825
+ /**
826
+ * Text to show on empty state and pagination footer when no records are available.
827
+ */
828
+ noRecordsText?: string;
829
+ /**
830
+ * If true, the table will not show the header with column titles.
831
+ */
832
+ noHeader?: boolean;
833
+ /**
834
+ * Function to call when a row cell is clicked.
835
+ * Receives an object with the current record, its index in `records`, the current column,
836
+ * its index in `columns` and the click event as properties.
837
+ */
838
+ onCellClick?: DataTableCellClickHandler<T>;
839
+ /**
840
+ * Function to call when a row cell is double-clicked.
841
+ * Receives an object with the current record, its index in `records`, the current column,
842
+ * its index in `columns` and the click event as properties.
843
+ */
844
+ onCellDoubleClick?: DataTableCellClickHandler<T>;
845
+ /**
846
+ * Function to call when the user right-clicks on a row cell.
847
+ * Receives an object with the current record, its index in `records`, the current column,
848
+ * its index in `columns` and the click event as properties.
849
+ */
850
+ onCellContextMenu?: DataTableCellClickHandler<T>;
851
+ /**
852
+ * Function to call when a row is clicked.
853
+ * Receives an object with the current record, its index in `records` and the click event
854
+ * as properties.
855
+ */
856
+ onRowClick?: DataTableRowClickHandler<T>;
857
+ /**
858
+ * Function to call when a row is double-clicked.
859
+ * Receives an object with the current record, its index in `records` and the click event
860
+ * as properties.
861
+ */
862
+ onRowDoubleClick?: DataTableRowClickHandler<T>;
863
+ /**
864
+ * Function to call when the user right-clicks on a row.
865
+ * Receives an object with the current record, its index in `records` and the click event
866
+ * as properties.
867
+ */
868
+ onRowContextMenu?: DataTableRowClickHandler<T>;
869
+ /**
870
+ * Defines the row expansion behavior.
871
+ */
872
+ rowExpansion?: DataTableRowExpansionProps<T>;
873
+ /**
874
+ * Optional class name passed to each row.
875
+ * Can be a string or a function receiving the current record and its index as arguments and returning a string.
876
+ */
877
+ rowClassName?: string | ((record: T, index: number) => string | undefined);
878
+ /**
879
+ * Optional style passed to each row.
880
+ * A function receiving the current record and its index as arguments and returning either
881
+ * a style object, or a function that accepts theme and returns a style object.
882
+ */
883
+ rowStyle?: (record: T, index: number) => MantineStyleProp | undefined;
884
+ /**
885
+ * Optional style passed to each row.
886
+ * a function that receives the current record, its index, default row props and expanded element as arguments
887
+ * and returns a React node representing the row.
888
+ */
889
+ rowFactory?: (props: {
890
+ record: T;
891
+ index: number;
892
+ children: React.ReactNode;
893
+ rowProps: TableTrProps;
894
+ expandedElement?: React.ReactNode;
895
+ }) => React.ReactNode;
896
+ /**
897
+ * Optional function returning a React node representing the table wrapper.
898
+ * If not provided, no wrapper will be used.
899
+ *
900
+ * examplle: This function can be used with rowFactory if using drag and drop to pass context
901
+ */
902
+ tableWrapper?: ({ children }: {
903
+ children: React.ReactNode;
904
+ }) => React.ReactNode;
905
+ /**
906
+ * Optional function returning an object of custom attributes to be applied to each row in the table.
907
+ * Receives the current record and its index as arguments.
908
+ * Useful for adding data attributes, handling middle-clicks, etc.
909
+ */
910
+ customRowAttributes?: (record: T, index: number) => Record<string, unknown>;
911
+ /**
912
+ * Ref pointing to the scrollable viewport element.
913
+ * Useful for imperative scrolling.
914
+ */
915
+ scrollViewportRef?: React.RefObject<HTMLDivElement | null>;
916
+ /**
917
+ * Additional props passed to the underlying `ScrollArea` element.
918
+ */
919
+ scrollAreaProps?: Omit<ScrollAreaProps, "classNames" | "styles" | "onScrollPositionChange">;
920
+ /**
921
+ * Ref pointing to the table element.
922
+ */
923
+ tableRef?: ((instance: HTMLTableElement | null) => void) | React.RefObject<HTMLTableElement>;
924
+ /**
925
+ * Ref pointing to the table body element.
926
+ */
927
+ bodyRef?: ((instance: HTMLTableSectionElement | null) => void) | React.RefObject<HTMLTableSectionElement>;
928
+ } & Omit<TableProps, "onScroll" | "className" | "classNames" | "style" | "styles" | "p" | "px" | "py" | "pt" | "pb" | "layout" | "captionSide" | "c" | "color" | "borderColor" | "stripedColor" | "highlightOnHoverColor" | "stickyHeader" | "stickyHeaderOffset" | "onDragEnd"> & DataTableColorProps<T> & DataTableColumnProps<T> & DataTableOuterBorderProps & DataTableLoaderProps & DataTableEmptyStateProps & DataTablePaginationProps & DataTableSortProps<T> & DataTableScrollProps & DataTableSelectionProps<T>;
929
+ export type WithOptionalProperty<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
930
+ export type WithRequiredProperty<Type, Key extends keyof Type> = Type & { [Property in Key]-?: Type[Property]; };
931
+ export declare function DataTable<T>({ withTableBorder, borderRadius, textSelectionDisabled, height, minHeight, maxHeight, shadow, verticalAlign, fetching, columns, storeColumnsKey, groups, pinFirstColumn, pinLastColumn, defaultColumnProps, defaultColumnRender, idAccessor, records, selectionTrigger, selectedRecords, onSelectedRecordsChange, selectionColumnClassName, selectionColumnStyle, isRecordSelectable, selectionCheckboxProps, allRecordsSelectionCheckboxProps, getRecordSelectionCheckboxProps, sortStatus, sortIcons, onSortStatusChange, horizontalSpacing, page, onPageChange, totalRecords, recordsPerPage, onRecordsPerPageChange, recordsPerPageOptions, recordsPerPageLabel, paginationWithEdges, paginationWithControls, paginationActiveTextColor, paginationActiveBackgroundColor, paginationSize, paginationText, paginationWrapBreakpoint, getPaginationControlProps, getPaginationItemProps, renderPagination, loaderBackgroundBlur, customLoader, loaderSize, loaderType, loaderColor, loadingText, emptyState, noRecordsText, noRecordsIcon, highlightOnHover, striped, noHeader, onRowClick, onRowDoubleClick, onRowContextMenu, onCellClick, onCellDoubleClick, onCellContextMenu, onScroll, onScrollToTop, onScrollToBottom, onScrollToLeft, onScrollToRight, c, backgroundColor, borderColor, rowBorderColor, stripedColor, highlightOnHoverColor, rowColor, rowBackgroundColor, rowExpansion, rowClassName, rowStyle, customRowAttributes, scrollViewportRef, scrollAreaProps, tableRef, bodyRef, m, my, mx, mt, mb, ml, mr, className, classNames, style, styles, rowFactory, tableWrapper, ...otherProps }: DataTableProps<T>): JSX.Element;
932
+ export declare function DataTableDraggableRow({ className, children, isDragging, ref: refProp, ...otherProps }: DataTableDraggableRowProps & {
933
+ ref?: Ref<HTMLTableRowElement>;
934
+ }): JSX.Element;
966
935
  type DataTableColumnPinning = {
967
- accessor: string;
968
- defaultPinned: 'left' | 'right' | undefined;
969
- pinnable: boolean;
970
- pinned: 'left' | 'right' | undefined;
936
+ accessor: string;
937
+ defaultPinned: "left" | "right" | undefined;
938
+ pinnable: boolean;
939
+ pinned: "left" | "right" | undefined;
971
940
  };
972
-
973
941
  type DataTableColumnToggle = {
974
- accessor: string;
975
- defaultToggle: boolean;
976
- toggleable: boolean;
977
- toggled: boolean;
942
+ accessor: string;
943
+ defaultToggle: boolean;
944
+ toggleable: boolean;
945
+ toggled: boolean;
978
946
  };
979
-
980
947
  /**
981
948
  * Hook to handle column features such as drag-and-drop reordering, visibility toggling and resizing.
982
949
  * @see https://icflorescu.github.io/mantine-datatable/examples/column-dragging-and-toggling/
983
950
  */
984
- declare const useDataTableColumns: <T>({ key, columns, getInitialValueInEffect, headerRef, scrollViewportRef, }: {
985
- /**
986
- * The key to use in localStorage to store the columns order and toggle state.
987
- */
988
- key: string | undefined;
989
- /**
990
- * Columns definitions.
991
- */
992
- columns: DataTableColumn<T>[];
993
- /**
994
- * If set to true, value will be updated in useEffect after mount.
995
- * @default true
996
- */
997
- getInitialValueInEffect?: boolean;
998
- /**
999
- * Reference to the table header element for measuring column widths.
1000
- */
1001
- headerRef?: RefObject<HTMLTableSectionElement | null>;
1002
- /**
1003
- * Reference to the scroll viewport for calculating overflow.
1004
- */
1005
- scrollViewportRef?: RefObject<HTMLElement | null>;
951
+ export declare const useDataTableColumns: <T>({ key, columns, getInitialValueInEffect, headerRef, scrollViewportRef }: {
952
+ /**
953
+ * The key to use in localStorage to store the columns order and toggle state.
954
+ */
955
+ key: string | undefined;
956
+ /**
957
+ * Columns definitions.
958
+ */
959
+ columns: DataTableColumn<T>[];
960
+ /**
961
+ * If set to true, value will be updated in useEffect after mount.
962
+ * @default true
963
+ */
964
+ getInitialValueInEffect?: boolean;
965
+ /**
966
+ * Reference to the table header element for measuring column widths.
967
+ */
968
+ headerRef?: RefObject<HTMLTableSectionElement | null>;
969
+ /**
970
+ * Reference to the scroll viewport for calculating overflow.
971
+ */
972
+ scrollViewportRef?: RefObject<HTMLElement | null>;
1006
973
  }) => {
1007
- readonly effectiveColumns: DataTableColumn<T>[];
1008
- readonly setColumnsOrder: (order: string[]) => void;
1009
- readonly columnsOrder: string[];
1010
- readonly resetColumnsOrder: () => void;
1011
- readonly columnsToggle: DataTableColumnToggle[];
1012
- readonly setColumnsToggle: (toggle: DataTableColumnToggle[]) => void;
1013
- readonly resetColumnsToggle: () => void;
1014
- readonly columnsPinning: DataTableColumnPinning[];
1015
- readonly setColumnsPinning: (pinning: DataTableColumnPinning[] | ((prev: DataTableColumnPinning[]) => DataTableColumnPinning[])) => void;
1016
- readonly resetColumnsPinning: () => void;
1017
- readonly columnsWidth: {
1018
- [x: string]: string | number;
1019
- }[];
1020
- readonly setColumnsWidth: (updates: {
1021
- accessor: string;
1022
- width: string | number;
1023
- }[]) => void;
1024
- readonly setColumnWidth: (accessor: string, width: string | number) => void;
1025
- readonly setMultipleColumnWidths: (updates: {
1026
- accessor: string;
1027
- width: string | number;
1028
- }[]) => void;
1029
- readonly resetColumnsWidth: () => void;
1030
- readonly hasResizableColumns: boolean;
1031
- readonly allResizableWidthsInitial: boolean;
1032
- readonly measureAndSetColumnWidths: () => void;
1033
- readonly isResizing: boolean;
1034
- readonly isLocked: boolean;
1035
- readonly tableWidth: number | null;
1036
- readonly beginResize: () => void;
1037
- readonly endResize: () => void;
974
+ readonly effectiveColumns: DataTableColumn<T>[];
975
+ readonly setColumnsOrder: (order: string[]) => void;
976
+ readonly columnsOrder: string[];
977
+ readonly resetColumnsOrder: () => void;
978
+ readonly columnsToggle: DataTableColumnToggle[];
979
+ readonly setColumnsToggle: (toggle: DataTableColumnToggle[]) => void;
980
+ readonly resetColumnsToggle: () => void;
981
+ readonly columnsPinning: DataTableColumnPinning[];
982
+ readonly setColumnsPinning: (pinning: DataTableColumnPinning[] | ((prev: DataTableColumnPinning[]) => DataTableColumnPinning[])) => void;
983
+ readonly resetColumnsPinning: () => void;
984
+ readonly columnsWidth: Record<string, string | number>[];
985
+ readonly setColumnsWidth: (updates: {
986
+ accessor: string;
987
+ width: string | number;
988
+ }[]) => void;
989
+ readonly setColumnWidth: (accessor: string, width: string | number) => void;
990
+ readonly setMultipleColumnWidths: (updates: {
991
+ accessor: string;
992
+ width: string | number;
993
+ }[]) => void;
994
+ readonly resetColumnsWidth: () => void;
995
+ readonly hasResizableColumns: boolean;
996
+ readonly allResizableWidthsInitial: boolean;
997
+ readonly measureAndSetColumnWidths: () => void;
998
+ readonly isResizing: boolean;
999
+ readonly isLocked: boolean;
1000
+ readonly tableWidth: number | null;
1001
+ readonly beginResize: () => void;
1002
+ readonly endResize: () => void;
1038
1003
  };
1039
-
1040
1004
  /**
1041
1005
  * Utility function that returns a humanized version of a string, e.g. "camelCase" -> "Camel Case"
1042
1006
  */
1043
- declare function humanize(value: string): string;
1007
+ export declare function humanize(value: string): string;
1044
1008
  /**
1045
1009
  * Sanitizes a value read from `localStorage` before the column hooks call array
1046
1010
  * methods on it.
@@ -1056,57 +1020,56 @@ declare function humanize(value: string): string;
1056
1020
  * Returns `value` when it is an array whose items all pass the optional
1057
1021
  * `isValidItem` predicate; otherwise returns `fallback`.
1058
1022
  */
1059
- declare function sanitizeStoredArray<T>(value: unknown, fallback: T[], isValidItem?: (item: unknown) => boolean): T[];
1023
+ export declare function sanitizeStoredArray<T>(value: unknown, fallback: T[], isValidItem?: (item: unknown) => boolean): T[];
1060
1024
  /**
1061
1025
  * Predicate matching the `{ accessor: string, ... }` shape persisted for column
1062
1026
  * toggle and pinning state.
1063
1027
  */
1064
- declare function hasStringAccessor(item: unknown): boolean;
1028
+ export declare function hasStringAccessor(item: unknown): boolean;
1065
1029
  /**
1066
1030
  * Utility function that returns an array of values that are present in the first array but not in the second
1067
1031
  */
1068
- declare function differenceBy<T>(arr1: T[], arr2: T[], iteratee: (value: T) => unknown): T[];
1032
+ export declare function differenceBy<T>(arr1: T[], arr2: T[], iteratee: (value: T) => unknown): T[];
1069
1033
  /**
1070
1034
  * Utility function that returns an array of unique values from a given array
1071
1035
  */
1072
- declare function uniqBy<T>(arr: T[], iteratee: (value: T) => unknown): T[];
1036
+ export declare function uniqBy<T>(arr: T[], iteratee: (value: T) => unknown): T[];
1073
1037
  /**
1074
1038
  * Utility function that returns the value at a given path in an object
1075
1039
  */
1076
- declare function getValueAtPath<T>(obj: T, path: keyof T | (string & NonNullable<unknown>)): unknown;
1040
+ export declare function getValueAtPath<T>(obj: T, path: keyof T | (string & NonNullable<unknown>)): unknown;
1077
1041
  /**
1078
1042
  * Utility function that returns the record id using idAccessor
1079
1043
  */
1080
- declare function getRecordId<T>(record: T, idAccessor: keyof T | (string & NonNullable<unknown>) | ((record: T) => React.Key)): unknown;
1044
+ export declare function getRecordId<T>(record: T, idAccessor: keyof T | (string & NonNullable<unknown>) | ((record: T) => React.Key)): unknown;
1081
1045
  /**
1082
1046
  * Utility function that reorders an array of records by a given field used for drag'n'drop functionality.
1083
1047
  * @see https://github.com/hello-pangea/dnd
1084
1048
  */
1085
- declare function reorderRecords<T>(dropResult: DropResult, records: T[]): T[];
1049
+ export declare function reorderRecords<T>(dropResult: DropResult, records: T[]): T[];
1086
1050
  /**
1087
1051
  * Utility function that swaps elements of an array, by a given result from drag'n'drop functionality.
1088
1052
  * @see https://github.com/hello-pangea/dnd
1089
1053
  */
1090
- declare function swapRecords<T>(dropResult: DropResult, records: T[]): T[];
1054
+ export declare function swapRecords<T>(dropResult: DropResult, records: T[]): T[];
1091
1055
  /**
1092
1056
  * Calculates the maximum depth of nested column groups
1093
1057
  */
1094
- declare function getMaxGroupDepth<T>(groups: readonly DataTableColumnGroup<T>[]): number;
1058
+ export declare function getMaxGroupDepth<T>(groups: readonly DataTableColumnGroup<T>[]): number;
1095
1059
  /**
1096
1060
  * Flattens nested column groups to extract all columns at the deepest level
1097
1061
  */
1098
- declare function flattenColumns<T>(groups: DataTableColumnGroup<T>[]): DataTableColumn<T>[];
1062
+ export declare function flattenColumns<T>(groups: DataTableColumnGroup<T>[]): DataTableColumn<T>[];
1099
1063
  /**
1100
1064
  * Calculates the column span for a group based on visible columns
1101
1065
  */
1102
- declare function calculateColSpan<T>(group: DataTableColumnGroup<T>, visibles?: (boolean | undefined)[]): number;
1066
+ export declare function calculateColSpan<T>(group: DataTableColumnGroup<T>, visibles?: (boolean | undefined)[]): number;
1103
1067
  /**
1104
1068
  * Gets all groups at a specific depth level
1105
1069
  */
1106
- declare function getGroupsAtDepth<T>(groups: readonly DataTableColumnGroup<T>[], targetDepth: number, currentDepth?: number): DataTableColumnGroup<T>[];
1070
+ export declare function getGroupsAtDepth<T>(groups: readonly DataTableColumnGroup<T>[], targetDepth: number, currentDepth?: number): DataTableColumnGroup<T>[];
1107
1071
  /**
1108
1072
  * Checks if a group needs a right border based on its position and context
1109
1073
  */
1110
- declare function needsRightBorder(isLastGroup: boolean, hasMoreColumnsAfter: boolean, withColumnBorders: boolean): boolean;
1111
-
1112
- export { DataTable, type DataTableCellClickHandler, type DataTableColumn, type DataTableColumnGroup, type DataTableColumnPinning, type DataTableColumnTextAlign, type DataTableColumnToggle, type DataTableDefaultColumnProps, DataTableDraggableRow, type DataTableDraggableRowProps, type DataTableEmptyStateProps, type DataTableOuterBorderProps, type DataTablePaginationProps, type DataTablePaginationRenderContext, type DataTableProps, type DataTableRowClickHandler, type DataTableRowExpansionCollapseProps, type DataTableRowExpansionProps, type DataTableSelectionProps, type DataTableSelectionTrigger, type DataTableSortProps, type DataTableSortStatus, type DataTableVerticalAlign, type WithOptionalProperty, type WithRequiredProperty, calculateColSpan, differenceBy, flattenColumns, getGroupsAtDepth, getMaxGroupDepth, getRecordId, getValueAtPath, hasStringAccessor, humanize, needsRightBorder, reorderRecords, sanitizeStoredArray, swapRecords, uniqBy, useDataTableColumns };
1074
+ export declare function needsRightBorder(isLastGroup: boolean, hasMoreColumnsAfter: boolean, withColumnBorders: boolean): boolean;
1075
+ export type { DataTableColumnPinning, DataTableColumnToggle };