@cutting/material-react-table 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/dist/index.d.ts +186 -524
- package/dist/index.js +323 -342
- package/dist/index.js.map +1 -1
- package/locales/ar/index.mjs +1 -2
- package/locales/az/index.mjs +1 -2
- package/locales/bg/index.mjs +1 -2
- package/locales/cs/index.mjs +1 -2
- package/locales/da/index.mjs +1 -2
- package/locales/de/index.mjs +1 -2
- package/locales/el/index.mjs +1 -2
- package/locales/en/index.mjs +1 -2
- package/locales/es/index.mjs +1 -2
- package/locales/et/index.mjs +1 -2
- package/locales/fa/index.mjs +1 -2
- package/locales/fi/index.mjs +1 -2
- package/locales/fr/index.mjs +1 -2
- package/locales/he/index.mjs +1 -2
- package/locales/hr/index.mjs +1 -2
- package/locales/hu/index.mjs +1 -2
- package/locales/hy/index.mjs +1 -2
- package/locales/id/index.mjs +1 -2
- package/locales/it/index.mjs +1 -2
- package/locales/ja/index.mjs +1 -2
- package/locales/ko/index.mjs +1 -2
- package/locales/nl/index.mjs +1 -2
- package/locales/no/index.mjs +1 -2
- package/locales/np/index.mjs +1 -2
- package/locales/pl/index.mjs +1 -2
- package/locales/pt/index.mjs +1 -2
- package/locales/pt-BR/index.mjs +1 -2
- package/locales/ro/index.mjs +1 -2
- package/locales/ru/index.mjs +1 -2
- package/locales/sk/index.mjs +1 -2
- package/locales/sr-Cyrl-RS/index.mjs +1 -2
- package/locales/sr-Latn-RS/index.mjs +1 -2
- package/locales/sv/index.mjs +1 -2
- package/locales/tr/index.mjs +1 -2
- package/locales/uk/index.mjs +1 -2
- package/locales/vi/index.mjs +1 -2
- package/locales/zh-Hans/index.mjs +1 -2
- package/locales/zh-Hant/index.mjs +1 -2
- package/package.json +19 -27
- package/src/MaterialReactTable.smoke.test.tsx +3 -9
- package/src/components/MaterialReactTable.tsx +13 -21
- package/src/components/body/MRT_TableBody.tsx +67 -82
- package/src/components/body/MRT_TableBodyCell.tsx +38 -80
- package/src/components/body/MRT_TableBodyCellValue.tsx +5 -14
- package/src/components/body/MRT_TableBodyRow.tsx +55 -102
- package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +2 -6
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -9
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +8 -14
- package/src/components/body/MRT_TableDetailPanel.test.tsx +3 -9
- package/src/components/body/MRT_TableDetailPanel.tsx +8 -14
- package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +6 -16
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +6 -12
- package/src/components/buttons/MRT_CopyButton.tsx +7 -15
- package/src/components/buttons/MRT_EditActionButtons.test.tsx +2 -6
- package/src/components/buttons/MRT_EditActionButtons.tsx +15 -37
- package/src/components/buttons/MRT_ExpandAllButton.tsx +8 -16
- package/src/components/buttons/MRT_ExpandButton.tsx +9 -21
- package/src/components/buttons/MRT_GrabHandleButton.tsx +6 -10
- package/src/components/buttons/MRT_RowPinButton.tsx +8 -23
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +5 -18
- package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +4 -12
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +4 -11
- package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +4 -13
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +3 -11
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +4 -9
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -15
- package/src/components/footer/MRT_TableFooter.tsx +9 -16
- package/src/components/footer/MRT_TableFooterCell.tsx +9 -32
- package/src/components/footer/MRT_TableFooterRow.tsx +18 -32
- package/src/components/head/MRT_TableHead.tsx +8 -18
- package/src/components/head/MRT_TableHeadCell.tsx +46 -100
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -30
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -15
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +20 -54
- package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +5 -19
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +9 -38
- package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +3 -13
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +10 -24
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +10 -26
- package/src/components/head/MRT_TableHeadRow.tsx +24 -36
- package/src/components/inputs/MRT_EditCellTextField.test.tsx +2 -9
- package/src/components/inputs/MRT_EditCellTextField.tsx +9 -28
- package/src/components/inputs/MRT_FilterCheckbox.tsx +9 -23
- package/src/components/inputs/MRT_FilterRangeFields.tsx +6 -15
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +24 -32
- package/src/components/inputs/MRT_FilterTextField.test.tsx +72 -14
- package/src/components/inputs/MRT_FilterTextField.tsx +77 -138
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +10 -32
- package/src/components/inputs/MRT_SelectCheckbox.test.tsx +4 -11
- package/src/components/inputs/MRT_SelectCheckbox.tsx +17 -36
- package/src/components/menus/MRT_ActionMenuItem.tsx +6 -15
- package/src/components/menus/MRT_CellActionMenu.tsx +6 -9
- package/src/components/menus/MRT_ColumnActionMenu.tsx +22 -57
- package/src/components/menus/MRT_FilterOptionMenu.tsx +38 -65
- package/src/components/menus/MRT_RowActionMenu.tsx +33 -22
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +29 -65
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.test.tsx +43 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +14 -50
- package/src/components/modals/MRT_EditRowModal.test.tsx +5 -21
- package/src/components/modals/MRT_EditRowModal.tsx +8 -26
- package/src/components/table/MRT_Table.tsx +12 -20
- package/src/components/table/MRT_TableContainer.test.tsx +147 -0
- package/src/components/table/MRT_TableContainer.tsx +33 -37
- package/src/components/table/MRT_TableLoadingOverlay.tsx +3 -5
- package/src/components/table/MRT_TablePaper.tsx +7 -14
- package/src/components/toolbar/MRT_BottomToolbar.tsx +11 -23
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +4 -11
- package/src/components/toolbar/MRT_TablePagination.tsx +33 -40
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +21 -50
- package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +26 -10
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +23 -21
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +11 -21
- package/src/components/toolbar/MRT_TopToolbar.tsx +12 -28
- package/src/fns/aggregationFns.test.tsx +1 -3
- package/src/fns/filterFns.test.tsx +8 -37
- package/src/fns/filterFns.ts +71 -96
- package/src/fns/sortingFns.test.tsx +5 -21
- package/src/fns/sortingFns.ts +10 -14
- package/src/fns/tableFeatures.test.tsx +6 -29
- package/src/fns/tableFeatures.ts +5 -4
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +2 -11
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +2 -10
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +8 -17
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +3 -8
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +2 -8
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +3 -13
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -5
- package/src/hooks/useMRT_ColumnVirtualizer.ts +28 -49
- package/src/hooks/useMRT_Effects.test.tsx +114 -0
- package/src/hooks/useMRT_Effects.ts +26 -27
- package/src/hooks/useMRT_RowVirtualizer.ts +18 -33
- package/src/hooks/useMRT_Rows.ts +3 -42
- package/src/hooks/useMRT_TableInstance.ts +63 -129
- package/src/hooks/useMRT_TableOptions.ts +15 -29
- package/src/hooks/useMaterialReactTable.ts +2 -7
- package/src/icons.ts +38 -1
- package/src/index.ts +0 -4
- package/src/locales/ar.ts +1 -2
- package/src/locales/az.ts +1 -2
- package/src/locales/bg.ts +1 -2
- package/src/locales/cs.ts +2 -4
- package/src/locales/da.ts +1 -2
- package/src/locales/de.ts +1 -2
- package/src/locales/el.ts +1 -2
- package/src/locales/en.ts +1 -2
- package/src/locales/es.ts +1 -2
- package/src/locales/et.ts +2 -4
- package/src/locales/fa.ts +1 -2
- package/src/locales/fi.ts +2 -4
- package/src/locales/fr.ts +1 -2
- package/src/locales/he.ts +1 -2
- package/src/locales/hr.ts +1 -2
- package/src/locales/hu.ts +1 -2
- package/src/locales/hy.ts +1 -2
- package/src/locales/id.ts +2 -4
- package/src/locales/it.ts +1 -2
- package/src/locales/ja.ts +1 -2
- package/src/locales/ko.ts +1 -2
- package/src/locales/nl.ts +1 -2
- package/src/locales/no.ts +2 -4
- package/src/locales/np.ts +2 -4
- package/src/locales/pl.ts +1 -2
- package/src/locales/pt-BR.ts +1 -2
- package/src/locales/pt.ts +1 -2
- package/src/locales/ro.ts +1 -2
- package/src/locales/ru.ts +1 -2
- package/src/locales/sk.ts +2 -4
- package/src/locales/sr-Cyrl-RS.ts +1 -2
- package/src/locales/sr-Latn-RS.ts +1 -2
- package/src/locales/sv.ts +1 -2
- package/src/locales/tr.ts +1 -2
- package/src/locales/uk.ts +1 -2
- package/src/locales/vi.ts +1 -2
- package/src/types.ts +156 -349
- package/src/utils/cell.utils.ts +30 -68
- package/src/utils/column.utils.ts +61 -49
- package/src/utils/displayColumn.utils.ts +16 -38
- package/src/utils/highlight.utils.ts +7 -11
- package/src/utils/row.utils.ts +40 -65
- package/src/utils/slotProps.utils.ts +1 -4
- package/src/utils/style.utils.ts +18 -46
- package/src/utils/tanstack.helpers.ts +10 -17
- package/src/utils/utils.ts +6 -10
- package/src/utils/virtualization.utils.ts +5 -9
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import { TableBody, type TableBodyProps } from '@mui/material';
|
|
2
|
-
import {
|
|
1
|
+
import { TableBody, type TableBodyProps, Typography } from '@mui/material';
|
|
2
|
+
import { type CSSObject } from '@mui/material/styles';
|
|
3
3
|
import { type VirtualItem } from '@tanstack/react-virtual';
|
|
4
4
|
import { memo, useMemo } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useMRT_Rows } from '../../hooks/useMRT_Rows';
|
|
7
7
|
import { useMRT_RowVirtualizer } from '../../hooks/useMRT_RowVirtualizer';
|
|
8
|
-
import {
|
|
9
|
-
type MRT_ColumnVirtualizer,
|
|
10
|
-
type MRT_Row,
|
|
11
|
-
type MRT_RowData,
|
|
12
|
-
type MRT_TableInstance,
|
|
13
|
-
} from '../../types';
|
|
8
|
+
import { type MRT_ColumnVirtualizer, type MRT_Row, type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
14
9
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
15
10
|
import { Memo_MRT_TableBodyRow, MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
16
11
|
|
|
17
|
-
export interface MRT_TableBodyProps<TData extends MRT_RowData>
|
|
18
|
-
extends TableBodyProps {
|
|
12
|
+
export interface MRT_TableBodyProps<TData extends MRT_RowData> extends TableBodyProps {
|
|
19
13
|
columnVirtualizer?: MRT_ColumnVirtualizer;
|
|
20
14
|
table: MRT_TableInstance<TData>;
|
|
21
15
|
}
|
|
@@ -24,7 +18,7 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
|
|
|
24
18
|
columnVirtualizer,
|
|
25
19
|
table,
|
|
26
20
|
...rest
|
|
27
|
-
}: MRT_TableBodyProps<TData>) => {
|
|
21
|
+
}: MRT_TableBodyProps<TData>): JSX.Element => {
|
|
28
22
|
const {
|
|
29
23
|
getBottomRows,
|
|
30
24
|
getIsSomeRowsPinned,
|
|
@@ -50,19 +44,16 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
|
|
|
50
44
|
...rest,
|
|
51
45
|
};
|
|
52
46
|
|
|
53
|
-
const tableHeadHeight =
|
|
54
|
-
|
|
55
|
-
tableHeadRef.current?.clientHeight) ||
|
|
56
|
-
0;
|
|
57
|
-
const tableFooterHeight =
|
|
58
|
-
(enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
|
|
47
|
+
const tableHeadHeight = ((enableStickyHeader || isFullScreen) && tableHeadRef.current?.clientHeight) || 0;
|
|
48
|
+
const tableFooterHeight = (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
|
|
59
49
|
|
|
50
|
+
const rowModelRows = getRowModel().rows;
|
|
60
51
|
const pinnedRowIds = useMemo(() => {
|
|
61
|
-
if (!rowPinning.bottom?.length && !rowPinning.top?.length)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}, [rowPinning,
|
|
52
|
+
if (!rowPinning.bottom?.length && !rowPinning.top?.length) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
return rowModelRows.filter((row) => row.getIsPinned()).map((r) => r.id);
|
|
56
|
+
}, [rowPinning, rowModelRows]);
|
|
66
57
|
|
|
67
58
|
const rows = useMRT_Rows(table);
|
|
68
59
|
|
|
@@ -78,42 +69,39 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
|
|
|
78
69
|
|
|
79
70
|
return (
|
|
80
71
|
<>
|
|
81
|
-
{!rowPinningDisplayMode?.includes('sticky') &&
|
|
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
|
-
)}
|
|
72
|
+
{!rowPinningDisplayMode?.includes('sticky') && getIsSomeRowsPinned('top') && (
|
|
73
|
+
<TableBody
|
|
74
|
+
{...tableBodyProps}
|
|
75
|
+
sx={(theme) => ({
|
|
76
|
+
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
|
|
77
|
+
position: 'sticky',
|
|
78
|
+
top: tableHeadHeight - 1,
|
|
79
|
+
zIndex: 1,
|
|
80
|
+
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as CSSObject),
|
|
81
|
+
})}
|
|
82
|
+
>
|
|
83
|
+
{getTopRows().map((row, staticRowIndex) => {
|
|
84
|
+
const props = {
|
|
85
|
+
...commonRowProps,
|
|
86
|
+
row,
|
|
87
|
+
staticRowIndex,
|
|
88
|
+
};
|
|
89
|
+
return memoMode === 'rows' ? (
|
|
90
|
+
<Memo_MRT_TableBodyRow key={row.id} {...props} />
|
|
91
|
+
) : (
|
|
92
|
+
<MRT_TableBodyRow key={row.id} {...props} />
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
</TableBody>
|
|
96
|
+
)}
|
|
107
97
|
<TableBody
|
|
108
98
|
{...tableBodyProps}
|
|
109
99
|
sx={(theme) => ({
|
|
110
100
|
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
|
|
111
|
-
height: rowVirtualizer
|
|
112
|
-
? `${rowVirtualizer.getTotalSize()}px`
|
|
113
|
-
: undefined,
|
|
101
|
+
height: rowVirtualizer ? `${rowVirtualizer.getTotalSize()}px` : undefined,
|
|
114
102
|
minHeight: !rows.length ? '100px' : undefined,
|
|
115
103
|
position: 'relative',
|
|
116
|
-
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as
|
|
104
|
+
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as CSSObject),
|
|
117
105
|
})}
|
|
118
106
|
>
|
|
119
107
|
{tableBodyProps?.children ??
|
|
@@ -135,7 +123,7 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
|
|
|
135
123
|
color: 'text.secondary',
|
|
136
124
|
fontStyle: 'italic',
|
|
137
125
|
maxWidth: `min(100vw, ${
|
|
138
|
-
tablePaperRef.current?.clientWidth ? tablePaperRef.current?.clientWidth +
|
|
126
|
+
tablePaperRef.current?.clientWidth ? tablePaperRef.current?.clientWidth + 'px' : '100%'
|
|
139
127
|
})`,
|
|
140
128
|
py: '2rem',
|
|
141
129
|
textAlign: 'center',
|
|
@@ -171,9 +159,7 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
|
|
|
171
159
|
row,
|
|
172
160
|
rowVirtualizer,
|
|
173
161
|
staticRowIndex,
|
|
174
|
-
virtualRow: rowVirtualizer
|
|
175
|
-
? (rowOrVirtualRow as VirtualItem)
|
|
176
|
-
: undefined,
|
|
162
|
+
virtualRow: rowVirtualizer ? (rowOrVirtualRow as VirtualItem) : undefined,
|
|
177
163
|
};
|
|
178
164
|
const key = `${row.id}-${row.index}`;
|
|
179
165
|
return memoMode === 'rows' ? (
|
|
@@ -185,32 +171,31 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
|
|
|
185
171
|
</>
|
|
186
172
|
))}
|
|
187
173
|
</TableBody>
|
|
188
|
-
{!rowPinningDisplayMode?.includes('sticky') &&
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
)}
|
|
174
|
+
{!rowPinningDisplayMode?.includes('sticky') && getIsSomeRowsPinned('bottom') && (
|
|
175
|
+
<TableBody
|
|
176
|
+
{...tableBodyProps}
|
|
177
|
+
sx={(theme) => ({
|
|
178
|
+
bottom: tableFooterHeight - 1,
|
|
179
|
+
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
|
|
180
|
+
position: 'sticky',
|
|
181
|
+
zIndex: 1,
|
|
182
|
+
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as CSSObject),
|
|
183
|
+
})}
|
|
184
|
+
>
|
|
185
|
+
{getBottomRows().map((row, staticRowIndex) => {
|
|
186
|
+
const props = {
|
|
187
|
+
...commonRowProps,
|
|
188
|
+
row,
|
|
189
|
+
staticRowIndex,
|
|
190
|
+
};
|
|
191
|
+
return memoMode === 'rows' ? (
|
|
192
|
+
<Memo_MRT_TableBodyRow key={row.id} {...props} />
|
|
193
|
+
) : (
|
|
194
|
+
<MRT_TableBodyRow key={row.id} {...props} />
|
|
195
|
+
);
|
|
196
|
+
})}
|
|
197
|
+
</TableBody>
|
|
198
|
+
)}
|
|
214
199
|
</>
|
|
215
200
|
);
|
|
216
201
|
};
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
-
import { Skeleton } from '@mui/material';
|
|
2
|
-
import { TableCell, type TableCellProps } from '@mui/material';
|
|
1
|
+
import { Skeleton, TableCell, type TableCellProps } from '@mui/material';
|
|
3
2
|
import { useTheme } from '@mui/material/styles';
|
|
4
3
|
import {
|
|
5
4
|
type DragEvent,
|
|
6
5
|
memo,
|
|
7
6
|
type MouseEvent,
|
|
7
|
+
type ReactNode,
|
|
8
8
|
type RefObject,
|
|
9
9
|
useEffect,
|
|
10
10
|
useMemo,
|
|
11
11
|
useState,
|
|
12
12
|
} from 'react';
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
type MRT_RowData,
|
|
17
|
-
type MRT_TableInstance,
|
|
18
|
-
} from '../../types';
|
|
19
|
-
import {
|
|
20
|
-
cellKeyboardShortcuts,
|
|
21
|
-
isCellEditable,
|
|
22
|
-
openEditingCell,
|
|
23
|
-
} from '../../utils/cell.utils';
|
|
14
|
+
import { type MRT_Cell, type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
15
|
+
import { cellKeyboardShortcuts, isCellEditable, openEditingCell } from '../../utils/cell.utils';
|
|
24
16
|
import { getCommonMRTCellStyles } from '../../utils/style.utils';
|
|
25
17
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
26
18
|
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
|
27
19
|
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
28
20
|
import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
|
|
29
21
|
|
|
30
|
-
export interface MRT_TableBodyCellProps<TData extends MRT_RowData>
|
|
31
|
-
extends TableCellProps {
|
|
22
|
+
export interface MRT_TableBodyCellProps<TData extends MRT_RowData> extends TableCellProps {
|
|
32
23
|
cell: MRT_Cell<TData>;
|
|
33
24
|
numRows?: number;
|
|
34
25
|
rowRef: RefObject<HTMLTableRowElement | null>;
|
|
@@ -45,7 +36,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
45
36
|
staticRowIndex,
|
|
46
37
|
table,
|
|
47
38
|
...rest
|
|
48
|
-
}: MRT_TableBodyCellProps<TData>) => {
|
|
39
|
+
}: MRT_TableBodyCellProps<TData>): JSX.Element => {
|
|
49
40
|
const theme = useTheme();
|
|
50
41
|
const {
|
|
51
42
|
options: {
|
|
@@ -100,14 +91,12 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
100
91
|
|
|
101
92
|
const [skeletonWidth, setSkeletonWidth] = useState(100);
|
|
102
93
|
useEffect(() => {
|
|
103
|
-
if ((!isLoading && !showSkeletons) || skeletonWidth !== 100)
|
|
94
|
+
if ((!isLoading && !showSkeletons) || skeletonWidth !== 100) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
104
97
|
const size = column.getSize();
|
|
105
|
-
setSkeletonWidth(
|
|
106
|
-
|
|
107
|
-
? size / 2
|
|
108
|
-
: Math.round(Math.random() * (size - size / 3) + size / 3),
|
|
109
|
-
);
|
|
110
|
-
}, [isLoading, showSkeletons]);
|
|
98
|
+
setSkeletonWidth(columnDefType === 'display' ? size / 2 : Math.round(Math.random() * (size - size / 3) + size / 3));
|
|
99
|
+
}, [column, columnDefType, isLoading, showSkeletons, skeletonWidth]);
|
|
111
100
|
|
|
112
101
|
const draggingBorders = useMemo(() => {
|
|
113
102
|
const isDraggingColumn = draggingColumn?.id === column.id;
|
|
@@ -118,8 +107,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
118
107
|
const isLastColumn = column.getIsLastColumn();
|
|
119
108
|
const isLastRow = numRows && staticRowIndex === numRows - 1;
|
|
120
109
|
const isResizingColumn = columnResizing.isResizingColumn === column.id;
|
|
121
|
-
const showResizeBorder =
|
|
122
|
-
isResizingColumn && columnResizeMode === 'onChange';
|
|
110
|
+
const showResizeBorder = isResizingColumn && columnResizeMode === 'onChange';
|
|
123
111
|
|
|
124
112
|
const borderStyle = showResizeBorder
|
|
125
113
|
? `2px solid ${draggingBorderColor} !important`
|
|
@@ -130,66 +118,56 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
130
118
|
: undefined;
|
|
131
119
|
|
|
132
120
|
if (showResizeBorder) {
|
|
133
|
-
return columnResizeDirection === 'ltr'
|
|
134
|
-
? { borderRight: borderStyle }
|
|
135
|
-
: { borderLeft: borderStyle };
|
|
121
|
+
return columnResizeDirection === 'ltr' ? { borderRight: borderStyle } : { borderLeft: borderStyle };
|
|
136
122
|
}
|
|
137
123
|
|
|
138
124
|
return borderStyle
|
|
139
125
|
? {
|
|
140
|
-
borderBottom:
|
|
141
|
-
isDraggingRow || isHoveredRow || (isLastRow && !isResizingColumn)
|
|
142
|
-
? borderStyle
|
|
143
|
-
: undefined,
|
|
126
|
+
borderBottom: isDraggingRow || isHoveredRow || (isLastRow && !isResizingColumn) ? borderStyle : undefined,
|
|
144
127
|
borderLeft:
|
|
145
|
-
isDraggingColumn ||
|
|
146
|
-
isHoveredColumn ||
|
|
147
|
-
((isDraggingRow || isHoveredRow) && isFirstColumn)
|
|
128
|
+
isDraggingColumn || isHoveredColumn || ((isDraggingRow || isHoveredRow) && isFirstColumn)
|
|
148
129
|
? borderStyle
|
|
149
130
|
: undefined,
|
|
150
131
|
borderRight:
|
|
151
|
-
isDraggingColumn ||
|
|
152
|
-
isHoveredColumn ||
|
|
153
|
-
((isDraggingRow || isHoveredRow) && isLastColumn)
|
|
132
|
+
isDraggingColumn || isHoveredColumn || ((isDraggingRow || isHoveredRow) && isLastColumn)
|
|
154
133
|
? borderStyle
|
|
155
134
|
: undefined,
|
|
156
135
|
borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
|
|
157
136
|
}
|
|
158
137
|
: undefined;
|
|
159
138
|
}, [
|
|
139
|
+
column,
|
|
140
|
+
columnResizeDirection,
|
|
141
|
+
columnResizeMode,
|
|
160
142
|
columnResizing.isResizingColumn,
|
|
143
|
+
draggingBorderColor,
|
|
161
144
|
draggingColumn,
|
|
162
145
|
draggingRow,
|
|
163
146
|
hoveredColumn,
|
|
164
147
|
hoveredRow,
|
|
148
|
+
numRows,
|
|
149
|
+
row.id,
|
|
165
150
|
staticRowIndex,
|
|
151
|
+
theme.palette.grey,
|
|
166
152
|
]);
|
|
167
153
|
|
|
168
|
-
const isColumnPinned =
|
|
169
|
-
enableColumnPinning &&
|
|
170
|
-
columnDef.columnDefType !== 'group' &&
|
|
171
|
-
column.getIsPinned();
|
|
154
|
+
const isColumnPinned = enableColumnPinning && columnDef.columnDefType !== 'group' && column.getIsPinned();
|
|
172
155
|
|
|
173
156
|
const isEditable = isCellEditable({ cell, table });
|
|
174
157
|
|
|
175
158
|
const isEditing =
|
|
176
159
|
isEditable &&
|
|
177
160
|
!['custom', 'modal'].includes(editDisplayMode as string) &&
|
|
178
|
-
(editDisplayMode === 'table' ||
|
|
179
|
-
editingRow?.id === row.id ||
|
|
180
|
-
editingCell?.id === cell.id) &&
|
|
161
|
+
(editDisplayMode === 'table' || editingRow?.id === row.id || editingCell?.id === cell.id) &&
|
|
181
162
|
!row.getIsGrouped();
|
|
182
163
|
|
|
183
|
-
const isCreating =
|
|
184
|
-
isEditable && createDisplayMode === 'row' && creatingRow?.id === row.id;
|
|
164
|
+
const isCreating = isEditable && createDisplayMode === 'row' && creatingRow?.id === row.id;
|
|
185
165
|
|
|
166
|
+
const columnClickToCopy = parseFromValuesOrFunc(columnDef.enableClickToCopy, cell);
|
|
186
167
|
const showClickToCopyButton =
|
|
187
|
-
(parseFromValuesOrFunc(enableClickToCopy, cell) === true ||
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// @ts-expect-error
|
|
191
|
-
parseFromValuesOrFunc(columnDef.enableClickToCopy, cell),
|
|
192
|
-
);
|
|
168
|
+
(parseFromValuesOrFunc(enableClickToCopy, cell) === true || columnClickToCopy === true) &&
|
|
169
|
+
columnClickToCopy !== 'context-menu' &&
|
|
170
|
+
columnClickToCopy !== false;
|
|
193
171
|
|
|
194
172
|
const isRightClickable = parseFromValuesOrFunc(enableCellActions, cell);
|
|
195
173
|
|
|
@@ -211,9 +189,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
211
189
|
setHoveredColumn(null);
|
|
212
190
|
}
|
|
213
191
|
if (enableColumnOrdering && draggingColumn) {
|
|
214
|
-
setHoveredColumn(
|
|
215
|
-
columnDef.enableColumnOrdering !== false ? column : null,
|
|
216
|
-
);
|
|
192
|
+
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
217
193
|
}
|
|
218
194
|
};
|
|
219
195
|
|
|
@@ -265,15 +241,8 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
265
241
|
textOverflow: 'clip',
|
|
266
242
|
},
|
|
267
243
|
alignItems: layoutMode?.startsWith('grid') ? 'center' : undefined,
|
|
268
|
-
cursor: isRightClickable
|
|
269
|
-
|
|
270
|
-
: isEditable && editDisplayMode === 'cell'
|
|
271
|
-
? 'pointer'
|
|
272
|
-
: 'inherit',
|
|
273
|
-
outline:
|
|
274
|
-
actionCell?.id === cell.id
|
|
275
|
-
? `1px solid ${theme.palette.grey[500]}`
|
|
276
|
-
: undefined,
|
|
244
|
+
cursor: isRightClickable ? 'context-menu' : isEditable && editDisplayMode === 'cell' ? 'pointer' : 'inherit',
|
|
245
|
+
outline: actionCell?.id === cell.id ? `1px solid ${theme.palette.grey[500]}` : undefined,
|
|
277
246
|
outlineOffset: '-1px',
|
|
278
247
|
overflow: 'hidden',
|
|
279
248
|
p:
|
|
@@ -290,8 +259,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
290
259
|
: '1.5rem',
|
|
291
260
|
|
|
292
261
|
textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
|
|
293
|
-
whiteSpace:
|
|
294
|
-
row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal',
|
|
262
|
+
whiteSpace: row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal',
|
|
295
263
|
...getCommonMRTCellStyles({
|
|
296
264
|
column,
|
|
297
265
|
table,
|
|
@@ -306,21 +274,13 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
306
274
|
{cell.getIsPlaceholder() ? (
|
|
307
275
|
(columnDef.PlaceholderCell?.({ cell, column, row, table }) ?? null)
|
|
308
276
|
) : showSkeletons !== false && (isLoading || showSkeletons) ? (
|
|
309
|
-
<Skeleton
|
|
310
|
-
animation="wave"
|
|
311
|
-
height={20}
|
|
312
|
-
width={skeletonWidth}
|
|
313
|
-
{...skeletonProps}
|
|
314
|
-
/>
|
|
277
|
+
<Skeleton animation="wave" height={20} width={skeletonWidth} {...skeletonProps} />
|
|
315
278
|
) : columnDefType === 'display' &&
|
|
316
|
-
(['mrt-row-expand', 'mrt-row-numbers', 'mrt-row-select'].includes(
|
|
317
|
-
column.id,
|
|
318
|
-
) ||
|
|
319
|
-
!row.getIsGrouped()) ? (
|
|
279
|
+
(['mrt-row-expand', 'mrt-row-numbers', 'mrt-row-select'].includes(column.id) || !row.getIsGrouped()) ? (
|
|
320
280
|
columnDef.Cell?.({
|
|
321
281
|
cell,
|
|
322
282
|
column,
|
|
323
|
-
renderedCellValue: cell.renderValue() as
|
|
283
|
+
renderedCellValue: cell.renderValue() as ReactNode,
|
|
324
284
|
row,
|
|
325
285
|
rowRef,
|
|
326
286
|
staticColumnIndex,
|
|
@@ -336,9 +296,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
|
336
296
|
) : (
|
|
337
297
|
<MRT_TableBodyCellValue {...cellValueProps} />
|
|
338
298
|
)}
|
|
339
|
-
{cell.getIsGrouped() && !columnDef.GroupedCell && (
|
|
340
|
-
<> ({row.subRows?.length})</>
|
|
341
|
-
)}
|
|
299
|
+
{cell.getIsGrouped() && !columnDef.GroupedCell && <> ({row.subRows?.length})</>}
|
|
342
300
|
</>
|
|
343
301
|
)}
|
|
344
302
|
</TableCell>
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { Box } from '@mui/material';
|
|
2
2
|
import { type ReactNode, type RefObject } from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
type MRT_Cell,
|
|
6
|
-
type MRT_RowData,
|
|
7
|
-
type MRT_TableInstance,
|
|
8
|
-
} from '../../types';
|
|
4
|
+
import { type MRT_Cell, type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
9
5
|
import { highlightWords } from '../../utils/highlight.utils';
|
|
10
6
|
|
|
11
7
|
const allowedTypes = ['string', 'number'];
|
|
@@ -24,7 +20,7 @@ export const MRT_TableBodyCellValue = <TData extends MRT_RowData>({
|
|
|
24
20
|
staticColumnIndex,
|
|
25
21
|
staticRowIndex,
|
|
26
22
|
table,
|
|
27
|
-
}: MRT_TableBodyCellValueProps<TData>) => {
|
|
23
|
+
}: MRT_TableBodyCellValueProps<TData>): ReactNode => {
|
|
28
24
|
const {
|
|
29
25
|
options: {
|
|
30
26
|
enableFilterMatchHighlighting,
|
|
@@ -73,13 +69,10 @@ export const MRT_TableBodyCellValue = <TData extends MRT_RowData>({
|
|
|
73
69
|
((filterValue &&
|
|
74
70
|
allowedTypes.includes(typeof filterValue) &&
|
|
75
71
|
['autocomplete', 'text'].includes(columnDef.filterVariant!)) ||
|
|
76
|
-
(globalFilter &&
|
|
77
|
-
allowedTypes.includes(typeof globalFilter) &&
|
|
78
|
-
column.getCanGlobalFilter()))
|
|
72
|
+
(globalFilter && allowedTypes.includes(typeof globalFilter) && column.getCanGlobalFilter()))
|
|
79
73
|
) {
|
|
80
74
|
const chunks = highlightWords({
|
|
81
|
-
matchExactly:
|
|
82
|
-
(filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
|
75
|
+
matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
|
83
76
|
query: (filterValue ?? globalFilter ?? '').toString(),
|
|
84
77
|
text: renderedCellValue?.toString() as string,
|
|
85
78
|
});
|
|
@@ -97,9 +90,7 @@ export const MRT_TableBodyCellValue = <TData extends MRT_RowData>({
|
|
|
97
90
|
backgroundColor: matchHighlightColor,
|
|
98
91
|
borderRadius: '2px',
|
|
99
92
|
color: (theme) =>
|
|
100
|
-
theme.palette.mode === 'dark'
|
|
101
|
-
? theme.palette.common.white
|
|
102
|
-
: theme.palette.common.black,
|
|
93
|
+
theme.palette.mode === 'dark' ? theme.palette.common.white : theme.palette.common.black,
|
|
103
94
|
padding: '2px 1px',
|
|
104
95
|
}
|
|
105
96
|
: undefined
|