material-react-table 2.7.0 → 2.9.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.
- package/dist/index.d.ts +253 -99
- package/dist/index.esm.js +3546 -3475
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3567 -3498
- package/dist/index.js.map +1 -1
- package/locales/ja/index.esm.js +4 -4
- package/locales/ja/index.js +4 -4
- package/package.json +25 -23
- package/src/{MaterialReactTable.tsx → components/MaterialReactTable.tsx} +3 -3
- package/src/{body → components/body}/MRT_TableBody.tsx +6 -7
- package/src/{body → components/body}/MRT_TableBodyCell.tsx +16 -26
- package/src/{body → components/body}/MRT_TableBodyCellValue.tsx +2 -2
- package/src/{body → components/body}/MRT_TableBodyRow.tsx +79 -59
- package/src/{body → components/body}/MRT_TableBodyRowGrabHandle.tsx +3 -3
- package/src/{body → components/body}/MRT_TableBodyRowPinButton.tsx +3 -3
- package/src/{body → components/body}/MRT_TableDetailPanel.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_ColumnPinningButtons.tsx +2 -2
- package/src/{buttons → components/buttons}/MRT_CopyButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_EditActionButtons.tsx +2 -2
- package/src/{buttons → components/buttons}/MRT_ExpandAllButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_ExpandButton.tsx +6 -3
- package/src/{buttons → components/buttons}/MRT_GrabHandleButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_RowPinButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_ShowHideColumnsButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleDensePaddingButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleFiltersButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleFullScreenButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleGlobalFilterButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleRowActionMenuButton.tsx +4 -4
- package/src/{footer → components/footer}/MRT_TableFooter.tsx +2 -2
- package/src/{footer → components/footer}/MRT_TableFooterCell.tsx +13 -4
- package/src/{footer → components/footer}/MRT_TableFooterRow.tsx +22 -11
- package/src/{head → components/head}/MRT_TableHead.tsx +3 -3
- package/src/{head → components/head}/MRT_TableHeadCell.tsx +13 -3
- package/src/{head → components/head}/MRT_TableHeadCellColumnActionsButton.tsx +4 -4
- package/src/{head → components/head}/MRT_TableHeadCellFilterContainer.tsx +5 -5
- package/src/{head → components/head}/MRT_TableHeadCellFilterLabel.tsx +2 -2
- package/src/{head → components/head}/MRT_TableHeadCellGrabHandle.tsx +4 -3
- package/src/{head → components/head}/MRT_TableHeadCellResizeHandle.tsx +6 -4
- package/src/{head → components/head}/MRT_TableHeadCellSortLabel.tsx +2 -2
- package/src/{head → components/head}/MRT_TableHeadRow.tsx +22 -11
- package/src/{inputs → components/inputs}/MRT_EditCellTextField.tsx +15 -6
- package/src/{inputs → components/inputs}/MRT_FilterCheckbox.tsx +3 -3
- package/src/{inputs → components/inputs}/MRT_FilterRangeFields.tsx +2 -2
- package/src/{inputs → components/inputs}/MRT_FilterRangeSlider.tsx +2 -2
- package/src/{inputs → components/inputs}/MRT_FilterTextField.tsx +3 -3
- package/src/{inputs → components/inputs}/MRT_GlobalFilterTextField.tsx +2 -2
- package/src/{inputs → components/inputs}/MRT_SelectCheckbox.tsx +7 -9
- package/src/{menus → components/menus}/MRT_ColumnActionMenu.tsx +8 -8
- package/src/{menus → components/menus}/MRT_FilterOptionMenu.tsx +2 -2
- package/src/{menus → components/menus}/MRT_RowActionMenu.tsx +9 -9
- package/src/{menus → components/menus}/MRT_ShowHideColumnsMenu.tsx +5 -7
- package/src/{menus → components/menus}/MRT_ShowHideColumnsMenuItems.tsx +6 -5
- package/src/{modals → components/modals}/MRT_EditRowModal.tsx +4 -4
- package/src/{table → components/table}/MRT_Table.tsx +8 -4
- package/src/{table → components/table}/MRT_TableContainer.tsx +2 -2
- package/src/{table → components/table}/MRT_TableLoadingOverlay.tsx +3 -3
- package/src/{table → components/table}/MRT_TablePaper.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_BottomToolbar.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_LinearProgressBar.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_TablePagination.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_ToolbarAlertBanner.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_ToolbarDropZone.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_ToolbarInternalButtons.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_TopToolbar.tsx +3 -3
- package/src/{filterFns.ts → fns/filterFns.ts} +1 -1
- package/src/{sortingFns.ts → fns/sortingFns.ts} +1 -1
- package/src/hooks/display-columns/getMRT_DisplayColumns.tsx +26 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +35 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +36 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +98 -0
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +37 -0
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +31 -0
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +41 -0
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +40 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +79 -80
- package/src/hooks/useMRT_Effects.ts +1 -1
- package/src/hooks/useMRT_RowVirtualizer.ts +32 -36
- package/src/hooks/useMRT_Rows.ts +2 -2
- package/src/hooks/useMRT_TableInstance.ts +54 -39
- package/src/hooks/useMRT_TableOptions.ts +30 -20
- package/src/{useMaterialReactTable.ts → hooks/useMaterialReactTable.ts} +3 -3
- package/src/index.ts +79 -82
- package/src/locales/ja.ts +4 -4
- package/src/types.ts +57 -26
- package/src/utils/column.utils.ts +173 -0
- package/src/utils/displayColumn.utils.ts +134 -0
- package/src/utils/row.utils.ts +47 -0
- package/src/{style.utils.ts → utils/style.utils.ts} +88 -42
- package/src/utils/tanstack.helpers.ts +64 -0
- package/src/utils/utils.ts +23 -0
- package/src/utils/virtualization.utils.ts +19 -0
- package/src/utils.ts +0 -0
- package/src/column.utils.ts +0 -361
- package/src/hooks/useMRT_DisplayColumns.tsx +0 -290
- /package/src/{aggregationFns.ts → fns/aggregationFns.ts} +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
import { useMemo } from 'react';
|
2
2
|
import { useTheme } from '@mui/material/styles';
|
3
|
-
import { MRT_AggregationFns } from '../aggregationFns';
|
4
|
-
import { MRT_FilterFns } from '../filterFns';
|
3
|
+
import { MRT_AggregationFns } from '../fns/aggregationFns';
|
4
|
+
import { MRT_FilterFns } from '../fns/filterFns';
|
5
|
+
import { MRT_SortingFns } from '../fns/sortingFns';
|
5
6
|
import { MRT_Default_Icons } from '../icons';
|
6
7
|
import { MRT_Localization_EN } from '../locales/en';
|
7
|
-
import { MRT_SortingFns } from '../sortingFns';
|
8
8
|
import {
|
9
9
|
type MRT_DefinedTableOptions,
|
10
10
|
type MRT_RowData,
|
@@ -51,6 +51,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
51
51
|
enableColumnOrdering = false,
|
52
52
|
enableColumnPinning = false,
|
53
53
|
enableColumnResizing = false,
|
54
|
+
enableColumnVirtualization,
|
54
55
|
enableDensityToggle = true,
|
55
56
|
enableExpandAll = true,
|
56
57
|
enableExpanding,
|
@@ -66,6 +67,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
66
67
|
enablePagination = true,
|
67
68
|
enableRowPinning = false,
|
68
69
|
enableRowSelection = false,
|
70
|
+
enableRowVirtualization,
|
69
71
|
enableSelectAll = true,
|
70
72
|
enableSorting = true,
|
71
73
|
enableStickyHeader = false,
|
@@ -96,31 +98,37 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
96
98
|
...rest
|
97
99
|
}: MRT_TableOptions<TData>) => {
|
98
100
|
const theme = useTheme();
|
99
|
-
|
100
|
-
|
101
|
+
|
102
|
+
icons = useMemo(() => ({ ...MRT_Default_Icons, ...icons }), [icons]);
|
103
|
+
localization = useMemo(
|
101
104
|
() => ({
|
102
105
|
...MRT_Localization_EN,
|
103
106
|
...localization,
|
104
107
|
}),
|
105
108
|
[localization],
|
106
109
|
);
|
107
|
-
|
110
|
+
aggregationFns = useMemo(
|
108
111
|
() => ({ ...MRT_AggregationFns, ...aggregationFns }),
|
109
112
|
[],
|
110
113
|
);
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
+
filterFns = useMemo(() => ({ ...MRT_FilterFns, ...filterFns }), []);
|
115
|
+
sortingFns = useMemo(() => ({ ...MRT_SortingFns, ...sortingFns }), []);
|
116
|
+
defaultColumn = useMemo(
|
114
117
|
() => ({ ...MRT_DefaultColumn, ...defaultColumn }),
|
115
118
|
[defaultColumn],
|
116
119
|
);
|
117
|
-
|
120
|
+
defaultDisplayColumn = useMemo(
|
118
121
|
() => ({
|
119
122
|
...MRT_DefaultDisplayColumn,
|
120
123
|
...defaultDisplayColumn,
|
121
124
|
}),
|
122
125
|
[defaultDisplayColumn],
|
123
126
|
);
|
127
|
+
//cannot be changed after initialization
|
128
|
+
[enableColumnVirtualization, enableRowVirtualization] = useMemo(
|
129
|
+
() => [enableColumnVirtualization, enableRowVirtualization],
|
130
|
+
[],
|
131
|
+
);
|
124
132
|
|
125
133
|
if (!columnResizeDirection) {
|
126
134
|
columnResizeDirection = theme.direction || 'ltr';
|
@@ -130,12 +138,12 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
130
138
|
layoutMode || (enableColumnResizing ? 'grid-no-grow' : 'semantic');
|
131
139
|
if (
|
132
140
|
layoutMode === 'semantic' &&
|
133
|
-
(
|
141
|
+
(enableRowVirtualization || enableColumnVirtualization)
|
134
142
|
) {
|
135
143
|
layoutMode = 'grid';
|
136
144
|
}
|
137
145
|
|
138
|
-
if (
|
146
|
+
if (enableRowVirtualization) {
|
139
147
|
enableStickyHeader = true;
|
140
148
|
}
|
141
149
|
|
@@ -151,14 +159,14 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
151
159
|
}
|
152
160
|
|
153
161
|
return {
|
154
|
-
aggregationFns
|
162
|
+
aggregationFns,
|
155
163
|
autoResetExpanded,
|
156
164
|
columnFilterDisplayMode,
|
157
165
|
columnResizeDirection,
|
158
166
|
columnResizeMode,
|
159
167
|
createDisplayMode,
|
160
|
-
defaultColumn
|
161
|
-
defaultDisplayColumn
|
168
|
+
defaultColumn,
|
169
|
+
defaultDisplayColumn,
|
162
170
|
editDisplayMode,
|
163
171
|
enableBottomToolbar,
|
164
172
|
enableColumnActions,
|
@@ -166,6 +174,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
166
174
|
enableColumnOrdering,
|
167
175
|
enableColumnPinning,
|
168
176
|
enableColumnResizing,
|
177
|
+
enableColumnVirtualization,
|
169
178
|
enableDensityToggle,
|
170
179
|
enableExpandAll,
|
171
180
|
enableExpanding,
|
@@ -181,6 +190,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
181
190
|
enablePagination,
|
182
191
|
enableRowPinning,
|
183
192
|
enableRowSelection,
|
193
|
+
enableRowVirtualization,
|
184
194
|
enableSelectAll,
|
185
195
|
enableSorting,
|
186
196
|
enableStickyHeader,
|
@@ -188,10 +198,10 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
188
198
|
enableTableHead,
|
189
199
|
enableToolbarInternalActions,
|
190
200
|
enableTopToolbar,
|
191
|
-
filterFns
|
192
|
-
icons
|
201
|
+
filterFns,
|
202
|
+
icons,
|
193
203
|
layoutMode,
|
194
|
-
localization
|
204
|
+
localization,
|
195
205
|
manualFiltering,
|
196
206
|
manualGrouping,
|
197
207
|
manualPagination,
|
@@ -207,7 +217,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
207
217
|
rowNumberDisplayMode,
|
208
218
|
rowPinningDisplayMode,
|
209
219
|
selectAllMode,
|
210
|
-
sortingFns
|
220
|
+
sortingFns,
|
211
221
|
...rest,
|
212
|
-
}
|
222
|
+
} as MRT_DefinedTableOptions<TData>;
|
213
223
|
};
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { useMRT_TableInstance } from './hooks/useMRT_TableInstance';
|
2
|
-
import { useMRT_TableOptions } from './hooks/useMRT_TableOptions';
|
3
1
|
import {
|
4
2
|
type MRT_RowData,
|
5
3
|
type MRT_TableInstance,
|
6
4
|
type MRT_TableOptions,
|
7
|
-
} from '
|
5
|
+
} from '../types';
|
6
|
+
import { useMRT_TableInstance } from './useMRT_TableInstance';
|
7
|
+
import { useMRT_TableOptions } from './useMRT_TableOptions';
|
8
8
|
|
9
9
|
export const useMaterialReactTable = <TData extends MRT_RowData>(
|
10
10
|
tableOptions: MRT_TableOptions<TData>,
|
package/src/index.ts
CHANGED
@@ -1,92 +1,89 @@
|
|
1
|
-
//root
|
2
|
-
export * from './MaterialReactTable';
|
3
|
-
export * from './aggregationFns';
|
4
|
-
export * from './column.utils';
|
5
|
-
export * from './filterFns';
|
6
|
-
export * from './sortingFns';
|
7
|
-
export * from './style.utils';
|
8
1
|
export * from './types';
|
9
|
-
|
2
|
+
|
3
|
+
//helpers
|
4
|
+
export * from './utils/tanstack.helpers';
|
5
|
+
export * from './utils/column.utils';
|
6
|
+
export * from './utils/displayColumn.utils';
|
7
|
+
export * from './utils/row.utils';
|
8
|
+
|
9
|
+
//fns
|
10
|
+
export * from './fns/aggregationFns';
|
11
|
+
export * from './fns/filterFns';
|
12
|
+
export * from './fns/sortingFns';
|
10
13
|
|
11
14
|
//hooks
|
15
|
+
export * from './hooks/useMaterialReactTable';
|
12
16
|
export * from './hooks/useMRT_ColumnVirtualizer';
|
13
|
-
export * from './hooks/useMRT_DisplayColumns';
|
14
17
|
export * from './hooks/useMRT_Effects';
|
15
18
|
export * from './hooks/useMRT_RowVirtualizer';
|
16
19
|
export * from './hooks/useMRT_Rows';
|
17
20
|
export * from './hooks/useMRT_TableInstance';
|
18
21
|
export * from './hooks/useMRT_TableOptions';
|
19
22
|
|
20
|
-
//
|
21
|
-
export * from './
|
22
|
-
|
23
|
-
export * from './body/
|
24
|
-
export * from './body/
|
25
|
-
export * from './body/
|
26
|
-
export * from './body/
|
27
|
-
export * from './body/
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
export * from './buttons/
|
32
|
-
export * from './buttons/
|
33
|
-
export * from './buttons/
|
34
|
-
export * from './buttons/
|
35
|
-
export * from './buttons/
|
36
|
-
export * from './buttons/
|
37
|
-
export * from './buttons/
|
38
|
-
export * from './buttons/
|
39
|
-
export * from './buttons/
|
40
|
-
export * from './buttons/
|
41
|
-
export * from './buttons/
|
42
|
-
export * from './buttons/
|
43
|
-
|
44
|
-
//footer
|
45
|
-
export * from './footer/MRT_TableFooter';
|
46
|
-
export * from './footer/MRT_TableFooterCell';
|
47
|
-
export * from './footer/MRT_TableFooterRow';
|
48
|
-
|
49
|
-
|
50
|
-
export * from './head/
|
51
|
-
export * from './head/
|
52
|
-
export * from './head/
|
53
|
-
export * from './head/
|
54
|
-
export * from './head/
|
55
|
-
export * from './head/
|
56
|
-
export * from './head/
|
57
|
-
export * from './head/
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
export * from './inputs/
|
62
|
-
export * from './inputs/
|
63
|
-
export * from './inputs/
|
64
|
-
export * from './inputs/
|
65
|
-
export * from './inputs/
|
66
|
-
|
67
|
-
export * from './
|
68
|
-
|
69
|
-
|
70
|
-
export * from './menus/
|
71
|
-
export * from './menus/
|
72
|
-
|
73
|
-
export * from './
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
export * from './
|
78
|
-
|
79
|
-
//
|
80
|
-
export * from './
|
81
|
-
export * from './
|
82
|
-
export * from './
|
83
|
-
export * from './
|
84
|
-
|
85
|
-
|
86
|
-
export * from './toolbar/
|
87
|
-
export * from './toolbar/MRT_LinearProgressBar';
|
88
|
-
export * from './toolbar/MRT_TablePagination';
|
89
|
-
export * from './toolbar/MRT_ToolbarAlertBanner';
|
90
|
-
export * from './toolbar/MRT_ToolbarDropZone';
|
91
|
-
export * from './toolbar/MRT_ToolbarInternalButtons';
|
92
|
-
export * from './toolbar/MRT_TopToolbar';
|
23
|
+
//components
|
24
|
+
export * from './components/MaterialReactTable';
|
25
|
+
//body components
|
26
|
+
export * from './components/body/MRT_TableBody';
|
27
|
+
export * from './components/body/MRT_TableBodyCell';
|
28
|
+
export * from './components/body/MRT_TableBodyCellValue';
|
29
|
+
export * from './components/body/MRT_TableBodyRow';
|
30
|
+
export * from './components/body/MRT_TableBodyRowGrabHandle';
|
31
|
+
export * from './components/body/MRT_TableBodyRowPinButton';
|
32
|
+
export * from './components/body/MRT_TableDetailPanel';
|
33
|
+
//button components
|
34
|
+
export * from './components/buttons/MRT_ColumnPinningButtons';
|
35
|
+
export * from './components/buttons/MRT_CopyButton';
|
36
|
+
export * from './components/buttons/MRT_EditActionButtons';
|
37
|
+
export * from './components/buttons/MRT_ExpandAllButton';
|
38
|
+
export * from './components/buttons/MRT_ExpandButton';
|
39
|
+
export * from './components/buttons/MRT_GrabHandleButton';
|
40
|
+
export * from './components/buttons/MRT_RowPinButton';
|
41
|
+
export * from './components/buttons/MRT_ShowHideColumnsButton';
|
42
|
+
export * from './components/buttons/MRT_ToggleDensePaddingButton';
|
43
|
+
export * from './components/buttons/MRT_ToggleFiltersButton';
|
44
|
+
export * from './components/buttons/MRT_ToggleFullScreenButton';
|
45
|
+
export * from './components/buttons/MRT_ToggleGlobalFilterButton';
|
46
|
+
export * from './components/buttons/MRT_ToggleRowActionMenuButton';
|
47
|
+
//footer components
|
48
|
+
export * from './components/footer/MRT_TableFooter';
|
49
|
+
export * from './components/footer/MRT_TableFooterCell';
|
50
|
+
export * from './components/footer/MRT_TableFooterRow';
|
51
|
+
//head components
|
52
|
+
export * from './components/head/MRT_TableHead';
|
53
|
+
export * from './components/head/MRT_TableHeadCell';
|
54
|
+
export * from './components/head/MRT_TableHeadCellColumnActionsButton';
|
55
|
+
export * from './components/head/MRT_TableHeadCellFilterContainer';
|
56
|
+
export * from './components/head/MRT_TableHeadCellFilterLabel';
|
57
|
+
export * from './components/head/MRT_TableHeadCellGrabHandle';
|
58
|
+
export * from './components/head/MRT_TableHeadCellResizeHandle';
|
59
|
+
export * from './components/head/MRT_TableHeadCellSortLabel';
|
60
|
+
export * from './components/head/MRT_TableHeadRow';
|
61
|
+
//input components
|
62
|
+
export * from './components/inputs/MRT_EditCellTextField';
|
63
|
+
export * from './components/inputs/MRT_FilterCheckbox';
|
64
|
+
export * from './components/inputs/MRT_FilterRangeFields';
|
65
|
+
export * from './components/inputs/MRT_FilterRangeSlider';
|
66
|
+
export * from './components/inputs/MRT_FilterTextField';
|
67
|
+
export * from './components/inputs/MRT_GlobalFilterTextField';
|
68
|
+
export * from './components/inputs/MRT_SelectCheckbox';
|
69
|
+
//menu components
|
70
|
+
export * from './components/menus/MRT_ColumnActionMenu';
|
71
|
+
export * from './components/menus/MRT_FilterOptionMenu';
|
72
|
+
export * from './components/menus/MRT_RowActionMenu';
|
73
|
+
export * from './components/menus/MRT_ShowHideColumnsMenu';
|
74
|
+
export * from './components/menus/MRT_ShowHideColumnsMenuItems';
|
75
|
+
//modal components
|
76
|
+
export * from './components/modals/MRT_EditRowModal';
|
77
|
+
//table components
|
78
|
+
export * from './components/table/MRT_Table';
|
79
|
+
export * from './components/table/MRT_TableContainer';
|
80
|
+
export * from './components/table/MRT_TableLoadingOverlay';
|
81
|
+
export * from './components/table/MRT_TablePaper';
|
82
|
+
//toolbar components
|
83
|
+
export * from './components/toolbar/MRT_BottomToolbar';
|
84
|
+
export * from './components/toolbar/MRT_LinearProgressBar';
|
85
|
+
export * from './components/toolbar/MRT_TablePagination';
|
86
|
+
export * from './components/toolbar/MRT_ToolbarAlertBanner';
|
87
|
+
export * from './components/toolbar/MRT_ToolbarDropZone';
|
88
|
+
export * from './components/toolbar/MRT_ToolbarInternalButtons';
|
89
|
+
export * from './components/toolbar/MRT_TopToolbar';
|
package/src/locales/ja.ts
CHANGED
@@ -78,10 +78,10 @@ export const MRT_Localization_JA: MRT_Localization = {
|
|
78
78
|
showHideColumns: '列の表示状態',
|
79
79
|
showHideFilters: '検索バーを表示',
|
80
80
|
showHideSearch: '検索',
|
81
|
-
sortByColumnAsc: '{column}
|
82
|
-
sortByColumnDesc: '{column}
|
83
|
-
sortedByColumnAsc: '{column}
|
84
|
-
sortedByColumnDesc: '{column}
|
81
|
+
sortByColumnAsc: '{column}を昇順で並べ替え',
|
82
|
+
sortByColumnDesc: '{column}を降順で並べ替え',
|
83
|
+
sortedByColumnAsc: '{column}を昇順で並べ替え',
|
84
|
+
sortedByColumnDesc: '{column}を降順で並べ替え',
|
85
85
|
thenBy: 'さらに',
|
86
86
|
toggleDensity: 'テーブルの高さを変更',
|
87
87
|
toggleFullScreen: 'フルスクリーン切り替え',
|
package/src/types.ts
CHANGED
@@ -71,10 +71,10 @@ import {
|
|
71
71
|
type DateTimePickerProps,
|
72
72
|
type TimePickerProps,
|
73
73
|
} from '@mui/x-date-pickers';
|
74
|
-
import { type MRT_AggregationFns } from './aggregationFns';
|
75
|
-
import { type MRT_FilterFns } from './filterFns';
|
74
|
+
import { type MRT_AggregationFns } from './fns/aggregationFns';
|
75
|
+
import { type MRT_FilterFns } from './fns/filterFns';
|
76
|
+
import { type MRT_SortingFns } from './fns/sortingFns';
|
76
77
|
import { type MRT_Icons } from './icons';
|
77
|
-
import { type MRT_SortingFns } from './sortingFns';
|
78
78
|
|
79
79
|
export type { MRT_Icons };
|
80
80
|
export type LiteralUnion<T extends U, U = string> =
|
@@ -87,6 +87,17 @@ export type Xor<A, B> =
|
|
87
87
|
| Prettify<A & { [k in keyof B]?: never }>
|
88
88
|
| Prettify<B & { [k in keyof A]?: never }>;
|
89
89
|
|
90
|
+
export type DropdownOption =
|
91
|
+
| {
|
92
|
+
label?: string;
|
93
|
+
/**
|
94
|
+
* @deprecated use `label` instead
|
95
|
+
*/
|
96
|
+
text?: string;
|
97
|
+
value: any;
|
98
|
+
}
|
99
|
+
| string;
|
100
|
+
|
90
101
|
export type MRT_DensityState = 'comfortable' | 'compact' | 'spacious';
|
91
102
|
|
92
103
|
export type MRT_ColumnFilterFnsState = Record<string, MRT_FilterOption>;
|
@@ -302,7 +313,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
|
|
302
313
|
getSelectedRowModel: () => MRT_RowModel<TData>;
|
303
314
|
getState: () => MRT_TableState<TData>;
|
304
315
|
getTopRows: () => MRT_Row<TData>[];
|
305
|
-
options:
|
316
|
+
options: MRT_StatefulTableOptions<TData>;
|
306
317
|
refs: {
|
307
318
|
bottomToolbarRef: MutableRefObject<HTMLDivElement>;
|
308
319
|
editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
@@ -338,6 +349,32 @@ export type MRT_DefinedTableOptions<TData extends MRT_RowData> =
|
|
338
349
|
localization: MRT_Localization;
|
339
350
|
};
|
340
351
|
|
352
|
+
export type MRT_StatefulTableOptions<TData extends MRT_RowData> =
|
353
|
+
MRT_DefinedTableOptions<TData> & {
|
354
|
+
state: Pick<
|
355
|
+
MRT_TableState<TData>,
|
356
|
+
| 'columnFilterFns'
|
357
|
+
| 'columnOrder'
|
358
|
+
| 'columnSizingInfo'
|
359
|
+
| 'creatingRow'
|
360
|
+
| 'density'
|
361
|
+
| 'draggingColumn'
|
362
|
+
| 'draggingRow'
|
363
|
+
| 'editingCell'
|
364
|
+
| 'editingRow'
|
365
|
+
| 'globalFilterFn'
|
366
|
+
| 'grouping'
|
367
|
+
| 'hoveredColumn'
|
368
|
+
| 'hoveredRow'
|
369
|
+
| 'isFullScreen'
|
370
|
+
| 'pagination'
|
371
|
+
| 'showAlertBanner'
|
372
|
+
| 'showColumnFilters'
|
373
|
+
| 'showGlobalFilter'
|
374
|
+
| 'showToolbarDropZone'
|
375
|
+
>;
|
376
|
+
};
|
377
|
+
|
341
378
|
export type MRT_TableState<TData extends MRT_RowData> = TableState & {
|
342
379
|
columnFilterFns: MRT_ColumnFilterFnsState;
|
343
380
|
creatingRow: MRT_Row<TData> | null;
|
@@ -457,17 +494,14 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
457
494
|
LiteralUnion<string & MRT_FilterOption>
|
458
495
|
> | null;
|
459
496
|
columns?: MRT_ColumnDef<TData, TValue>[];
|
460
|
-
editSelectOptions?:
|
461
|
-
| {
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
}
|
469
|
-
| string
|
470
|
-
)[];
|
497
|
+
editSelectOptions?:
|
498
|
+
| ((props: {
|
499
|
+
cell: MRT_Cell<TData, TValue>;
|
500
|
+
column: MRT_Column<TData>;
|
501
|
+
row: MRT_Row<TData>;
|
502
|
+
table: MRT_TableInstance<TData>;
|
503
|
+
}) => DropdownOption[])
|
504
|
+
| DropdownOption[];
|
471
505
|
editVariant?: 'select' | 'text';
|
472
506
|
enableClickToCopy?: boolean;
|
473
507
|
enableColumnActions?: boolean;
|
@@ -477,17 +511,7 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
477
511
|
enableEditing?: ((row: MRT_Row<TData>) => boolean) | boolean;
|
478
512
|
enableFilterMatchHighlighting?: boolean;
|
479
513
|
filterFn?: MRT_FilterFn<TData>;
|
480
|
-
filterSelectOptions?:
|
481
|
-
| {
|
482
|
-
label?: string;
|
483
|
-
/**
|
484
|
-
* @deprecated use `label` instead
|
485
|
-
*/
|
486
|
-
text?: string;
|
487
|
-
value: any;
|
488
|
-
}
|
489
|
-
| string
|
490
|
-
)[];
|
514
|
+
filterSelectOptions?: DropdownOption[];
|
491
515
|
filterVariant?:
|
492
516
|
| 'autocomplete'
|
493
517
|
| 'checkbox'
|
@@ -506,6 +530,10 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
506
530
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
507
531
|
*/
|
508
532
|
footer?: string;
|
533
|
+
/**
|
534
|
+
* If `layoutMode` is `'grid'` or `'grid-no-grow'`, you can specify the flex grow value for individual columns to still grow and take up remaining space, or set to `false`/0 to not grow.
|
535
|
+
*/
|
536
|
+
grow?: boolean | number;
|
509
537
|
/**
|
510
538
|
* header must be a string. If you want custom JSX to render the header, you can also specify a `Header` option. (Capital H)
|
511
539
|
*/
|
@@ -1136,6 +1164,9 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
1136
1164
|
renderBottomToolbarCustomActions?: (props: {
|
1137
1165
|
table: MRT_TableInstance<TData>;
|
1138
1166
|
}) => ReactNode;
|
1167
|
+
renderCaption?:
|
1168
|
+
| ((props: { table: MRT_TableInstance<TData> }) => ReactNode)
|
1169
|
+
| ReactNode;
|
1139
1170
|
renderColumnActionsMenuItems?: (props: {
|
1140
1171
|
closeMenu: () => void;
|
1141
1172
|
column: MRT_Column<TData>;
|
@@ -0,0 +1,173 @@
|
|
1
|
+
import { type Row } from '@tanstack/react-table';
|
2
|
+
import {
|
3
|
+
type MRT_Column,
|
4
|
+
type MRT_ColumnDef,
|
5
|
+
type MRT_ColumnOrderState,
|
6
|
+
type MRT_DefinedColumnDef,
|
7
|
+
type MRT_DefinedTableOptions,
|
8
|
+
type MRT_FilterOption,
|
9
|
+
type MRT_RowData,
|
10
|
+
type MRT_TableInstance,
|
11
|
+
} from '../types';
|
12
|
+
|
13
|
+
export const getColumnId = <TData extends MRT_RowData>(
|
14
|
+
columnDef: MRT_ColumnDef<TData>,
|
15
|
+
): string =>
|
16
|
+
columnDef.id ?? columnDef.accessorKey?.toString?.() ?? columnDef.header;
|
17
|
+
|
18
|
+
export const getAllLeafColumnDefs = <TData extends MRT_RowData>(
|
19
|
+
columns: MRT_ColumnDef<TData>[],
|
20
|
+
): MRT_ColumnDef<TData>[] => {
|
21
|
+
const allLeafColumnDefs: MRT_ColumnDef<TData>[] = [];
|
22
|
+
const getLeafColumns = (cols: MRT_ColumnDef<TData>[]) => {
|
23
|
+
cols.forEach((col) => {
|
24
|
+
if (col.columns) {
|
25
|
+
getLeafColumns(col.columns);
|
26
|
+
} else {
|
27
|
+
allLeafColumnDefs.push(col);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
31
|
+
getLeafColumns(columns);
|
32
|
+
return allLeafColumnDefs;
|
33
|
+
};
|
34
|
+
|
35
|
+
export const prepareColumns = <TData extends MRT_RowData>({
|
36
|
+
columnDefs,
|
37
|
+
tableOptions,
|
38
|
+
}: {
|
39
|
+
columnDefs: MRT_ColumnDef<TData>[];
|
40
|
+
tableOptions: MRT_DefinedTableOptions<TData>;
|
41
|
+
}): MRT_DefinedColumnDef<TData>[] => {
|
42
|
+
const {
|
43
|
+
aggregationFns = {},
|
44
|
+
defaultDisplayColumn,
|
45
|
+
filterFns = {},
|
46
|
+
sortingFns = {},
|
47
|
+
state: { columnFilterFns = {} } = {},
|
48
|
+
} = tableOptions;
|
49
|
+
return columnDefs.map((columnDef) => {
|
50
|
+
//assign columnId
|
51
|
+
if (!columnDef.id) columnDef.id = getColumnId(columnDef);
|
52
|
+
//assign columnDefType
|
53
|
+
if (!columnDef.columnDefType) columnDef.columnDefType = 'data';
|
54
|
+
if (columnDef.columns?.length) {
|
55
|
+
columnDef.columnDefType = 'group';
|
56
|
+
//recursively prepare columns if this is a group column
|
57
|
+
columnDef.columns = prepareColumns({
|
58
|
+
columnDefs: columnDef.columns,
|
59
|
+
tableOptions,
|
60
|
+
});
|
61
|
+
} else if (columnDef.columnDefType === 'data') {
|
62
|
+
//assign aggregationFns if multiple aggregationFns are provided
|
63
|
+
if (Array.isArray(columnDef.aggregationFn)) {
|
64
|
+
const aggFns = columnDef.aggregationFn as string[];
|
65
|
+
columnDef.aggregationFn = (
|
66
|
+
columnId: string,
|
67
|
+
leafRows: Row<TData>[],
|
68
|
+
childRows: Row<TData>[],
|
69
|
+
) =>
|
70
|
+
aggFns.map((fn) =>
|
71
|
+
aggregationFns[fn]?.(columnId, leafRows, childRows),
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
//assign filterFns
|
76
|
+
if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
|
77
|
+
columnDef.filterFn =
|
78
|
+
filterFns[columnFilterFns[columnDef.id]] ?? filterFns.fuzzy;
|
79
|
+
(columnDef as MRT_DefinedColumnDef<TData>)._filterFn =
|
80
|
+
columnFilterFns[columnDef.id];
|
81
|
+
}
|
82
|
+
|
83
|
+
//assign sortingFns
|
84
|
+
if (Object.keys(sortingFns).includes(columnDef.sortingFn as string)) {
|
85
|
+
// @ts-ignore
|
86
|
+
columnDef.sortingFn = sortingFns[columnDef.sortingFn];
|
87
|
+
}
|
88
|
+
} else if (columnDef.columnDefType === 'display') {
|
89
|
+
columnDef = {
|
90
|
+
...(defaultDisplayColumn as MRT_ColumnDef<TData>),
|
91
|
+
...columnDef,
|
92
|
+
};
|
93
|
+
}
|
94
|
+
return columnDef;
|
95
|
+
}) as MRT_DefinedColumnDef<TData>[];
|
96
|
+
};
|
97
|
+
|
98
|
+
export const reorderColumn = <TData extends MRT_RowData>(
|
99
|
+
draggedColumn: MRT_Column<TData>,
|
100
|
+
targetColumn: MRT_Column<TData>,
|
101
|
+
columnOrder: MRT_ColumnOrderState,
|
102
|
+
): MRT_ColumnOrderState => {
|
103
|
+
if (draggedColumn.getCanPin()) {
|
104
|
+
draggedColumn.pin(targetColumn.getIsPinned());
|
105
|
+
}
|
106
|
+
const newColumnOrder = [...columnOrder];
|
107
|
+
newColumnOrder.splice(
|
108
|
+
newColumnOrder.indexOf(targetColumn.id),
|
109
|
+
0,
|
110
|
+
newColumnOrder.splice(newColumnOrder.indexOf(draggedColumn.id), 1)[0],
|
111
|
+
);
|
112
|
+
return newColumnOrder;
|
113
|
+
};
|
114
|
+
|
115
|
+
export const getDefaultColumnFilterFn = <TData extends MRT_RowData>(
|
116
|
+
columnDef: MRT_ColumnDef<TData>,
|
117
|
+
): MRT_FilterOption => {
|
118
|
+
if (columnDef.filterVariant === 'multi-select') return 'arrIncludesSome';
|
119
|
+
if (columnDef.filterVariant?.includes('range')) return 'betweenInclusive';
|
120
|
+
if (
|
121
|
+
columnDef.filterVariant === 'select' ||
|
122
|
+
columnDef.filterVariant === 'checkbox'
|
123
|
+
)
|
124
|
+
return 'equals';
|
125
|
+
return 'fuzzy';
|
126
|
+
};
|
127
|
+
|
128
|
+
export const getIsFirstColumn = <TData extends MRT_RowData>(
|
129
|
+
column: MRT_Column<TData>,
|
130
|
+
table: MRT_TableInstance<TData>,
|
131
|
+
) => {
|
132
|
+
const leftColumns = table.getLeftVisibleLeafColumns();
|
133
|
+
return leftColumns.length
|
134
|
+
? leftColumns[0].id === column.id
|
135
|
+
: table.getVisibleLeafColumns()[0].id === column.id;
|
136
|
+
};
|
137
|
+
|
138
|
+
export const getIsLastColumn = <TData extends MRT_RowData>(
|
139
|
+
column: MRT_Column<TData>,
|
140
|
+
table: MRT_TableInstance<TData>,
|
141
|
+
) => {
|
142
|
+
const rightColumns = table.getRightVisibleLeafColumns();
|
143
|
+
const columns = table.getVisibleLeafColumns();
|
144
|
+
return rightColumns.length
|
145
|
+
? rightColumns[rightColumns.length - 1].id === column.id
|
146
|
+
: columns[columns.length - 1].id === column.id;
|
147
|
+
};
|
148
|
+
|
149
|
+
export const getIsLastLeftPinnedColumn = <TData extends MRT_RowData>(
|
150
|
+
table: MRT_TableInstance<TData>,
|
151
|
+
column: MRT_Column<TData>,
|
152
|
+
) => {
|
153
|
+
return (
|
154
|
+
column.getIsPinned() === 'left' &&
|
155
|
+
table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
|
156
|
+
);
|
157
|
+
};
|
158
|
+
|
159
|
+
export const getIsFirstRightPinnedColumn = <TData extends MRT_RowData>(
|
160
|
+
column: MRT_Column<TData>,
|
161
|
+
) => {
|
162
|
+
return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
|
163
|
+
};
|
164
|
+
|
165
|
+
export const getTotalRight = <TData extends MRT_RowData>(
|
166
|
+
table: MRT_TableInstance<TData>,
|
167
|
+
column: MRT_Column<TData>,
|
168
|
+
) => {
|
169
|
+
return table
|
170
|
+
.getRightLeafHeaders()
|
171
|
+
.slice(column.getPinnedIndex() + 1)
|
172
|
+
.reduce((acc, col) => acc + col.getSize(), 0);
|
173
|
+
};
|