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.
Files changed (96) hide show
  1. package/dist/index.d.ts +253 -99
  2. package/dist/index.esm.js +3546 -3475
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +3567 -3498
  5. package/dist/index.js.map +1 -1
  6. package/locales/ja/index.esm.js +4 -4
  7. package/locales/ja/index.js +4 -4
  8. package/package.json +25 -23
  9. package/src/{MaterialReactTable.tsx → components/MaterialReactTable.tsx} +3 -3
  10. package/src/{body → components/body}/MRT_TableBody.tsx +6 -7
  11. package/src/{body → components/body}/MRT_TableBodyCell.tsx +16 -26
  12. package/src/{body → components/body}/MRT_TableBodyCellValue.tsx +2 -2
  13. package/src/{body → components/body}/MRT_TableBodyRow.tsx +79 -59
  14. package/src/{body → components/body}/MRT_TableBodyRowGrabHandle.tsx +3 -3
  15. package/src/{body → components/body}/MRT_TableBodyRowPinButton.tsx +3 -3
  16. package/src/{body → components/body}/MRT_TableDetailPanel.tsx +3 -3
  17. package/src/{buttons → components/buttons}/MRT_ColumnPinningButtons.tsx +2 -2
  18. package/src/{buttons → components/buttons}/MRT_CopyButton.tsx +3 -3
  19. package/src/{buttons → components/buttons}/MRT_EditActionButtons.tsx +2 -2
  20. package/src/{buttons → components/buttons}/MRT_ExpandAllButton.tsx +3 -3
  21. package/src/{buttons → components/buttons}/MRT_ExpandButton.tsx +6 -3
  22. package/src/{buttons → components/buttons}/MRT_GrabHandleButton.tsx +3 -3
  23. package/src/{buttons → components/buttons}/MRT_RowPinButton.tsx +3 -3
  24. package/src/{buttons → components/buttons}/MRT_ShowHideColumnsButton.tsx +1 -1
  25. package/src/{buttons → components/buttons}/MRT_ToggleDensePaddingButton.tsx +1 -1
  26. package/src/{buttons → components/buttons}/MRT_ToggleFiltersButton.tsx +1 -1
  27. package/src/{buttons → components/buttons}/MRT_ToggleFullScreenButton.tsx +1 -1
  28. package/src/{buttons → components/buttons}/MRT_ToggleGlobalFilterButton.tsx +1 -1
  29. package/src/{buttons → components/buttons}/MRT_ToggleRowActionMenuButton.tsx +4 -4
  30. package/src/{footer → components/footer}/MRT_TableFooter.tsx +2 -2
  31. package/src/{footer → components/footer}/MRT_TableFooterCell.tsx +13 -4
  32. package/src/{footer → components/footer}/MRT_TableFooterRow.tsx +22 -11
  33. package/src/{head → components/head}/MRT_TableHead.tsx +3 -3
  34. package/src/{head → components/head}/MRT_TableHeadCell.tsx +13 -3
  35. package/src/{head → components/head}/MRT_TableHeadCellColumnActionsButton.tsx +4 -4
  36. package/src/{head → components/head}/MRT_TableHeadCellFilterContainer.tsx +5 -5
  37. package/src/{head → components/head}/MRT_TableHeadCellFilterLabel.tsx +2 -2
  38. package/src/{head → components/head}/MRT_TableHeadCellGrabHandle.tsx +4 -3
  39. package/src/{head → components/head}/MRT_TableHeadCellResizeHandle.tsx +6 -4
  40. package/src/{head → components/head}/MRT_TableHeadCellSortLabel.tsx +2 -2
  41. package/src/{head → components/head}/MRT_TableHeadRow.tsx +22 -11
  42. package/src/{inputs → components/inputs}/MRT_EditCellTextField.tsx +15 -6
  43. package/src/{inputs → components/inputs}/MRT_FilterCheckbox.tsx +3 -3
  44. package/src/{inputs → components/inputs}/MRT_FilterRangeFields.tsx +2 -2
  45. package/src/{inputs → components/inputs}/MRT_FilterRangeSlider.tsx +2 -2
  46. package/src/{inputs → components/inputs}/MRT_FilterTextField.tsx +3 -3
  47. package/src/{inputs → components/inputs}/MRT_GlobalFilterTextField.tsx +2 -2
  48. package/src/{inputs → components/inputs}/MRT_SelectCheckbox.tsx +7 -9
  49. package/src/{menus → components/menus}/MRT_ColumnActionMenu.tsx +8 -8
  50. package/src/{menus → components/menus}/MRT_FilterOptionMenu.tsx +2 -2
  51. package/src/{menus → components/menus}/MRT_RowActionMenu.tsx +9 -9
  52. package/src/{menus → components/menus}/MRT_ShowHideColumnsMenu.tsx +5 -7
  53. package/src/{menus → components/menus}/MRT_ShowHideColumnsMenuItems.tsx +6 -5
  54. package/src/{modals → components/modals}/MRT_EditRowModal.tsx +4 -4
  55. package/src/{table → components/table}/MRT_Table.tsx +8 -4
  56. package/src/{table → components/table}/MRT_TableContainer.tsx +2 -2
  57. package/src/{table → components/table}/MRT_TableLoadingOverlay.tsx +3 -3
  58. package/src/{table → components/table}/MRT_TablePaper.tsx +3 -3
  59. package/src/{toolbar → components/toolbar}/MRT_BottomToolbar.tsx +3 -3
  60. package/src/{toolbar → components/toolbar}/MRT_LinearProgressBar.tsx +2 -2
  61. package/src/{toolbar → components/toolbar}/MRT_TablePagination.tsx +3 -3
  62. package/src/{toolbar → components/toolbar}/MRT_ToolbarAlertBanner.tsx +3 -3
  63. package/src/{toolbar → components/toolbar}/MRT_ToolbarDropZone.tsx +2 -2
  64. package/src/{toolbar → components/toolbar}/MRT_ToolbarInternalButtons.tsx +2 -2
  65. package/src/{toolbar → components/toolbar}/MRT_TopToolbar.tsx +3 -3
  66. package/src/{filterFns.ts → fns/filterFns.ts} +1 -1
  67. package/src/{sortingFns.ts → fns/sortingFns.ts} +1 -1
  68. package/src/hooks/display-columns/getMRT_DisplayColumns.tsx +26 -0
  69. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +35 -0
  70. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +36 -0
  71. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +98 -0
  72. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +37 -0
  73. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +31 -0
  74. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +41 -0
  75. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +40 -0
  76. package/src/hooks/useMRT_ColumnVirtualizer.ts +79 -80
  77. package/src/hooks/useMRT_Effects.ts +1 -1
  78. package/src/hooks/useMRT_RowVirtualizer.ts +32 -36
  79. package/src/hooks/useMRT_Rows.ts +2 -2
  80. package/src/hooks/useMRT_TableInstance.ts +54 -39
  81. package/src/hooks/useMRT_TableOptions.ts +30 -20
  82. package/src/{useMaterialReactTable.ts → hooks/useMaterialReactTable.ts} +3 -3
  83. package/src/index.ts +79 -82
  84. package/src/locales/ja.ts +4 -4
  85. package/src/types.ts +57 -26
  86. package/src/utils/column.utils.ts +173 -0
  87. package/src/utils/displayColumn.utils.ts +134 -0
  88. package/src/utils/row.utils.ts +47 -0
  89. package/src/{style.utils.ts → utils/style.utils.ts} +88 -42
  90. package/src/utils/tanstack.helpers.ts +64 -0
  91. package/src/utils/utils.ts +23 -0
  92. package/src/utils/virtualization.utils.ts +19 -0
  93. package/src/utils.ts +0 -0
  94. package/src/column.utils.ts +0 -361
  95. package/src/hooks/useMRT_DisplayColumns.tsx +0 -290
  96. /package/src/{aggregationFns.ts → fns/aggregationFns.ts} +0 -0
@@ -3,24 +3,23 @@ import Checkbox, { type CheckboxProps } from '@mui/material/Checkbox';
3
3
  import Radio, { type RadioProps } from '@mui/material/Radio';
4
4
  import Tooltip from '@mui/material/Tooltip';
5
5
  import { type Theme } from '@mui/material/styles';
6
- import { parseFromValuesOrFunc } from '../column.utils';
7
- import { getCommonTooltipProps } from '../style.utils';
8
6
  import {
9
7
  type MRT_Row,
10
8
  type MRT_RowData,
11
9
  type MRT_TableInstance,
12
- } from '../types';
10
+ } from '../../types';
11
+ import { getIsRowSelected } from '../../utils/row.utils';
12
+ import { getCommonTooltipProps } from '../../utils/style.utils';
13
+ import { parseFromValuesOrFunc } from '../../utils/utils';
13
14
 
14
15
  interface Props<TData extends MRT_RowData> extends CheckboxProps {
15
16
  row?: MRT_Row<TData>;
16
- selectAll?: boolean;
17
17
  staticRowIndex?: number;
18
18
  table: MRT_TableInstance<TData>;
19
19
  }
20
20
 
21
21
  export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
22
22
  row,
23
- selectAll,
24
23
  staticRowIndex,
25
24
  table,
26
25
  ...rest
@@ -39,6 +38,8 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
39
38
  } = table;
40
39
  const { density, isLoading } = getState();
41
40
 
41
+ const selectAll = !row;
42
+
42
43
  const checkboxProps = {
43
44
  ...(!row
44
45
  ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
@@ -92,10 +93,7 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
92
93
  'aria-label': selectAll
93
94
  ? localization.toggleSelectAll
94
95
  : localization.toggleSelectRow,
95
- checked: selectAll
96
- ? allRowsSelected
97
- : row?.getIsSelected() ||
98
- (row?.getIsAllSubRowsSelected() && row.getCanSelectSubRows()),
96
+ checked: selectAll ? allRowsSelected : getIsRowSelected({ row, table }),
99
97
  disabled:
100
98
  isLoading || (row && !row.getCanSelect()) || row?.id === 'mrt-row-create',
101
99
  inputProps: {
@@ -7,12 +7,12 @@ import Menu, { type MenuProps } from '@mui/material/Menu';
7
7
  import MenuItem from '@mui/material/MenuItem';
8
8
  import { useTheme } from '@mui/material/styles';
9
9
  import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
10
- import { getMRTTheme } from '../style.utils';
11
10
  import {
12
11
  type MRT_Header,
13
12
  type MRT_RowData,
14
13
  type MRT_TableInstance,
15
- } from '../types';
14
+ } from '../../types';
15
+ import { getMRTTheme } from '../../utils/style.utils';
16
16
 
17
17
  export const commonMenuItemStyles = {
18
18
  alignItems: 'center',
@@ -403,12 +403,12 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
403
403
 
404
404
  return (
405
405
  <Menu
406
- MenuListProps={{
407
- dense: density === 'compact',
408
- sx: {
409
- backgroundColor: menuBackgroundColor,
410
- },
411
- }}
406
+ MenuListProps={{
407
+ dense: density === 'compact',
408
+ sx: {
409
+ backgroundColor: menuBackgroundColor,
410
+ },
411
+ }}
412
412
  anchorEl={anchorEl}
413
413
  onClose={() => setAnchorEl(null)}
414
414
  open={!!anchorEl}
@@ -3,7 +3,6 @@ import Box from '@mui/material/Box';
3
3
  import Menu, { type MenuProps } from '@mui/material/Menu';
4
4
  import MenuItem from '@mui/material/MenuItem';
5
5
  import { useTheme } from '@mui/material/styles';
6
- import { getMRTTheme } from '../style.utils';
7
6
  import {
8
7
  type MRT_FilterOption,
9
8
  type MRT_Header,
@@ -11,7 +10,8 @@ import {
11
10
  type MRT_Localization,
12
11
  type MRT_RowData,
13
12
  type MRT_TableInstance,
14
- } from '../types';
13
+ } from '../../types';
14
+ import { getMRTTheme } from '../../utils/style.utils';
15
15
 
16
16
  export const mrtFilterOptions = (
17
17
  localization: MRT_Localization,
@@ -8,13 +8,13 @@ import {
8
8
  commonListItemStyles,
9
9
  commonMenuItemStyles,
10
10
  } from './MRT_ColumnActionMenu';
11
- import { parseFromValuesOrFunc } from '../column.utils';
12
- import { getMRTTheme } from '../style.utils';
13
11
  import {
14
12
  type MRT_Row,
15
13
  type MRT_RowData,
16
14
  type MRT_TableInstance,
17
- } from '../types';
15
+ } from '../../types';
16
+ import { getMRTTheme } from '../../utils/style.utils';
17
+ import { parseFromValuesOrFunc } from '../../utils/utils';
18
18
 
19
19
  interface Props<TData extends MRT_RowData> extends Partial<MenuProps> {
20
20
  anchorEl: HTMLElement | null;
@@ -51,12 +51,12 @@ export const MRT_RowActionMenu = <TData extends MRT_RowData>({
51
51
 
52
52
  return (
53
53
  <Menu
54
- MenuListProps={{
55
- dense: density === 'compact',
56
- sx: {
57
- backgroundColor: menuBackgroundColor,
58
- },
59
- }}
54
+ MenuListProps={{
55
+ dense: density === 'compact',
56
+ sx: {
57
+ backgroundColor: menuBackgroundColor,
58
+ },
59
+ }}
60
60
  anchorEl={anchorEl}
61
61
  onClick={(event) => event.stopPropagation()}
62
62
  onClose={() => setAnchorEl(null)}
@@ -1,17 +1,17 @@
1
1
  import { useMemo, useState } from 'react';
2
- import { useTheme } from '@mui/material';
3
2
  import Box from '@mui/material/Box';
4
3
  import Button from '@mui/material/Button';
5
4
  import Divider from '@mui/material/Divider';
6
5
  import Menu, { type MenuProps } from '@mui/material/Menu';
6
+ import { useTheme } from '@mui/material/styles';
7
7
  import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
8
- import { getDefaultColumnOrderIds } from '../column.utils';
9
- import { getMRTTheme } from '../style.utils';
10
8
  import {
11
9
  type MRT_Column,
12
10
  type MRT_RowData,
13
11
  type MRT_TableInstance,
14
- } from '../types';
12
+ } from '../../types';
13
+ import { getDefaultColumnOrderIds } from '../../utils/displayColumn.utils';
14
+ import { getMRTTheme } from '../../utils/style.utils';
15
15
 
16
16
  interface Props<TData extends MRT_RowData> extends Partial<MenuProps> {
17
17
  anchorEl: HTMLElement | null;
@@ -114,9 +114,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
114
114
  {enableColumnOrdering && (
115
115
  <Button
116
116
  onClick={() =>
117
- table.setColumnOrder(
118
- getDefaultColumnOrderIds(table.options as any),
119
- )
117
+ table.setColumnOrder(getDefaultColumnOrderIds(table.options))
120
118
  }
121
119
  >
122
120
  {localization.resetOrder}
@@ -11,15 +11,16 @@ import MenuItem, { type MenuItemProps } from '@mui/material/MenuItem';
11
11
  import Switch from '@mui/material/Switch';
12
12
  import Tooltip from '@mui/material/Tooltip';
13
13
  import Typography from '@mui/material/Typography';
14
- import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
15
- import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
16
- import { parseFromValuesOrFunc, reorderColumn } from '../column.utils';
17
- import { getCommonTooltipProps, getMRTTheme } from '../style.utils';
18
14
  import {
19
15
  type MRT_Column,
20
16
  type MRT_RowData,
21
17
  type MRT_TableInstance,
22
- } from '../types';
18
+ } from '../../types';
19
+ import { reorderColumn } from '../../utils/column.utils';
20
+ import { getCommonTooltipProps, getMRTTheme } from '../../utils/style.utils';
21
+ import { parseFromValuesOrFunc } from '../../utils/utils';
22
+ import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
23
+ import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
23
24
 
24
25
  interface Props<TData extends MRT_RowData> extends MenuItemProps {
25
26
  allColumns: MRT_Column<TData>[];
@@ -3,14 +3,14 @@ import DialogActions from '@mui/material/DialogActions';
3
3
  import DialogContent from '@mui/material/DialogContent';
4
4
  import DialogTitle from '@mui/material/DialogTitle';
5
5
  import Stack from '@mui/material/Stack';
6
- import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
7
- import { parseFromValuesOrFunc } from '../column.utils';
8
- import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
9
6
  import {
10
7
  type MRT_Row,
11
8
  type MRT_RowData,
12
9
  type MRT_TableInstance,
13
- } from '../types';
10
+ } from '../../types';
11
+ import { parseFromValuesOrFunc } from '../../utils/utils';
12
+ import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
13
+ import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
14
14
 
15
15
  interface Props<TData extends MRT_RowData> extends Partial<DialogProps> {
16
16
  open: boolean;
@@ -1,12 +1,12 @@
1
1
  import { useMemo } from 'react';
2
2
  import Table, { type TableProps } from '@mui/material/Table';
3
+ import { useMRT_ColumnVirtualizer } from '../../hooks/useMRT_ColumnVirtualizer';
4
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
5
+ import { parseCSSVarId } from '../../utils/style.utils';
6
+ import { parseFromValuesOrFunc } from '../../utils/utils';
3
7
  import { MRT_TableBody, Memo_MRT_TableBody } from '../body/MRT_TableBody';
4
- import { parseFromValuesOrFunc } from '../column.utils';
5
8
  import { MRT_TableFooter } from '../footer/MRT_TableFooter';
6
9
  import { MRT_TableHead } from '../head/MRT_TableHead';
7
- import { useMRT_ColumnVirtualizer } from '../hooks/useMRT_ColumnVirtualizer';
8
- import { parseCSSVarId } from '../style.utils';
9
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
10
10
 
11
11
  interface Props<TData extends MRT_RowData> extends TableProps {
12
12
  table: MRT_TableInstance<TData>;
@@ -27,6 +27,7 @@ export const MRT_Table = <TData extends MRT_RowData>({
27
27
  layoutMode,
28
28
  memoMode,
29
29
  muiTableProps,
30
+ renderCaption,
30
31
  },
31
32
  } = table;
32
33
  const { columnSizing, columnSizingInfo, columnVisibility, isFullScreen } =
@@ -37,6 +38,8 @@ export const MRT_Table = <TData extends MRT_RowData>({
37
38
  ...rest,
38
39
  };
39
40
 
41
+ const Caption = parseFromValuesOrFunc(renderCaption, { table });
42
+
40
43
  const columnSizeVars = useMemo(() => {
41
44
  const headers = getFlatHeaders();
42
45
  const colSizes: { [key: string]: number } = {};
@@ -67,6 +70,7 @@ export const MRT_Table = <TData extends MRT_RowData>({
67
70
  ...(parseFromValuesOrFunc(tableProps?.sx, theme) as any),
68
71
  })}
69
72
  >
73
+ {!!Caption && <caption>{Caption}</caption>}
70
74
  {enableTableHead && <MRT_TableHead {...commonTableGroupProps} />}
71
75
  {memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? (
72
76
  <Memo_MRT_TableBody {...commonTableGroupProps} />
@@ -4,9 +4,9 @@ import TableContainer, {
4
4
  } from '@mui/material/TableContainer';
5
5
  import { MRT_Table } from './MRT_Table';
6
6
  import { MRT_TableLoadingOverlay } from './MRT_TableLoadingOverlay';
7
- import { parseFromValuesOrFunc } from '../column.utils';
7
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
8
+ import { parseFromValuesOrFunc } from '../../utils/utils';
8
9
  import { MRT_EditRowModal } from '../modals/MRT_EditRowModal';
9
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
10
10
 
11
11
  const useIsomorphicLayoutEffect =
12
12
  typeof window !== 'undefined' ? useLayoutEffect : useEffect;
@@ -3,9 +3,9 @@ import CircularProgress, {
3
3
  type CircularProgressProps,
4
4
  } from '@mui/material/CircularProgress';
5
5
  import { alpha } from '@mui/material/styles';
6
- import { parseFromValuesOrFunc } from '../column.utils';
7
- import { getMRTTheme } from '../style.utils';
8
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
6
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
+ import { getMRTTheme } from '../../utils/style.utils';
8
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
9
 
10
10
  interface Props<TData extends MRT_RowData> extends CircularProgressProps {
11
11
  table: MRT_TableInstance<TData>;
@@ -1,10 +1,10 @@
1
1
  import Paper, { type PaperProps } from '@mui/material/Paper';
2
2
  import { MRT_TableContainer } from './MRT_TableContainer';
3
- import { parseFromValuesOrFunc } from '../column.utils';
4
- import { getMRTTheme } from '../style.utils';
3
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
4
+ import { getMRTTheme } from '../../utils/style.utils';
5
+ import { parseFromValuesOrFunc } from '../../utils/utils';
5
6
  import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
6
7
  import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
7
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
8
8
 
9
9
  interface Props<TData extends MRT_RowData> extends PaperProps {
10
10
  table: MRT_TableInstance<TData>;
@@ -5,9 +5,9 @@ import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
5
5
  import { MRT_TablePagination } from './MRT_TablePagination';
6
6
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
7
7
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
8
- import { parseFromValuesOrFunc } from '../column.utils';
9
- import { getCommonToolbarStyles } from '../style.utils';
10
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
8
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
9
+ import { getCommonToolbarStyles } from '../../utils/style.utils';
10
+ import { parseFromValuesOrFunc } from '../../utils/utils';
11
11
 
12
12
  interface Props<TData extends MRT_RowData> extends BoxProps {
13
13
  table: MRT_TableInstance<TData>;
@@ -2,8 +2,8 @@ import Collapse from '@mui/material/Collapse';
2
2
  import LinearProgress, {
3
3
  type LinearProgressProps,
4
4
  } from '@mui/material/LinearProgress';
5
- import { parseFromValuesOrFunc } from '../column.utils';
6
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
5
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
6
+ import { parseFromValuesOrFunc } from '../../utils/utils';
7
7
 
8
8
  interface Props<TData extends MRT_RowData> extends LinearProgressProps {
9
9
  isTopToolbar: boolean;
@@ -8,9 +8,9 @@ import Select, { type SelectProps } from '@mui/material/Select';
8
8
  import Tooltip from '@mui/material/Tooltip';
9
9
  import Typography from '@mui/material/Typography';
10
10
  import { useTheme } from '@mui/material/styles';
11
- import { parseFromValuesOrFunc } from '../column.utils';
12
- import { flipIconStyles, getCommonTooltipProps } from '../style.utils';
13
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
11
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
12
+ import { flipIconStyles, getCommonTooltipProps } from '../../utils/style.utils';
13
+ import { parseFromValuesOrFunc } from '../../utils/utils';
14
14
 
15
15
  const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
16
16
 
@@ -5,9 +5,9 @@ import Box from '@mui/material/Box';
5
5
  import Chip from '@mui/material/Chip';
6
6
  import Collapse from '@mui/material/Collapse';
7
7
  import Stack from '@mui/material/Stack';
8
- import { parseFromValuesOrFunc } from '../column.utils';
8
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
9
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
10
  import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
10
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
11
11
 
12
12
  interface Props<TData extends MRT_RowData> extends AlertProps {
13
13
  stackAlertBanner?: boolean;
@@ -139,7 +139,7 @@ export const MRT_ToolbarAlertBanner = <TData extends MRT_RowData>({
139
139
  {enableRowSelection &&
140
140
  enableSelectAll &&
141
141
  positionToolbarAlertBanner === 'head-overlay' && (
142
- <MRT_SelectCheckbox selectAll table={table} />
142
+ <MRT_SelectCheckbox table={table} />
143
143
  )}{' '}
144
144
  {selectedAlert}
145
145
  </Box>
@@ -3,8 +3,8 @@ import Box, { type BoxProps } from '@mui/material/Box';
3
3
  import Fade from '@mui/material/Fade';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { alpha } from '@mui/material/styles';
6
- import { parseFromValuesOrFunc } from '../column.utils';
7
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
6
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
+ import { parseFromValuesOrFunc } from '../../utils/utils';
8
8
 
9
9
  interface Props<TData extends MRT_RowData> extends BoxProps {
10
10
  table: MRT_TableInstance<TData>;
@@ -1,11 +1,11 @@
1
1
  import Box, { type BoxProps } from '@mui/material/Box';
2
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
3
+ import { parseFromValuesOrFunc } from '../../utils/utils';
2
4
  import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
3
5
  import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingButton';
4
6
  import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
5
7
  import { MRT_ToggleFullScreenButton } from '../buttons/MRT_ToggleFullScreenButton';
6
8
  import { MRT_ToggleGlobalFilterButton } from '../buttons/MRT_ToggleGlobalFilterButton';
7
- import { parseFromValuesOrFunc } from '../column.utils';
8
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
9
9
 
10
10
  interface Props<TData extends MRT_RowData> extends BoxProps {
11
11
  table: MRT_TableInstance<TData>;
@@ -5,10 +5,10 @@ import { MRT_TablePagination } from './MRT_TablePagination';
5
5
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
6
6
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
7
7
  import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
8
- import { parseFromValuesOrFunc } from '../column.utils';
8
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
9
+ import { getCommonToolbarStyles } from '../../utils/style.utils';
10
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
11
  import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
10
- import { getCommonToolbarStyles } from '../style.utils';
11
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
12
12
 
13
13
  interface Props<TData extends MRT_RowData> {
14
14
  table: MRT_TableInstance<TData>;
@@ -4,7 +4,7 @@ import {
4
4
  rankings,
5
5
  } from '@tanstack/match-sorter-utils';
6
6
  import { type Row, filterFns } from '@tanstack/react-table';
7
- import { type MRT_RowData } from './types';
7
+ import { type MRT_RowData } from '../types';
8
8
 
9
9
  const fuzzy = <TData extends MRT_RowData>(
10
10
  row: Row<TData>,
@@ -1,6 +1,6 @@
1
1
  import { type RankingInfo, compareItems } from '@tanstack/match-sorter-utils';
2
2
  import { type Row, sortingFns } from '@tanstack/react-table';
3
- import { type MRT_Row, type MRT_RowData } from './types';
3
+ import { type MRT_Row, type MRT_RowData } from '../types';
4
4
 
5
5
  const fuzzy = <TData extends MRT_RowData>(
6
6
  rowA: Row<TData>,
@@ -0,0 +1,26 @@
1
+ import {
2
+ type MRT_ColumnDef,
3
+ type MRT_RowData,
4
+ type MRT_StatefulTableOptions,
5
+ } from '../../types';
6
+ import { getMRT_RowActionsColumnDef } from './getMRT_RowActionsColumnDef';
7
+ import { getMRT_RowDragColumnDef } from './getMRT_RowDragColumnDef';
8
+ import { getMRT_RowExpandColumnDef } from './getMRT_RowExpandColumnDef';
9
+ import { getMRT_RowNumbersColumnDef } from './getMRT_RowNumbersColumnDef';
10
+ import { getMRT_RowPinningColumnDef } from './getMRT_RowPinningColumnDef';
11
+ import { getMRT_RowSelectColumnDef } from './getMRT_RowSelectColumnDef';
12
+ import { getMRT_RowSpacerColumnDef } from './getMRT_RowSpacerColumnDef';
13
+
14
+ export const getMRT_DisplayColumns = <TData extends MRT_RowData>(
15
+ tableOptions: MRT_StatefulTableOptions<TData>,
16
+ ): MRT_ColumnDef<TData>[] => {
17
+ return [
18
+ getMRT_RowNumbersColumnDef(tableOptions),
19
+ getMRT_RowSelectColumnDef(tableOptions),
20
+ getMRT_RowExpandColumnDef(tableOptions),
21
+ getMRT_RowActionsColumnDef(tableOptions),
22
+ getMRT_RowDragColumnDef(tableOptions),
23
+ getMRT_RowPinningColumnDef(tableOptions),
24
+ getMRT_RowSpacerColumnDef(tableOptions),
25
+ ].filter(Boolean) as MRT_ColumnDef<TData>[];
26
+ };
@@ -0,0 +1,35 @@
1
+ import { MRT_ToggleRowActionMenuButton } from '../../components/buttons/MRT_ToggleRowActionMenuButton';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import {
8
+ defaultDisplayColumnProps,
9
+ showRowActionsColumn,
10
+ } from '../../utils/displayColumn.utils';
11
+
12
+ export const getMRT_RowActionsColumnDef = <TData extends MRT_RowData>(
13
+ tableOptions: MRT_StatefulTableOptions<TData>,
14
+ ): MRT_ColumnDef<TData> | null => {
15
+ if (!showRowActionsColumn(tableOptions)) {
16
+ return null;
17
+ }
18
+
19
+ return {
20
+ Cell: ({ cell, row, staticRowIndex, table }) => (
21
+ <MRT_ToggleRowActionMenuButton
22
+ cell={cell}
23
+ row={row}
24
+ staticRowIndex={staticRowIndex}
25
+ table={table}
26
+ />
27
+ ),
28
+ ...defaultDisplayColumnProps({
29
+ header: 'actions',
30
+ id: 'mrt-row-actions',
31
+ size: 70,
32
+ tableOptions,
33
+ }),
34
+ };
35
+ };
@@ -0,0 +1,36 @@
1
+ import { type RefObject } from 'react';
2
+ import { MRT_TableBodyRowGrabHandle } from '../../components/body/MRT_TableBodyRowGrabHandle';
3
+ import {
4
+ type MRT_ColumnDef,
5
+ type MRT_RowData,
6
+ type MRT_StatefulTableOptions,
7
+ } from '../../types';
8
+ import {
9
+ defaultDisplayColumnProps,
10
+ showRowDragColumn,
11
+ } from '../../utils/displayColumn.utils';
12
+
13
+ export const getMRT_RowDragColumnDef = <TData extends MRT_RowData>(
14
+ tableOptions: MRT_StatefulTableOptions<TData>,
15
+ ): MRT_ColumnDef<TData> | null => {
16
+ if (!showRowDragColumn(tableOptions)) {
17
+ return null;
18
+ }
19
+
20
+ return {
21
+ Cell: ({ row, rowRef, table }) => (
22
+ <MRT_TableBodyRowGrabHandle
23
+ row={row}
24
+ rowRef={rowRef as RefObject<HTMLTableRowElement>}
25
+ table={table}
26
+ />
27
+ ),
28
+ grow: false,
29
+ ...defaultDisplayColumnProps({
30
+ header: 'move',
31
+ id: 'mrt-row-drag',
32
+ size: 60,
33
+ tableOptions,
34
+ }),
35
+ };
36
+ };
@@ -0,0 +1,98 @@
1
+ import { type ReactNode } from 'react';
2
+ import Stack from '@mui/material/Stack';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import { MRT_ExpandAllButton } from '../../components/buttons/MRT_ExpandAllButton';
5
+ import { MRT_ExpandButton } from '../../components/buttons/MRT_ExpandButton';
6
+ import {
7
+ type MRT_ColumnDef,
8
+ type MRT_RowData,
9
+ type MRT_StatefulTableOptions,
10
+ } from '../../types';
11
+ import {
12
+ defaultDisplayColumnProps,
13
+ showRowExpandColumn,
14
+ } from '../../utils/displayColumn.utils';
15
+ import { getCommonTooltipProps } from '../../utils/style.utils';
16
+
17
+ export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
18
+ tableOptions: MRT_StatefulTableOptions<TData>,
19
+ ): MRT_ColumnDef<TData> | null => {
20
+ if (!showRowExpandColumn(tableOptions)) {
21
+ return null;
22
+ }
23
+
24
+ const {
25
+ defaultColumn,
26
+ enableExpandAll,
27
+ groupedColumnMode,
28
+ positionExpandColumn,
29
+ renderDetailPanel,
30
+ state: { grouping },
31
+ } = tableOptions;
32
+
33
+ const alignProps =
34
+ positionExpandColumn === 'last'
35
+ ? ({
36
+ align: 'right',
37
+ } as const)
38
+ : undefined;
39
+
40
+ return {
41
+ Cell: ({ cell, column, row, staticRowIndex, table }) => {
42
+ const expandButtonProps = { row, staticRowIndex, table };
43
+ const subRowsLength = row.subRows?.length;
44
+ if (groupedColumnMode === 'remove' && row.groupingColumnId) {
45
+ return (
46
+ <Stack alignItems="center" flexDirection="row" gap="0.25rem">
47
+ <MRT_ExpandButton {...expandButtonProps} />
48
+ <Tooltip
49
+ {...getCommonTooltipProps('right')}
50
+ title={table.getColumn(row.groupingColumnId).columnDef.header}
51
+ >
52
+ <span>{row.groupingValue as ReactNode}</span>
53
+ </Tooltip>
54
+ {!!subRowsLength && <span>({subRowsLength})</span>}
55
+ </Stack>
56
+ );
57
+ } else {
58
+ return (
59
+ <>
60
+ <MRT_ExpandButton {...expandButtonProps} />
61
+ {column.columnDef.GroupedCell?.({ cell, column, row, table })}
62
+ </>
63
+ );
64
+ }
65
+ },
66
+ Header: enableExpandAll
67
+ ? ({ table }) => {
68
+ return (
69
+ <>
70
+ <MRT_ExpandAllButton table={table} />
71
+ {groupedColumnMode === 'remove' &&
72
+ grouping
73
+ ?.map(
74
+ (groupedColumnId) =>
75
+ table.getColumn(groupedColumnId).columnDef.header,
76
+ )
77
+ ?.join(', ')}
78
+ </>
79
+ );
80
+ }
81
+ : undefined,
82
+ muiTableBodyCellProps: alignProps,
83
+ muiTableHeadCellProps: alignProps,
84
+ ...defaultDisplayColumnProps({
85
+ header: 'expand',
86
+ id: 'mrt-row-expand',
87
+ size:
88
+ groupedColumnMode === 'remove'
89
+ ? defaultColumn?.size ?? 180
90
+ : renderDetailPanel
91
+ ? enableExpandAll
92
+ ? 60
93
+ : 70
94
+ : 100,
95
+ tableOptions,
96
+ }),
97
+ };
98
+ };