@cutting/material-react-table 5.0.0-beta.2 → 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.
Files changed (190) hide show
  1. package/README.md +1 -4
  2. package/dist/index.d.ts +189 -524
  3. package/dist/index.js +329 -345
  4. package/dist/index.js.map +1 -1
  5. package/locales/ar/index.mjs +1 -2
  6. package/locales/az/index.mjs +1 -2
  7. package/locales/bg/index.mjs +1 -2
  8. package/locales/cs/index.mjs +1 -2
  9. package/locales/da/index.mjs +1 -2
  10. package/locales/de/index.mjs +1 -2
  11. package/locales/el/index.mjs +1 -2
  12. package/locales/en/index.mjs +1 -2
  13. package/locales/es/index.mjs +1 -2
  14. package/locales/et/index.mjs +1 -2
  15. package/locales/fa/index.mjs +1 -2
  16. package/locales/fi/index.mjs +1 -2
  17. package/locales/fr/index.mjs +1 -2
  18. package/locales/he/index.mjs +1 -2
  19. package/locales/hr/index.mjs +1 -2
  20. package/locales/hu/index.mjs +1 -2
  21. package/locales/hy/index.mjs +1 -2
  22. package/locales/id/index.mjs +1 -2
  23. package/locales/it/index.mjs +1 -2
  24. package/locales/ja/index.mjs +1 -2
  25. package/locales/ko/index.mjs +1 -2
  26. package/locales/nl/index.mjs +1 -2
  27. package/locales/no/index.mjs +1 -2
  28. package/locales/np/index.mjs +1 -2
  29. package/locales/pl/index.mjs +1 -2
  30. package/locales/pt/index.mjs +1 -2
  31. package/locales/pt-BR/index.mjs +1 -2
  32. package/locales/ro/index.mjs +1 -2
  33. package/locales/ru/index.mjs +1 -2
  34. package/locales/sk/index.mjs +1 -2
  35. package/locales/sr-Cyrl-RS/index.mjs +1 -2
  36. package/locales/sr-Latn-RS/index.mjs +1 -2
  37. package/locales/sv/index.mjs +1 -2
  38. package/locales/tr/index.mjs +1 -2
  39. package/locales/uk/index.mjs +1 -2
  40. package/locales/vi/index.mjs +1 -2
  41. package/locales/zh-Hans/index.mjs +1 -2
  42. package/locales/zh-Hant/index.mjs +1 -2
  43. package/package.json +32 -40
  44. package/src/MaterialReactTable.smoke.test.tsx +3 -9
  45. package/src/components/MaterialReactTable.tsx +13 -21
  46. package/src/components/body/MRT_TableBody.tsx +67 -82
  47. package/src/components/body/MRT_TableBodyCell.tsx +38 -80
  48. package/src/components/body/MRT_TableBodyCellValue.tsx +5 -14
  49. package/src/components/body/MRT_TableBodyRow.tsx +55 -102
  50. package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +2 -6
  51. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -9
  52. package/src/components/body/MRT_TableBodyRowPinButton.tsx +8 -14
  53. package/src/components/body/MRT_TableDetailPanel.test.tsx +3 -9
  54. package/src/components/body/MRT_TableDetailPanel.tsx +8 -14
  55. package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +6 -16
  56. package/src/components/buttons/MRT_ColumnPinningButtons.tsx +6 -12
  57. package/src/components/buttons/MRT_CopyButton.tsx +7 -15
  58. package/src/components/buttons/MRT_EditActionButtons.test.tsx +2 -6
  59. package/src/components/buttons/MRT_EditActionButtons.tsx +15 -37
  60. package/src/components/buttons/MRT_ExpandAllButton.tsx +8 -16
  61. package/src/components/buttons/MRT_ExpandButton.tsx +9 -21
  62. package/src/components/buttons/MRT_GrabHandleButton.tsx +6 -10
  63. package/src/components/buttons/MRT_RowPinButton.tsx +8 -23
  64. package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +5 -18
  65. package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +4 -12
  66. package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +4 -11
  67. package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +4 -13
  68. package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -5
  69. package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +3 -11
  70. package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +4 -9
  71. package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -5
  72. package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -15
  73. package/src/components/footer/MRT_TableFooter.tsx +9 -16
  74. package/src/components/footer/MRT_TableFooterCell.tsx +9 -32
  75. package/src/components/footer/MRT_TableFooterRow.tsx +18 -32
  76. package/src/components/head/MRT_TableHead.tsx +8 -18
  77. package/src/components/head/MRT_TableHeadCell.tsx +46 -100
  78. package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -30
  79. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -15
  80. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +20 -54
  81. package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +5 -19
  82. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +9 -38
  83. package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +3 -13
  84. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +10 -24
  85. package/src/components/head/MRT_TableHeadCellSortLabel.tsx +10 -26
  86. package/src/components/head/MRT_TableHeadRow.tsx +24 -36
  87. package/src/components/inputs/MRT_EditCellTextField.test.tsx +2 -9
  88. package/src/components/inputs/MRT_EditCellTextField.tsx +9 -28
  89. package/src/components/inputs/MRT_FilterCheckbox.tsx +9 -23
  90. package/src/components/inputs/MRT_FilterRangeFields.tsx +6 -15
  91. package/src/components/inputs/MRT_FilterRangeSlider.tsx +24 -32
  92. package/src/components/inputs/MRT_FilterTextField.test.tsx +72 -14
  93. package/src/components/inputs/MRT_FilterTextField.tsx +77 -138
  94. package/src/components/inputs/MRT_GlobalFilterTextField.tsx +10 -32
  95. package/src/components/inputs/MRT_SelectCheckbox.test.tsx +4 -11
  96. package/src/components/inputs/MRT_SelectCheckbox.tsx +17 -36
  97. package/src/components/menus/MRT_ActionMenuItem.tsx +6 -15
  98. package/src/components/menus/MRT_CellActionMenu.tsx +6 -9
  99. package/src/components/menus/MRT_ColumnActionMenu.tsx +22 -57
  100. package/src/components/menus/MRT_FilterOptionMenu.tsx +38 -65
  101. package/src/components/menus/MRT_RowActionMenu.tsx +33 -22
  102. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +29 -65
  103. package/src/components/menus/MRT_ShowHideColumnsMenuItems.test.tsx +43 -0
  104. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +14 -50
  105. package/src/components/modals/MRT_EditRowModal.test.tsx +5 -21
  106. package/src/components/modals/MRT_EditRowModal.tsx +8 -26
  107. package/src/components/table/MRT_Table.tsx +12 -20
  108. package/src/components/table/MRT_TableContainer.test.tsx +147 -0
  109. package/src/components/table/MRT_TableContainer.tsx +33 -37
  110. package/src/components/table/MRT_TableLoadingOverlay.tsx +3 -5
  111. package/src/components/table/MRT_TablePaper.tsx +7 -14
  112. package/src/components/toolbar/MRT_BottomToolbar.tsx +11 -23
  113. package/src/components/toolbar/MRT_LinearProgressBar.tsx +4 -11
  114. package/src/components/toolbar/MRT_TablePagination.tsx +33 -40
  115. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +21 -50
  116. package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +26 -10
  117. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +23 -21
  118. package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +11 -21
  119. package/src/components/toolbar/MRT_TopToolbar.tsx +12 -28
  120. package/src/fns/aggregationFns.test.tsx +1 -3
  121. package/src/fns/filterFns.test.tsx +9 -37
  122. package/src/fns/filterFns.ts +73 -96
  123. package/src/fns/sortingFns.test.tsx +39 -0
  124. package/src/fns/sortingFns.ts +15 -15
  125. package/src/fns/tableFeatures.test.tsx +6 -29
  126. package/src/fns/tableFeatures.ts +5 -4
  127. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +2 -11
  128. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +2 -10
  129. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +8 -17
  130. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +3 -8
  131. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +2 -8
  132. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +3 -13
  133. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -5
  134. package/src/hooks/useMRT_ColumnVirtualizer.ts +28 -49
  135. package/src/hooks/useMRT_Effects.test.tsx +114 -0
  136. package/src/hooks/useMRT_Effects.ts +26 -27
  137. package/src/hooks/useMRT_RowVirtualizer.ts +18 -33
  138. package/src/hooks/useMRT_Rows.ts +3 -42
  139. package/src/hooks/useMRT_TableInstance.ts +63 -129
  140. package/src/hooks/useMRT_TableOptions.ts +15 -29
  141. package/src/hooks/useMaterialReactTable.ts +2 -7
  142. package/src/icons.ts +38 -1
  143. package/src/index.ts +0 -4
  144. package/src/locales/ar.ts +1 -2
  145. package/src/locales/az.ts +1 -2
  146. package/src/locales/bg.ts +1 -2
  147. package/src/locales/cs.ts +2 -4
  148. package/src/locales/da.ts +1 -2
  149. package/src/locales/de.ts +1 -2
  150. package/src/locales/el.ts +1 -2
  151. package/src/locales/en.ts +1 -2
  152. package/src/locales/es.ts +1 -2
  153. package/src/locales/et.ts +2 -4
  154. package/src/locales/fa.ts +1 -2
  155. package/src/locales/fi.ts +2 -4
  156. package/src/locales/fr.ts +1 -2
  157. package/src/locales/he.ts +1 -2
  158. package/src/locales/hr.ts +1 -2
  159. package/src/locales/hu.ts +1 -2
  160. package/src/locales/hy.ts +1 -2
  161. package/src/locales/id.ts +2 -4
  162. package/src/locales/it.ts +1 -2
  163. package/src/locales/ja.ts +1 -2
  164. package/src/locales/ko.ts +1 -2
  165. package/src/locales/nl.ts +1 -2
  166. package/src/locales/no.ts +2 -4
  167. package/src/locales/np.ts +2 -4
  168. package/src/locales/pl.ts +1 -2
  169. package/src/locales/pt-BR.ts +1 -2
  170. package/src/locales/pt.ts +1 -2
  171. package/src/locales/ro.ts +1 -2
  172. package/src/locales/ru.ts +1 -2
  173. package/src/locales/sk.ts +2 -4
  174. package/src/locales/sr-Cyrl-RS.ts +1 -2
  175. package/src/locales/sr-Latn-RS.ts +1 -2
  176. package/src/locales/sv.ts +1 -2
  177. package/src/locales/tr.ts +1 -2
  178. package/src/locales/uk.ts +1 -2
  179. package/src/locales/vi.ts +1 -2
  180. package/src/types.ts +156 -349
  181. package/src/utils/cell.utils.ts +30 -68
  182. package/src/utils/column.utils.ts +61 -49
  183. package/src/utils/displayColumn.utils.ts +16 -38
  184. package/src/utils/highlight.utils.ts +7 -11
  185. package/src/utils/row.utils.ts +40 -65
  186. package/src/utils/slotProps.utils.ts +1 -4
  187. package/src/utils/style.utils.ts +18 -46
  188. package/src/utils/tanstack.helpers.ts +10 -17
  189. package/src/utils/utils.ts +6 -10
  190. package/src/utils/virtualization.utils.ts +5 -9
@@ -1,30 +1,22 @@
1
- import { IconButton, type IconButtonProps } from '@mui/material';
2
- import { Tooltip } from '@mui/material';
1
+ import { IconButton, type IconButtonProps, Tooltip } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
3
3
  import { type MouseEvent, useState } from 'react';
4
4
 
5
- import {
6
- type MRT_Header,
7
- type MRT_RowData,
8
- type MRT_TableInstance,
9
- } from '../../types';
5
+ import { type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
10
6
  import { getCommonTooltipProps } from '../../utils/style.utils';
11
7
  import { parseFromValuesOrFunc } from '../../utils/utils';
12
8
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
13
9
 
14
- export interface MRT_TableHeadCellColumnActionsButtonProps<
15
- TData extends MRT_RowData,
16
- > extends IconButtonProps {
10
+ export interface MRT_TableHeadCellColumnActionsButtonProps<TData extends MRT_RowData> extends IconButtonProps {
17
11
  header: MRT_Header<TData>;
18
12
  table: MRT_TableInstance<TData>;
19
13
  }
20
14
 
21
- export const MRT_TableHeadCellColumnActionsButton = <
22
- TData extends MRT_RowData,
23
- >({
15
+ export const MRT_TableHeadCellColumnActionsButton = <TData extends MRT_RowData>({
24
16
  header,
25
17
  table,
26
18
  ...rest
27
- }: MRT_TableHeadCellColumnActionsButtonProps<TData>) => {
19
+ }: MRT_TableHeadCellColumnActionsButtonProps<TData>): JSX.Element => {
28
20
  const {
29
21
  options: {
30
22
  icons: { MoreVertIcon },
@@ -57,10 +49,7 @@ export const MRT_TableHeadCellColumnActionsButton = <
57
49
 
58
50
  return (
59
51
  <>
60
- <Tooltip
61
- {...getCommonTooltipProps('top')}
62
- title={iconButtonProps?.title ?? localization.columnActions}
63
- >
52
+ <Tooltip {...getCommonTooltipProps('top')} title={iconButtonProps?.title ?? localization.columnActions}>
64
53
  <IconButton
65
54
  aria-label={localization.columnActions}
66
55
  onClick={handleClick}
@@ -75,23 +64,14 @@ export const MRT_TableHeadCellColumnActionsButton = <
75
64
  opacity: 0.3,
76
65
  transition: 'all 150ms',
77
66
  width: '2rem',
78
- ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
67
+ ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as CSSObject),
79
68
  })}
80
69
  title={undefined}
81
70
  >
82
- {iconButtonProps?.children ?? (
83
- <MoreVertIcon style={{ transform: 'scale(0.9)' }} />
84
- )}
71
+ {iconButtonProps?.children ?? <MoreVertIcon style={{ transform: 'scale(0.9)' }} />}
85
72
  </IconButton>
86
73
  </Tooltip>
87
- {anchorEl && (
88
- <MRT_ColumnActionMenu
89
- anchorEl={anchorEl}
90
- header={header}
91
- setAnchorEl={setAnchorEl}
92
- table={table}
93
- />
94
- )}
74
+ {anchorEl && <MRT_ColumnActionMenu anchorEl={anchorEl} header={header} setAnchorEl={setAnchorEl} table={table} />}
95
75
  </>
96
76
  );
97
77
  };
@@ -1,19 +1,13 @@
1
1
  import { Collapse, type CollapseProps } from '@mui/material';
2
2
 
3
- import {
4
- type MRT_Header,
5
- type MRT_RowData,
6
- type MRT_TableInstance,
7
- } from '../../types';
3
+ import { type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
8
4
  import { getColumnFilterInfo } from '../../utils/column.utils';
9
5
  import { MRT_FilterCheckbox } from '../inputs/MRT_FilterCheckbox';
10
6
  import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
11
7
  import { MRT_FilterRangeSlider } from '../inputs/MRT_FilterRangeSlider';
12
8
  import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
13
9
 
14
- export interface MRT_TableHeadCellFilterContainerProps<
15
- TData extends MRT_RowData,
16
- > extends CollapseProps {
10
+ export interface MRT_TableHeadCellFilterContainerProps<TData extends MRT_RowData> extends CollapseProps {
17
11
  header: MRT_Header<TData>;
18
12
  table: MRT_TableInstance<TData>;
19
13
  }
@@ -22,7 +16,7 @@ export const MRT_TableHeadCellFilterContainer = <TData extends MRT_RowData>({
22
16
  header,
23
17
  table,
24
18
  ...rest
25
- }: MRT_TableHeadCellFilterContainerProps<TData>) => {
19
+ }: MRT_TableHeadCellFilterContainerProps<TData>): JSX.Element => {
26
20
  const {
27
21
  options: { columnFilterDisplayMode },
28
22
  } = table;
@@ -32,12 +26,7 @@ export const MRT_TableHeadCellFilterContainer = <TData extends MRT_RowData>({
32
26
  const { isRangeFilter } = getColumnFilterInfo({ header, table });
33
27
 
34
28
  return (
35
- <Collapse
36
- in={showColumnFilters || columnFilterDisplayMode === 'popover'}
37
- mountOnEnter
38
- unmountOnExit
39
- {...rest}
40
- >
29
+ <Collapse in={showColumnFilters || columnFilterDisplayMode === 'popover'} mountOnEnter unmountOnExit {...rest}>
41
30
  {columnDef.filterVariant === 'checkbox' ? (
42
31
  <MRT_FilterCheckbox column={column} table={table} />
43
32
  ) : columnDef.filterVariant === 'range-slider' ? (
@@ -1,33 +1,22 @@
1
- import { Box } from '@mui/material';
2
- import { Grow } from '@mui/material';
3
- import { IconButton, type IconButtonProps } from '@mui/material';
4
- import { Popover } from '@mui/material';
5
- import { Tooltip } from '@mui/material';
1
+ import { Box, Grow, IconButton, type IconButtonProps, Popover, Tooltip } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
6
3
  import { type MouseEvent, useState } from 'react';
7
4
 
8
- import {
9
- type MRT_Header,
10
- type MRT_RowData,
11
- type MRT_TableInstance,
12
- } from '../../types';
13
- import {
14
- getColumnFilterInfo,
15
- useDropdownOptions,
16
- } from '../../utils/column.utils';
5
+ import { type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
6
+ import { getColumnFilterInfo, getFilterOptionLabel, useDropdownOptions } from '../../utils/column.utils';
17
7
  import { getValueAndLabel, parseFromValuesOrFunc } from '../../utils/utils';
18
8
  import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
19
9
 
20
- export interface MRT_TableHeadCellFilterLabelProps<TData extends MRT_RowData>
21
- extends IconButtonProps {
10
+ export interface MRT_TableHeadCellFilterLabelProps<TData extends MRT_RowData> extends IconButtonProps {
22
11
  header: MRT_Header<TData>;
23
12
  table: MRT_TableInstance<TData>;
24
13
  }
25
14
 
26
- export const MRT_TableHeadCellFilterLabel = <TData extends MRT_RowData = {}>({
15
+ export const MRT_TableHeadCellFilterLabel = <TData extends MRT_RowData = MRT_RowData>({
27
16
  header,
28
17
  table,
29
18
  ...rest
30
- }: MRT_TableHeadCellFilterLabelProps<TData>) => {
19
+ }: MRT_TableHeadCellFilterLabelProps<TData>): JSX.Element => {
31
20
  const {
32
21
  options: {
33
22
  columnFilterDisplayMode,
@@ -44,58 +33,36 @@ export const MRT_TableHeadCellFilterLabel = <TData extends MRT_RowData = {}>({
44
33
 
45
34
  const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
46
35
 
47
- const {
48
- currentFilterOption,
49
- isMultiSelectFilter,
50
- isRangeFilter,
51
- isSelectFilter,
52
- } = getColumnFilterInfo({ header, table });
36
+ const { currentFilterOption, isMultiSelectFilter, isRangeFilter, isSelectFilter } = getColumnFilterInfo({
37
+ header,
38
+ table,
39
+ });
53
40
 
54
41
  const dropdownOptions = useDropdownOptions({ header, table });
55
42
 
56
43
  const getSelectLabel = (index?: number) =>
57
44
  getValueAndLabel(
58
45
  dropdownOptions?.find(
59
- (option) =>
60
- getValueAndLabel(option).value ===
61
- (index !== undefined ? filterValue[index] : filterValue),
46
+ (option) => getValueAndLabel(option).value === (index !== undefined ? filterValue[index] : filterValue),
62
47
  ),
63
48
  ).label;
64
49
 
65
50
  const isFilterActive =
66
- (Array.isArray(filterValue) && filterValue.some(Boolean)) ||
67
- (!!filterValue && !Array.isArray(filterValue));
51
+ (Array.isArray(filterValue) && filterValue.some(Boolean)) || (!!filterValue && !Array.isArray(filterValue));
68
52
 
69
53
  const filterTooltip =
70
54
  columnFilterDisplayMode === 'popover' && !isFilterActive
71
- ? localization.filterByColumn?.replace(
72
- '{column}',
73
- String(columnDef.header),
74
- )
55
+ ? localization.filterByColumn?.replace('{column}', String(columnDef.header))
75
56
  : localization.filteringByColumn
76
57
  .replace('{column}', String(columnDef.header))
77
- .replace(
78
- '{filterType}',
79
- currentFilterOption
80
- ? localization[
81
- `filter${
82
- currentFilterOption.charAt(0).toUpperCase() +
83
- currentFilterOption.slice(1)
84
- }` as keyof typeof localization
85
- ]
86
- : '',
87
- )
58
+ .replace('{filterType}', currentFilterOption ? getFilterOptionLabel(localization, currentFilterOption) : '')
88
59
  .replace(
89
60
  '{filterValue}',
90
61
  `"${
91
62
  Array.isArray(filterValue)
92
63
  ? (filterValue as [string, string])
93
- .map((value, index) =>
94
- isMultiSelectFilter ? getSelectLabel(index) : value,
95
- )
96
- .join(
97
- `" ${isRangeFilter ? localization.and : localization.or} "`,
98
- )
64
+ .map((value, index) => (isMultiSelectFilter ? getSelectLabel(index) : value))
65
+ .join(`" ${isRangeFilter ? localization.and : localization.or} "`)
99
66
  : isSelectFilter
100
67
  ? getSelectLabel()
101
68
  : (filterValue as string)
@@ -139,7 +106,7 @@ export const MRT_TableHeadCellFilterLabel = <TData extends MRT_RowData = {}>({
139
106
  transform: 'scale(0.75)',
140
107
  transition: 'all 150ms ease-in-out',
141
108
  width: '16px',
142
- ...(parseFromValuesOrFunc(rest?.sx, theme) as any),
109
+ ...(parseFromValuesOrFunc(rest?.sx, theme) as CSSObject),
143
110
  })}
144
111
  >
145
112
  <FilterAltIcon />
@@ -156,9 +123,8 @@ export const MRT_TableHeadCellFilterLabel = <TData extends MRT_RowData = {}>({
156
123
  }}
157
124
  disableScrollLock
158
125
  onClick={(event) => event.stopPropagation()}
159
- onClose={(event) => {
160
- //@ts-expect-error
161
- event.stopPropagation();
126
+ onClose={(event: { stopPropagation?: () => void }) => {
127
+ event.stopPropagation?.();
162
128
  setAnchorEl(null);
163
129
  }}
164
130
  onKeyDown={(event) => event.key === 'Enter' && setAnchorEl(null)}
@@ -17,20 +17,12 @@ const columns = (): MRT_ColumnDef<Person>[] => [
17
17
  ];
18
18
 
19
19
  const headerOrder = (container: HTMLElement) =>
20
- Array.from(container.querySelectorAll('thead th')).map((th) =>
21
- th.textContent?.replace(/[^A-Za-z]/g, ''),
22
- );
20
+ Array.from(container.querySelectorAll('thead th')).map((th) => th.textContent?.replace(/[^A-Za-z]/g, ''));
23
21
 
24
22
  const dragColumnOnto = (container: HTMLElement, from: string, to: string) => {
25
- const handles = Array.from(
26
- container.querySelectorAll<HTMLElement>('thead [aria-label="Move"]'),
27
- );
28
- const headerCells = Array.from(
29
- container.querySelectorAll<HTMLElement>('thead th'),
30
- );
31
- const fromIndex = headerCells.findIndex((th) =>
32
- th.textContent?.includes(from),
33
- );
23
+ const handles = Array.from(container.querySelectorAll<HTMLElement>('thead [aria-label="Move"]'));
24
+ const headerCells = Array.from(container.querySelectorAll<HTMLElement>('thead th'));
25
+ const fromIndex = headerCells.findIndex((th) => th.textContent?.includes(from));
34
26
  const toIndex = headerCells.findIndex((th) => th.textContent?.includes(to));
35
27
 
36
28
  fireEvent.dragStart(handles[fromIndex], {
@@ -44,13 +36,7 @@ const dragColumnOnto = (container: HTMLElement, from: string, to: string) => {
44
36
 
45
37
  describe('column dragging', () => {
46
38
  test('reorders columns when one is dragged onto another', () => {
47
- const { container } = render(
48
- <MaterialReactTable
49
- columns={columns()}
50
- data={data}
51
- enableColumnOrdering
52
- />,
53
- );
39
+ const { container } = render(<MaterialReactTable columns={columns()} data={data} enableColumnOrdering />);
54
40
 
55
41
  expect(headerOrder(container)).toEqual(['Name', 'City']);
56
42
 
@@ -1,17 +1,12 @@
1
1
  import { type IconButtonProps } from '@mui/material/IconButton';
2
2
  import { type DragEvent, type RefObject } from 'react';
3
3
 
4
- import {
5
- type MRT_Column,
6
- type MRT_RowData,
7
- type MRT_TableInstance,
8
- } from '../../types';
9
- import { reorderColumn } from '../../utils/column.utils';
4
+ import { type MRT_Column, type MRT_RowData, type MRT_TableInstance } from '../../types';
5
+ import { moveColumn } from '../../utils/column.utils';
10
6
  import { parseFromValuesOrFunc } from '../../utils/utils';
11
7
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
12
8
 
13
- export interface MRT_TableHeadCellGrabHandleProps<TData extends MRT_RowData>
14
- extends IconButtonProps {
9
+ export interface MRT_TableHeadCellGrabHandleProps<TData extends MRT_RowData> extends IconButtonProps {
15
10
  column: MRT_Column<TData>;
16
11
  table: MRT_TableInstance<TData>;
17
12
  tableHeadCellRef: RefObject<HTMLTableCellElement | null>;
@@ -22,16 +17,14 @@ export const MRT_TableHeadCellGrabHandle = <TData extends MRT_RowData>({
22
17
  table,
23
18
  tableHeadCellRef,
24
19
  ...rest
25
- }: MRT_TableHeadCellGrabHandleProps<TData>) => {
20
+ }: MRT_TableHeadCellGrabHandleProps<TData>): JSX.Element => {
26
21
  const {
27
22
  options: { enableColumnOrdering, muiColumnDragHandleProps },
28
- setColumnOrder,
29
- setColumnPinning,
30
23
  setDraggingColumn,
31
24
  setHoveredColumn,
32
25
  } = table;
33
26
  const { columnDef } = column;
34
- const { columnOrder, draggingColumn, hoveredColumn } = table.state;
27
+ const { draggingColumn, hoveredColumn } = table.state;
35
28
 
36
29
  const iconButtonProps = {
37
30
  ...parseFromValuesOrFunc(muiColumnDragHandleProps, { column, table }),
@@ -46,11 +39,7 @@ export const MRT_TableHeadCellGrabHandle = <TData extends MRT_RowData>({
46
39
  iconButtonProps?.onDragStart?.(event);
47
40
  setDraggingColumn(column);
48
41
  try {
49
- event.dataTransfer.setDragImage(
50
- tableHeadCellRef.current as HTMLElement,
51
- 0,
52
- 0,
53
- );
42
+ event.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
54
43
  } catch (e) {
55
44
  console.error(e);
56
45
  }
@@ -60,32 +49,14 @@ export const MRT_TableHeadCellGrabHandle = <TData extends MRT_RowData>({
60
49
  iconButtonProps?.onDragEnd?.(event);
61
50
  if (hoveredColumn?.id === 'drop-zone') {
62
51
  column.toggleGrouping();
63
- } else if (
64
- enableColumnOrdering &&
65
- hoveredColumn &&
66
- hoveredColumn?.id !== draggingColumn?.id
67
- ) {
68
- const reorderedColumns = reorderColumn(
69
- column,
70
- hoveredColumn as MRT_Column<TData>,
71
- columnOrder,
72
- );
73
- setColumnOrder(reorderedColumns);
74
- setColumnPinning(({ end = [], start = [] }) => ({
75
- end: reorderedColumns.filter((header) => end.includes(header)),
76
- start: reorderedColumns.filter((header) => start.includes(header)),
77
- }));
52
+ } else if (enableColumnOrdering && hoveredColumn && hoveredColumn?.id !== draggingColumn?.id) {
53
+ moveColumn(table, column, hoveredColumn as MRT_Column<TData>);
78
54
  }
79
55
  setDraggingColumn(null);
80
56
  setHoveredColumn(null);
81
57
  };
82
58
 
83
59
  return (
84
- <MRT_GrabHandleButton
85
- {...iconButtonProps}
86
- onDragEnd={handleDragEnd}
87
- onDragStart={handleDragStart}
88
- table={table}
89
- />
60
+ <MRT_GrabHandleButton {...iconButtonProps} onDragEnd={handleDragEnd} onDragStart={handleDragStart} table={table} />
90
61
  );
91
62
  };
@@ -17,24 +17,14 @@ const columns = (): MRT_ColumnDef<Person>[] => [
17
17
  ];
18
18
 
19
19
  const nameColumnSize = (container: HTMLElement) =>
20
- (container.querySelector('table') as HTMLElement).style.getPropertyValue(
21
- '--header-name-size',
22
- );
20
+ (container.querySelector('table') as HTMLElement).style.getPropertyValue('--header-name-size');
23
21
 
24
22
  describe('column resizing', () => {
25
23
  test('dragging the resize handle widens the column', () => {
26
- const { container } = render(
27
- <MaterialReactTable
28
- columns={columns()}
29
- data={data}
30
- enableColumnResizing
31
- />,
32
- );
24
+ const { container } = render(<MaterialReactTable columns={columns()} data={data} enableColumnResizing />);
33
25
 
34
26
  const before = nameColumnSize(container);
35
- const handle = container.querySelector(
36
- 'thead .Mui-TableHeadCell-ResizeHandle-Wrapper',
37
- ) as HTMLElement;
27
+ const handle = container.querySelector('thead .Mui-TableHeadCell-ResizeHandle-Wrapper') as HTMLElement;
38
28
 
39
29
  fireEvent.mouseDown(handle, { clientX: 0 });
40
30
  fireEvent.mouseMove(document, { clientX: 120 });
@@ -1,15 +1,10 @@
1
- import { Box } from '@mui/material';
2
- import { Divider, type DividerProps } from '@mui/material';
1
+ import { Box, Divider, type DividerProps } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
3
3
 
4
- import {
5
- type MRT_Header,
6
- type MRT_RowData,
7
- type MRT_TableInstance,
8
- } from '../../types';
4
+ import { type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
9
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
10
6
 
11
- export interface MRT_TableHeadCellResizeHandleProps<TData extends MRT_RowData>
12
- extends DividerProps {
7
+ export interface MRT_TableHeadCellResizeHandleProps<TData extends MRT_RowData> extends DividerProps {
13
8
  header: MRT_Header<TData>;
14
9
  table: MRT_TableInstance<TData>;
15
10
  }
@@ -18,7 +13,7 @@ export const MRT_TableHeadCellResizeHandle = <TData extends MRT_RowData>({
18
13
  header,
19
14
  table,
20
15
  ...rest
21
- }: MRT_TableHeadCellResizeHandleProps<TData>) => {
16
+ }: MRT_TableHeadCellResizeHandleProps<TData>): JSX.Element => {
22
17
  const {
23
18
  options: { columnResizeDirection, columnResizeMode },
24
19
  setColumnResizing,
@@ -28,12 +23,7 @@ export const MRT_TableHeadCellResizeHandle = <TData extends MRT_RowData>({
28
23
 
29
24
  const handler = header.getResizeHandler();
30
25
 
31
- const mx =
32
- density === 'compact'
33
- ? '-8px'
34
- : density === 'comfortable'
35
- ? '-16px'
36
- : '-24px';
26
+ const mx = density === 'compact' ? '-8px' : density === 'comfortable' ? '-16px' : '-24px';
37
27
 
38
28
  const lr = column.columnDef.columnDefType === 'display' ? '4px' : '0';
39
29
 
@@ -53,16 +43,14 @@ export const MRT_TableHeadCellResizeHandle = <TData extends MRT_RowData>({
53
43
  transform:
54
44
  column.getIsResizing() && columnResizeMode === 'onEnd'
55
45
  ? `translateX(${
56
- (columnResizeDirection === 'rtl' ? -1 : 1) *
57
- (table.state.columnResizing.deltaOffset ?? 0)
46
+ (columnResizeDirection === 'rtl' ? -1 : 1) * (table.state.columnResizing.deltaOffset ?? 0)
58
47
  }px)`
59
48
  : undefined,
60
49
  }}
61
50
  sx={(theme) => ({
62
51
  '&:active > hr': {
63
52
  backgroundColor: theme.palette.info.main,
64
- opacity:
65
- header.subHeaders.length || columnResizeMode === 'onEnd' ? 1 : 0,
53
+ opacity: header.subHeaders.length || columnResizeMode === 'onEnd' ? 1 : 0,
66
54
  },
67
55
  cursor: 'col-resize',
68
56
  left: columnResizeDirection === 'rtl' ? lr : undefined,
@@ -83,12 +71,10 @@ export const MRT_TableHeadCellResizeHandle = <TData extends MRT_RowData>({
83
71
  height: '24px',
84
72
  touchAction: 'none',
85
73
  transform: 'translateX(4px)',
86
- transition: column.getIsResizing()
87
- ? undefined
88
- : 'all 150ms ease-in-out',
74
+ transition: column.getIsResizing() ? undefined : 'all 150ms ease-in-out',
89
75
  userSelect: 'none',
90
76
  zIndex: 4,
91
- ...(parseFromValuesOrFunc(rest?.sx, theme) as any),
77
+ ...(parseFromValuesOrFunc(rest?.sx, theme) as CSSObject),
92
78
  })}
93
79
  />
94
80
  </Box>
@@ -1,16 +1,10 @@
1
- import { Badge } from '@mui/material';
2
- import { TableSortLabel, type TableSortLabelProps } from '@mui/material';
3
- import { Tooltip } from '@mui/material';
1
+ import { Badge, TableSortLabel, type TableSortLabelProps, Tooltip } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
4
3
 
5
- import {
6
- type MRT_Header,
7
- type MRT_RowData,
8
- type MRT_TableInstance,
9
- } from '../../types';
4
+ import { type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
10
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
11
6
 
12
- export interface MRT_TableHeadCellSortLabelProps<TData extends MRT_RowData>
13
- extends TableSortLabelProps {
7
+ export interface MRT_TableHeadCellSortLabelProps<TData extends MRT_RowData> extends TableSortLabelProps {
14
8
  header: MRT_Header<TData>;
15
9
  table: MRT_TableInstance<TData>;
16
10
  }
@@ -19,7 +13,7 @@ export const MRT_TableHeadCellSortLabel = <TData extends MRT_RowData>({
19
13
  header,
20
14
  table,
21
15
  ...rest
22
- }: MRT_TableHeadCellSortLabelProps<TData>) => {
16
+ }: MRT_TableHeadCellSortLabelProps<TData>): JSX.Element => {
23
17
  const {
24
18
  options: {
25
19
  icons: { ArrowDownwardIcon, SyncAltIcon },
@@ -37,25 +31,17 @@ export const MRT_TableHeadCellSortLabel = <TData extends MRT_RowData>({
37
31
  ? ''
38
32
  : column.getIsSorted()
39
33
  ? column.getIsSorted() === 'desc'
40
- ? localization.sortedByColumnDesc.replace(
41
- '{column}',
42
- columnDef.header,
43
- )
34
+ ? localization.sortedByColumnDesc.replace('{column}', columnDef.header)
44
35
  : localization.sortedByColumnAsc.replace('{column}', columnDef.header)
45
36
  : column.getNextSortingOrder() === 'desc'
46
37
  ? localization.sortByColumnDesc.replace('{column}', columnDef.header)
47
38
  : localization.sortByColumnAsc.replace('{column}', columnDef.header);
48
39
 
49
- const direction = isSorted
50
- ? (column.getIsSorted() as 'asc' | 'desc')
51
- : undefined;
40
+ const direction = isSorted ? (column.getIsSorted() as 'asc' | 'desc') : undefined;
52
41
 
53
42
  return (
54
43
  <Tooltip placement="top" title={sortTooltip}>
55
- <Badge
56
- badgeContent={sorting.length > 1 ? column.getSortIndex() + 1 : 0}
57
- overlap="circular"
58
- >
44
+ <Badge badgeContent={sorting.length > 1 ? column.getSortIndex() + 1 : 0} overlap="circular">
59
45
  <TableSortLabel
60
46
  active
61
47
  aria-label={sortTooltip}
@@ -81,16 +67,14 @@ export const MRT_TableHeadCellSortLabel = <TData extends MRT_RowData>({
81
67
  sx={(theme) => ({
82
68
  '.MuiTableSortLabel-icon': {
83
69
  color: `${
84
- theme.palette.mode === 'dark'
85
- ? theme.palette.text.primary
86
- : theme.palette.text.secondary
70
+ theme.palette.mode === 'dark' ? theme.palette.text.primary : theme.palette.text.secondary
87
71
  } !important`,
88
72
  },
89
73
  flex: '0 0',
90
74
  opacity: isSorted ? 1 : 0.3,
91
75
  transition: 'all 150ms ease-in-out',
92
76
  width: '3ch',
93
- ...(parseFromValuesOrFunc(rest?.sx, theme) as any),
77
+ ...(parseFromValuesOrFunc(rest?.sx, theme) as CSSObject),
94
78
  })}
95
79
  />
96
80
  </Badge>
@@ -1,5 +1,5 @@
1
1
  import { TableRow, type TableRowProps } from '@mui/material';
2
- import { alpha } from '@mui/material/styles';
2
+ import { alpha, type CSSObject } from '@mui/material/styles';
3
3
 
4
4
  import {
5
5
  type MRT_ColumnVirtualizer,
@@ -12,8 +12,7 @@ import {
12
12
  import { parseFromValuesOrFunc } from '../../utils/utils';
13
13
  import { MRT_TableHeadCell } from './MRT_TableHeadCell';
14
14
 
15
- export interface MRT_TableHeadRowProps<TData extends MRT_RowData>
16
- extends TableRowProps {
15
+ export interface MRT_TableHeadRowProps<TData extends MRT_RowData> extends TableRowProps {
17
16
  columnVirtualizer?: MRT_ColumnVirtualizer;
18
17
  headerGroup: MRT_HeaderGroup<TData>;
19
18
  table: MRT_TableInstance<TData>;
@@ -24,7 +23,7 @@ export const MRT_TableHeadRow = <TData extends MRT_RowData>({
24
23
  headerGroup,
25
24
  table,
26
25
  ...rest
27
- }: MRT_TableHeadRowProps<TData>) => {
26
+ }: MRT_TableHeadRowProps<TData>): JSX.Element => {
28
27
  const {
29
28
  options: {
30
29
  enableStickyHeader,
@@ -34,8 +33,7 @@ export const MRT_TableHeadRow = <TData extends MRT_RowData>({
34
33
  },
35
34
  } = table;
36
35
 
37
- const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
38
- columnVirtualizer ?? {};
36
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
39
37
 
40
38
  const tableRowProps = {
41
39
  ...parseFromValuesOrFunc(muiTableHeadRowProps, {
@@ -52,40 +50,30 @@ export const MRT_TableHeadRow = <TData extends MRT_RowData>({
52
50
  backgroundColor: baseBackgroundColor,
53
51
  boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
54
52
  display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
55
- position:
56
- enableStickyHeader && layoutMode === 'semantic'
57
- ? 'sticky'
58
- : 'relative',
53
+ position: enableStickyHeader && layoutMode === 'semantic' ? 'sticky' : 'relative',
59
54
  top: 0,
60
- ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as any),
55
+ ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as CSSObject),
61
56
  })}
62
57
  >
63
- {virtualPaddingLeft ? (
64
- <th style={{ display: 'flex', width: virtualPaddingLeft }} />
65
- ) : null}
66
- {(virtualColumns ?? headerGroup.headers).map(
67
- (headerOrVirtualHeader, staticColumnIndex) => {
68
- let header = headerOrVirtualHeader as MRT_Header<TData>;
69
- if (columnVirtualizer) {
70
- staticColumnIndex = (headerOrVirtualHeader as MRT_VirtualItem)
71
- .index;
72
- header = headerGroup.headers[staticColumnIndex];
73
- }
58
+ {virtualPaddingLeft ? <th style={{ display: 'flex', width: virtualPaddingLeft }} /> : null}
59
+ {(virtualColumns ?? headerGroup.headers).map((headerOrVirtualHeader, staticColumnIndex) => {
60
+ let header = headerOrVirtualHeader as MRT_Header<TData>;
61
+ if (columnVirtualizer) {
62
+ staticColumnIndex = (headerOrVirtualHeader as MRT_VirtualItem).index;
63
+ header = headerGroup.headers[staticColumnIndex];
64
+ }
74
65
 
75
- return header ? (
76
- <MRT_TableHeadCell
77
- columnVirtualizer={columnVirtualizer}
78
- header={header}
79
- key={header.id}
80
- staticColumnIndex={staticColumnIndex}
81
- table={table}
82
- />
83
- ) : null;
84
- },
85
- )}
86
- {virtualPaddingRight ? (
87
- <th style={{ display: 'flex', width: virtualPaddingRight }} />
88
- ) : null}
66
+ return header ? (
67
+ <MRT_TableHeadCell
68
+ columnVirtualizer={columnVirtualizer}
69
+ header={header}
70
+ key={header.id}
71
+ staticColumnIndex={staticColumnIndex}
72
+ table={table}
73
+ />
74
+ ) : null;
75
+ })}
76
+ {virtualPaddingRight ? <th style={{ display: 'flex', width: virtualPaddingRight }} /> : null}
89
77
  </TableRow>
90
78
  );
91
79
  };