mantine-datatable 9.4.0 → 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 +968 -1005
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +74 -46
- package/dist/styles.layer.css +74 -46
- package/package.json +34 -34
package/dist/index.d.ts
CHANGED
|
@@ -1,1046 +1,1010 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { JSX, Ref, RefObject } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
borderRadius?: never;
|
|
261
|
+
export type DataTableOuterBorderProps = {
|
|
262
|
+
withTableBorder?: never;
|
|
263
|
+
borderRadius?: never;
|
|
273
264
|
} | {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
275
|
+
onRecordsPerPageChange?: never;
|
|
276
|
+
recordsPerPageOptions?: never;
|
|
277
|
+
recordsPerPageLabel?: never;
|
|
288
278
|
} | {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
329
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
495
|
+
/**
|
|
496
|
+
* Grouped columns.
|
|
497
|
+
*/
|
|
498
|
+
groups: DataTableColumnGroup<T>[];
|
|
499
|
+
columns?: never;
|
|
514
500
|
} | {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
501
|
+
groups?: never;
|
|
502
|
+
/**
|
|
503
|
+
* Visible columns.
|
|
504
|
+
*/
|
|
505
|
+
columns: DataTableColumn<T>[];
|
|
520
506
|
};
|
|
521
|
-
|
|
522
507
|
type DataTableLoaderProps = {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
508
|
+
/**
|
|
509
|
+
* Loader background blur (in pixels).
|
|
510
|
+
*/
|
|
511
|
+
loaderBackgroundBlur?: number;
|
|
527
512
|
} & ({
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
}) =>
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
*
|
|
600
|
-
*/
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
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
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
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
|
-
|
|
730
|
-
|
|
731
|
-
onSortStatusChange?: never;
|
|
706
|
+
export type DataTableSortProps<T = Record<string, unknown>> = ({
|
|
707
|
+
sortStatus?: never;
|
|
708
|
+
onSortStatusChange?: never;
|
|
732
709
|
} | {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
728
|
+
sorted: React.ReactNode;
|
|
864
729
|
/**
|
|
865
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
936
|
+
accessor: string;
|
|
937
|
+
defaultPinned: "left" | "right" | undefined;
|
|
938
|
+
pinnable: boolean;
|
|
939
|
+
pinned: "left" | "right" | undefined;
|
|
971
940
|
};
|
|
972
|
-
|
|
973
941
|
type DataTableColumnToggle = {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
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
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
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
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
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 };
|