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
@@ -0,0 +1,134 @@
|
|
1
|
+
import {
|
2
|
+
type MRT_DefinedTableOptions,
|
3
|
+
type MRT_DisplayColumnIds,
|
4
|
+
type MRT_Localization,
|
5
|
+
type MRT_RowData,
|
6
|
+
type MRT_StatefulTableOptions,
|
7
|
+
} from '../types';
|
8
|
+
import { getAllLeafColumnDefs, getColumnId } from './column.utils';
|
9
|
+
|
10
|
+
export function defaultDisplayColumnProps<TData extends MRT_RowData>({
|
11
|
+
header,
|
12
|
+
id,
|
13
|
+
size,
|
14
|
+
tableOptions,
|
15
|
+
}: {
|
16
|
+
header?: keyof MRT_Localization;
|
17
|
+
id: MRT_DisplayColumnIds;
|
18
|
+
size: number;
|
19
|
+
tableOptions: MRT_DefinedTableOptions<TData>;
|
20
|
+
}) {
|
21
|
+
const { defaultDisplayColumn, displayColumnDefOptions, localization } =
|
22
|
+
tableOptions;
|
23
|
+
return {
|
24
|
+
...defaultDisplayColumn,
|
25
|
+
header: header ? localization[header]! : '',
|
26
|
+
size,
|
27
|
+
...displayColumnDefOptions?.[id],
|
28
|
+
id,
|
29
|
+
} as const;
|
30
|
+
}
|
31
|
+
|
32
|
+
export const showRowPinningColumn = <TData extends MRT_RowData>(
|
33
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
34
|
+
) => {
|
35
|
+
const { enableRowPinning, rowPinningDisplayMode } = tableOptions;
|
36
|
+
return enableRowPinning && !rowPinningDisplayMode?.startsWith('select');
|
37
|
+
};
|
38
|
+
|
39
|
+
export const showRowDragColumn = <TData extends MRT_RowData>(
|
40
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
41
|
+
) => {
|
42
|
+
const { enableRowDragging, enableRowOrdering } = tableOptions;
|
43
|
+
return enableRowDragging || enableRowOrdering;
|
44
|
+
};
|
45
|
+
|
46
|
+
export const showRowExpandColumn = <TData extends MRT_RowData>(
|
47
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
48
|
+
) => {
|
49
|
+
const {
|
50
|
+
enableExpanding,
|
51
|
+
enableGrouping,
|
52
|
+
renderDetailPanel,
|
53
|
+
state: { grouping },
|
54
|
+
} = tableOptions;
|
55
|
+
return !!(
|
56
|
+
enableExpanding ||
|
57
|
+
(enableGrouping && (grouping === undefined || grouping?.length)) ||
|
58
|
+
renderDetailPanel
|
59
|
+
);
|
60
|
+
};
|
61
|
+
|
62
|
+
export const showRowActionsColumn = <TData extends MRT_RowData>(
|
63
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
64
|
+
) => {
|
65
|
+
const {
|
66
|
+
createDisplayMode,
|
67
|
+
editDisplayMode,
|
68
|
+
enableEditing,
|
69
|
+
enableRowActions,
|
70
|
+
state: { creatingRow },
|
71
|
+
} = tableOptions;
|
72
|
+
return (
|
73
|
+
enableRowActions ||
|
74
|
+
(creatingRow && createDisplayMode === 'row') ||
|
75
|
+
(enableEditing && ['modal', 'row'].includes(editDisplayMode ?? ''))
|
76
|
+
);
|
77
|
+
};
|
78
|
+
|
79
|
+
export const showRowSelectionColumn = <TData extends MRT_RowData>(
|
80
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
81
|
+
) => tableOptions.enableRowSelection;
|
82
|
+
|
83
|
+
export const showRowNumbersColumn = <TData extends MRT_RowData>(
|
84
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
85
|
+
) => tableOptions.enableRowNumbers;
|
86
|
+
|
87
|
+
export const showRowSpacerColumn = <TData extends MRT_RowData>(
|
88
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
89
|
+
) => tableOptions.layoutMode === 'grid-no-grow';
|
90
|
+
|
91
|
+
export const getLeadingDisplayColumnIds = <TData extends MRT_RowData>(
|
92
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
93
|
+
) =>
|
94
|
+
[
|
95
|
+
showRowPinningColumn(tableOptions) && 'mrt-row-pin',
|
96
|
+
showRowDragColumn(tableOptions) && 'mrt-row-drag',
|
97
|
+
tableOptions.positionActionsColumn === 'first' &&
|
98
|
+
showRowActionsColumn(tableOptions) &&
|
99
|
+
'mrt-row-actions',
|
100
|
+
tableOptions.positionExpandColumn === 'first' &&
|
101
|
+
showRowExpandColumn(tableOptions) &&
|
102
|
+
'mrt-row-expand',
|
103
|
+
showRowSelectionColumn(tableOptions) && 'mrt-row-select',
|
104
|
+
showRowNumbersColumn(tableOptions) && 'mrt-row-numbers',
|
105
|
+
].filter(Boolean) as MRT_DisplayColumnIds[];
|
106
|
+
|
107
|
+
export const getTrailingDisplayColumnIds = <TData extends MRT_RowData>(
|
108
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
109
|
+
) =>
|
110
|
+
[
|
111
|
+
tableOptions.positionActionsColumn === 'last' &&
|
112
|
+
showRowActionsColumn(tableOptions) &&
|
113
|
+
'mrt-row-actions',
|
114
|
+
tableOptions.positionExpandColumn === 'last' &&
|
115
|
+
showRowExpandColumn(tableOptions) &&
|
116
|
+
'mrt-row-expand',
|
117
|
+
showRowSpacerColumn(tableOptions) && 'mrt-row-spacer',
|
118
|
+
].filter(Boolean) as MRT_DisplayColumnIds[];
|
119
|
+
|
120
|
+
export const getDefaultColumnOrderIds = <TData extends MRT_RowData>(
|
121
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
122
|
+
) => {
|
123
|
+
const leadingDisplayCols: string[] = getLeadingDisplayColumnIds(tableOptions);
|
124
|
+
const trailingDisplayCols: string[] =
|
125
|
+
getTrailingDisplayColumnIds(tableOptions);
|
126
|
+
const allLeafColumnDefs = getAllLeafColumnDefs(tableOptions.columns)
|
127
|
+
.map((columnDef) => getColumnId(columnDef))
|
128
|
+
.filter(
|
129
|
+
(columnId) =>
|
130
|
+
!leadingDisplayCols.includes(columnId) &&
|
131
|
+
!trailingDisplayCols.includes(columnId),
|
132
|
+
);
|
133
|
+
return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
|
134
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import {
|
2
|
+
type MRT_Row,
|
3
|
+
type MRT_RowData,
|
4
|
+
type MRT_TableInstance,
|
5
|
+
} from '../types';
|
6
|
+
import { parseFromValuesOrFunc } from './utils';
|
7
|
+
|
8
|
+
export const getIsRowSelected = <TData extends MRT_RowData>({
|
9
|
+
row,
|
10
|
+
table,
|
11
|
+
}: {
|
12
|
+
row: MRT_Row<TData>;
|
13
|
+
table: MRT_TableInstance<TData>;
|
14
|
+
}) => {
|
15
|
+
const { options: enableRowSelection } = table;
|
16
|
+
return (
|
17
|
+
row.getIsSelected() ||
|
18
|
+
(parseFromValuesOrFunc(enableRowSelection, row) &&
|
19
|
+
row.getCanSelectSubRows() &&
|
20
|
+
row.getIsAllSubRowsSelected())
|
21
|
+
);
|
22
|
+
};
|
23
|
+
|
24
|
+
export const getCanRankRows = <TData extends MRT_RowData>(
|
25
|
+
table: MRT_TableInstance<TData>,
|
26
|
+
) => {
|
27
|
+
const { getState, options } = table;
|
28
|
+
const {
|
29
|
+
enableGlobalFilterRankedResults,
|
30
|
+
manualExpanding,
|
31
|
+
manualFiltering,
|
32
|
+
manualGrouping,
|
33
|
+
manualSorting,
|
34
|
+
} = options;
|
35
|
+
const { expanded, globalFilterFn } = getState();
|
36
|
+
|
37
|
+
return (
|
38
|
+
!manualExpanding &&
|
39
|
+
!manualFiltering &&
|
40
|
+
!manualGrouping &&
|
41
|
+
!manualSorting &&
|
42
|
+
enableGlobalFilterRankedResults &&
|
43
|
+
globalFilterFn === 'fuzzy' &&
|
44
|
+
expanded !== true &&
|
45
|
+
!Object.values(expanded).some(Boolean)
|
46
|
+
);
|
47
|
+
};
|
@@ -3,18 +3,18 @@ import { type TableCellProps } from '@mui/material/TableCell';
|
|
3
3
|
import { type TooltipProps } from '@mui/material/Tooltip';
|
4
4
|
import { alpha, darken, lighten } from '@mui/material/styles';
|
5
5
|
import { type Theme } from '@mui/material/styles';
|
6
|
-
import {
|
7
|
-
getIsFirstRightPinnedColumn,
|
8
|
-
getIsLastLeftPinnedColumn,
|
9
|
-
getTotalRight,
|
10
|
-
parseFromValuesOrFunc,
|
11
|
-
} from './column.utils';
|
12
6
|
import {
|
13
7
|
type MRT_Column,
|
14
8
|
type MRT_Header,
|
15
9
|
type MRT_RowData,
|
16
10
|
type MRT_TableInstance,
|
17
|
-
} from '
|
11
|
+
} from '../types';
|
12
|
+
import {
|
13
|
+
getIsFirstRightPinnedColumn,
|
14
|
+
getIsLastLeftPinnedColumn,
|
15
|
+
getTotalRight,
|
16
|
+
} from '../utils/column.utils';
|
17
|
+
import { parseFromValuesOrFunc } from './utils';
|
18
18
|
|
19
19
|
export const parseCSSVarId = (id: string) => id.replace(/[^a-zA-Z0-9]/g, '_');
|
20
20
|
|
@@ -42,6 +42,49 @@ export const getMRTTheme = <TData extends MRT_RowData>(
|
|
42
42
|
};
|
43
43
|
};
|
44
44
|
|
45
|
+
export const pinnedBeforeAfterStyles = {
|
46
|
+
content: '""',
|
47
|
+
height: '100%',
|
48
|
+
left: 0,
|
49
|
+
position: 'absolute',
|
50
|
+
top: 0,
|
51
|
+
width: '100%',
|
52
|
+
zIndex: -1,
|
53
|
+
};
|
54
|
+
|
55
|
+
export const getCommonPinnedCellStyles = <TData extends MRT_RowData>({
|
56
|
+
column,
|
57
|
+
table,
|
58
|
+
theme,
|
59
|
+
}: {
|
60
|
+
column?: MRT_Column<TData>;
|
61
|
+
table: MRT_TableInstance<TData>;
|
62
|
+
theme: Theme;
|
63
|
+
}) => {
|
64
|
+
const { baseBackgroundColor } = getMRTTheme(table, theme);
|
65
|
+
return {
|
66
|
+
'&[data-pinned="true"]': {
|
67
|
+
'&:before': {
|
68
|
+
backgroundColor: alpha(
|
69
|
+
darken(
|
70
|
+
baseBackgroundColor,
|
71
|
+
theme.palette.mode === 'dark' ? 0.05 : 0.01,
|
72
|
+
),
|
73
|
+
0.97,
|
74
|
+
),
|
75
|
+
boxShadow: column
|
76
|
+
? getIsLastLeftPinnedColumn(table, column)
|
77
|
+
? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
78
|
+
: getIsFirstRightPinnedColumn(column)
|
79
|
+
? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
80
|
+
: undefined
|
81
|
+
: undefined,
|
82
|
+
...pinnedBeforeAfterStyles,
|
83
|
+
},
|
84
|
+
},
|
85
|
+
};
|
86
|
+
};
|
87
|
+
|
45
88
|
export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
|
46
89
|
column,
|
47
90
|
header,
|
@@ -56,63 +99,66 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
|
|
56
99
|
theme: Theme;
|
57
100
|
}) => {
|
58
101
|
const {
|
59
|
-
options: { layoutMode },
|
102
|
+
options: { enableColumnVirtualization, layoutMode },
|
60
103
|
} = table;
|
104
|
+
const { columnDef } = column;
|
105
|
+
|
106
|
+
const isColumnPinned =
|
107
|
+
columnDef.columnDefType !== 'group' && column.getIsPinned();
|
108
|
+
|
61
109
|
const widthStyles: CSSProperties = {
|
62
110
|
minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
|
63
111
|
header?.id ?? column.id,
|
64
|
-
)}-size) * 1px), ${
|
112
|
+
)}-size) * 1px), ${columnDef.minSize ?? 30}px)`,
|
65
113
|
width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
|
66
114
|
header?.id ?? column.id,
|
67
|
-
)}-size) * 1px
|
115
|
+
)}-size) * 1px)`,
|
68
116
|
};
|
69
117
|
|
70
118
|
if (layoutMode === 'grid') {
|
71
|
-
widthStyles.flex =
|
72
|
-
|
73
|
-
|
119
|
+
widthStyles.flex = `${
|
120
|
+
[0, false].includes(columnDef.grow!)
|
121
|
+
? 0
|
122
|
+
: `var(--${header ? 'header' : 'col'}-${parseCSSVarId(
|
123
|
+
header?.id ?? column.id,
|
124
|
+
)}-size)`
|
125
|
+
} 0 auto`;
|
74
126
|
} else if (layoutMode === 'grid-no-grow') {
|
75
|
-
widthStyles.flex =
|
127
|
+
widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
|
76
128
|
}
|
77
129
|
|
130
|
+
const pinnedStyles = isColumnPinned
|
131
|
+
? {
|
132
|
+
...getCommonPinnedCellStyles({ column, table, theme }),
|
133
|
+
left:
|
134
|
+
isColumnPinned === 'left'
|
135
|
+
? `${column.getStart('left')}px`
|
136
|
+
: undefined,
|
137
|
+
opacity: 0.97,
|
138
|
+
position: 'sticky',
|
139
|
+
right:
|
140
|
+
isColumnPinned === 'right'
|
141
|
+
? `${getTotalRight(table, column)}px`
|
142
|
+
: undefined,
|
143
|
+
zIndex: 1,
|
144
|
+
}
|
145
|
+
: {};
|
146
|
+
|
78
147
|
return {
|
79
|
-
backgroundColor:
|
80
|
-
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
81
|
-
? alpha(
|
82
|
-
darken(
|
83
|
-
getMRTTheme(table, theme).baseBackgroundColor,
|
84
|
-
theme.palette.mode === 'dark' ? 0.05 : 0.01,
|
85
|
-
),
|
86
|
-
0.97,
|
87
|
-
)
|
88
|
-
: 'inherit',
|
148
|
+
backgroundColor: 'inherit',
|
89
149
|
backgroundImage: 'inherit',
|
90
|
-
boxShadow: getIsLastLeftPinnedColumn(table, column)
|
91
|
-
? `-4px 0 8px -6px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
92
|
-
: getIsFirstRightPinnedColumn(column)
|
93
|
-
? `4px 0 8px -6px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
94
|
-
: undefined,
|
95
150
|
display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
|
96
|
-
left:
|
97
|
-
column.getIsPinned() === 'left'
|
98
|
-
? `${column.getStart('left')}px`
|
99
|
-
: undefined,
|
100
151
|
opacity:
|
101
152
|
table.getState().draggingColumn?.id === column.id ||
|
102
153
|
table.getState().hoveredColumn?.id === column.id
|
103
154
|
? 0.5
|
104
155
|
: 1,
|
105
|
-
position:
|
106
|
-
|
107
|
-
? 'sticky'
|
108
|
-
: undefined,
|
109
|
-
right:
|
110
|
-
column.getIsPinned() === 'right'
|
111
|
-
? `${getTotalRight(table, column)}px`
|
112
|
-
: undefined,
|
113
|
-
transition: table.options.enableColumnVirtualization
|
156
|
+
position: 'relative',
|
157
|
+
transition: enableColumnVirtualization
|
114
158
|
? 'none'
|
115
159
|
: `padding 150ms ease-in-out`,
|
160
|
+
zIndex: 0,
|
161
|
+
...pinnedStyles,
|
116
162
|
...widthStyles,
|
117
163
|
...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
|
118
164
|
};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { type ReactNode } from 'react';
|
2
|
+
import {
|
3
|
+
createRow as _createRow,
|
4
|
+
flexRender as _flexRender,
|
5
|
+
type Renderable,
|
6
|
+
} from '@tanstack/react-table';
|
7
|
+
import {
|
8
|
+
type MRT_ColumnHelper,
|
9
|
+
type MRT_DisplayColumnDef,
|
10
|
+
type MRT_GroupColumnDef,
|
11
|
+
type MRT_Row,
|
12
|
+
type MRT_RowData,
|
13
|
+
type MRT_TableInstance,
|
14
|
+
} from '../types';
|
15
|
+
import { getAllLeafColumnDefs, getColumnId } from './column.utils';
|
16
|
+
|
17
|
+
export const flexRender = _flexRender as (
|
18
|
+
Comp: Renderable<any>,
|
19
|
+
props: any,
|
20
|
+
) => JSX.Element | ReactNode;
|
21
|
+
|
22
|
+
export function createMRTColumnHelper<
|
23
|
+
TData extends MRT_RowData,
|
24
|
+
>(): MRT_ColumnHelper<TData> {
|
25
|
+
return {
|
26
|
+
accessor: (accessor, column) => {
|
27
|
+
return typeof accessor === 'function'
|
28
|
+
? ({
|
29
|
+
...column,
|
30
|
+
accessorFn: accessor,
|
31
|
+
} as any)
|
32
|
+
: {
|
33
|
+
...column,
|
34
|
+
accessorKey: accessor,
|
35
|
+
};
|
36
|
+
},
|
37
|
+
display: (column) => column as MRT_DisplayColumnDef<TData>,
|
38
|
+
group: (column) => column as MRT_GroupColumnDef<TData>,
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
export const createRow = <TData extends MRT_RowData>(
|
43
|
+
table: MRT_TableInstance<TData>,
|
44
|
+
originalRow?: TData,
|
45
|
+
rowIndex = -1,
|
46
|
+
depth = 0,
|
47
|
+
subRows?: MRT_Row<TData>[],
|
48
|
+
parentId?: string,
|
49
|
+
): MRT_Row<TData> =>
|
50
|
+
_createRow(
|
51
|
+
table as any,
|
52
|
+
'mrt-row-create',
|
53
|
+
originalRow ??
|
54
|
+
Object.assign(
|
55
|
+
{},
|
56
|
+
...getAllLeafColumnDefs(table.options.columns).map((col) => ({
|
57
|
+
[getColumnId(col)]: '',
|
58
|
+
})),
|
59
|
+
),
|
60
|
+
rowIndex,
|
61
|
+
depth,
|
62
|
+
subRows as any,
|
63
|
+
parentId,
|
64
|
+
) as MRT_Row<TData>;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { type DropdownOption } from '../types';
|
2
|
+
|
3
|
+
export const parseFromValuesOrFunc = <T, U>(
|
4
|
+
fn: ((arg: U) => T) | T | undefined,
|
5
|
+
arg: U,
|
6
|
+
): T | undefined => (fn instanceof Function ? fn(arg) : fn);
|
7
|
+
|
8
|
+
export const getValueAndLabel = (
|
9
|
+
option: DropdownOption,
|
10
|
+
): { label: string; value: string } => {
|
11
|
+
let label: string = '';
|
12
|
+
let value: string = '';
|
13
|
+
if (option) {
|
14
|
+
if (typeof option !== 'object') {
|
15
|
+
label = option;
|
16
|
+
value = option;
|
17
|
+
} else {
|
18
|
+
label = option.label ?? option.text ?? option.value;
|
19
|
+
value = option.value ?? label;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
return { label, value };
|
23
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { type Range, defaultRangeExtractor } from '@tanstack/react-virtual';
|
2
|
+
|
3
|
+
export const extraIndexRangeExtractor = (
|
4
|
+
range: Range,
|
5
|
+
draggingIndex?: number,
|
6
|
+
) => {
|
7
|
+
const newIndexes = defaultRangeExtractor(range);
|
8
|
+
if (draggingIndex === undefined) return newIndexes;
|
9
|
+
if (
|
10
|
+
draggingIndex >= 0 &&
|
11
|
+
draggingIndex < Math.max(range.startIndex - range.overscan, 0)
|
12
|
+
) {
|
13
|
+
newIndexes.unshift(draggingIndex);
|
14
|
+
}
|
15
|
+
if (draggingIndex >= 0 && draggingIndex > range.endIndex + range.overscan) {
|
16
|
+
newIndexes.push(draggingIndex);
|
17
|
+
}
|
18
|
+
return newIndexes;
|
19
|
+
};
|
package/src/utils.ts
ADDED
File without changes
|