@neeyo/mantine-datatable 0.1.0

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.
@@ -0,0 +1,1112 @@
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;
162
+ } & ({
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;
170
+ } | {
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;
178
+ });
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;
201
+ }) => 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;
237
+ };
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;
250
+ } & 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;
260
+ } | {
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;
268
+ };
269
+
270
+ type DataTableOuterBorderProps = {
271
+ withTableBorder?: never;
272
+ borderRadius?: never;
273
+ } | {
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;
282
+ };
283
+
284
+ type DataTablePageSizeSelectorProps = {
285
+ onRecordsPerPageChange?: never;
286
+ recordsPerPageOptions?: never;
287
+ recordsPerPageLabel?: never;
288
+ } | {
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
+ };
326
+ };
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
+ */
357
+ 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
+ */
366
+ 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;
429
+ }) & DataTablePageSizeSelectorProps;
430
+
431
+ 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
+ };
506
+ };
507
+
508
+ type DataTableColumnProps<T = Record<string, unknown>> = {
509
+ /**
510
+ * Grouped columns.
511
+ */
512
+ groups: DataTableColumnGroup<T>[];
513
+ columns?: never;
514
+ } | {
515
+ groups?: never;
516
+ /**
517
+ * Visible columns.
518
+ */
519
+ columns: DataTableColumn<T>[];
520
+ };
521
+
522
+ type DataTableLoaderProps = {
523
+ /**
524
+ * Loader background blur (in pixels).
525
+ */
526
+ loaderBackgroundBlur?: number;
527
+ } & ({
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;
535
+ } | {
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;
550
+ });
551
+
552
+ type DataTableRowClickHandler<T = Record<string, unknown>> = (params: {
553
+ /**
554
+ * Click event.
555
+ */
556
+ event: React.MouseEvent;
557
+ /**
558
+ * Clicked record.
559
+ */
560
+ record: T;
561
+ /**
562
+ * Clicked record index.
563
+ */
564
+ 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;
627
+ };
628
+
629
+ 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;
653
+ };
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;
667
+ } | {
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;
709
+ };
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';
727
+ };
728
+
729
+ type DataTableSortProps<T = Record<string, unknown>> = ({
730
+ sortStatus?: never;
731
+ onSortStatusChange?: never;
732
+ } | {
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;
742
+ }) & {
743
+ /**
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.
862
+ */
863
+ onCellClick?: DataTableCellClickHandler<T>;
864
+ /**
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.
868
+ */
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];
958
+ };
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
+
966
+ type DataTableColumnPinning = {
967
+ accessor: string;
968
+ defaultPinned: 'left' | 'right' | undefined;
969
+ pinnable: boolean;
970
+ pinned: 'left' | 'right' | undefined;
971
+ };
972
+
973
+ type DataTableColumnToggle = {
974
+ accessor: string;
975
+ defaultToggle: boolean;
976
+ toggleable: boolean;
977
+ toggled: boolean;
978
+ };
979
+
980
+ /**
981
+ * Hook to handle column features such as drag-and-drop reordering, visibility toggling and resizing.
982
+ * @see https://documatrix.github.io/mantine-datatable/examples/column-dragging-and-toggling/
983
+ */
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>;
1006
+ }) => {
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;
1038
+ };
1039
+
1040
+ /**
1041
+ * Utility function that returns a humanized version of a string, e.g. "camelCase" -> "Camel Case"
1042
+ */
1043
+ declare function humanize(value: string): string;
1044
+ /**
1045
+ * Sanitizes a value read from `localStorage` before the column hooks call array
1046
+ * methods on it.
1047
+ *
1048
+ * Persisted column state is synchronized across browser tabs through the native
1049
+ * `storage` event (e.g. when a tab is duplicated). A malformed or unexpected
1050
+ * value — written by another tab, by a different DataTable instance sharing the
1051
+ * same `storeColumnsKey`, or by manual tampering — is delivered verbatim to
1052
+ * every listening table. Without this guard such a value flows straight into
1053
+ * `.map()` / `.forEach()` and crashes the app with
1054
+ * `TypeError: <x>.map is not a function`.
1055
+ *
1056
+ * Returns `value` when it is an array whose items all pass the optional
1057
+ * `isValidItem` predicate; otherwise returns `fallback`.
1058
+ */
1059
+ declare function sanitizeStoredArray<T>(value: unknown, fallback: T[], isValidItem?: (item: unknown) => boolean): T[];
1060
+ /**
1061
+ * Predicate matching the `{ accessor: string, ... }` shape persisted for column
1062
+ * toggle and pinning state.
1063
+ */
1064
+ declare function hasStringAccessor(item: unknown): boolean;
1065
+ /**
1066
+ * Utility function that returns an array of values that are present in the first array but not in the second
1067
+ */
1068
+ declare function differenceBy<T>(arr1: T[], arr2: T[], iteratee: (value: T) => unknown): T[];
1069
+ /**
1070
+ * Utility function that returns an array of unique values from a given array
1071
+ */
1072
+ declare function uniqBy<T>(arr: T[], iteratee: (value: T) => unknown): T[];
1073
+ /**
1074
+ * Utility function that returns the value at a given path in an object
1075
+ */
1076
+ declare function getValueAtPath<T>(obj: T, path: keyof T | (string & NonNullable<unknown>)): unknown;
1077
+ /**
1078
+ * Utility function that returns the record id using idAccessor
1079
+ */
1080
+ declare function getRecordId<T>(record: T, idAccessor: keyof T | (string & NonNullable<unknown>) | ((record: T) => React.Key)): unknown;
1081
+ /**
1082
+ * Utility function that reorders an array of records by a given field used for drag'n'drop functionality.
1083
+ * @see https://github.com/hello-pangea/dnd
1084
+ */
1085
+ declare function reorderRecords<T>(dropResult: DropResult, records: T[]): T[];
1086
+ /**
1087
+ * Utility function that swaps elements of an array, by a given result from drag'n'drop functionality.
1088
+ * @see https://github.com/hello-pangea/dnd
1089
+ */
1090
+ declare function swapRecords<T>(dropResult: DropResult, records: T[]): T[];
1091
+ /**
1092
+ * Calculates the maximum depth of nested column groups
1093
+ */
1094
+ declare function getMaxGroupDepth<T>(groups: readonly DataTableColumnGroup<T>[]): number;
1095
+ /**
1096
+ * Flattens nested column groups to extract all columns at the deepest level
1097
+ */
1098
+ declare function flattenColumns<T>(groups: DataTableColumnGroup<T>[]): DataTableColumn<T>[];
1099
+ /**
1100
+ * Calculates the column span for a group based on visible columns
1101
+ */
1102
+ declare function calculateColSpan<T>(group: DataTableColumnGroup<T>, visibles?: (boolean | undefined)[]): number;
1103
+ /**
1104
+ * Gets all groups at a specific depth level
1105
+ */
1106
+ declare function getGroupsAtDepth<T>(groups: readonly DataTableColumnGroup<T>[], targetDepth: number, currentDepth?: number): DataTableColumnGroup<T>[];
1107
+ /**
1108
+ * Checks if a group needs a right border based on its position and context
1109
+ */
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 };