material-react-table 2.11.2 → 2.12.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 (43) hide show
  1. package/README.md +29 -22
  2. package/dist/index.d.ts +30 -16
  3. package/dist/index.esm.js +161 -152
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +162 -156
  6. package/dist/index.js.map +1 -1
  7. package/package.json +24 -24
  8. package/src/components/body/MRT_TableBodyCell.tsx +11 -6
  9. package/src/components/body/MRT_TableBodyCellValue.tsx +5 -4
  10. package/src/components/body/MRT_TableBodyRow.tsx +10 -7
  11. package/src/components/body/MRT_TableDetailPanel.tsx +4 -9
  12. package/src/components/footer/MRT_TableFooterRow.tsx +6 -3
  13. package/src/components/head/MRT_TableHead.tsx +11 -11
  14. package/src/components/head/MRT_TableHeadCell.tsx +9 -3
  15. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +3 -4
  16. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +61 -37
  17. package/src/components/head/MRT_TableHeadRow.tsx +7 -3
  18. package/src/components/inputs/MRT_FilterRangeFields.tsx +8 -2
  19. package/src/components/inputs/MRT_FilterTextField.tsx +29 -38
  20. package/src/components/inputs/MRT_SelectCheckbox.tsx +2 -1
  21. package/src/components/menus/MRT_CellActionMenu.tsx +1 -5
  22. package/src/components/menus/MRT_ColumnActionMenu.tsx +1 -5
  23. package/src/components/menus/MRT_FilterOptionMenu.tsx +1 -5
  24. package/src/components/menus/MRT_RowActionMenu.tsx +1 -5
  25. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +1 -5
  26. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +3 -2
  27. package/src/components/table/MRT_TableLoadingOverlay.tsx +8 -8
  28. package/src/components/table/MRT_TablePaper.tsx +6 -6
  29. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +3 -1
  30. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +5 -0
  31. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +1 -1
  32. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +1 -1
  33. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +1 -1
  34. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +1 -1
  35. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +1 -1
  36. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +1 -1
  37. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -1
  38. package/src/hooks/useMRT_TableOptions.ts +4 -0
  39. package/src/types.ts +15 -13
  40. package/src/utils/column.utils.ts +78 -40
  41. package/src/utils/row.utils.ts +2 -1
  42. package/src/utils/style.utils.ts +24 -26
  43. package/src/utils/utils.ts +1 -1
@@ -3,7 +3,6 @@ import {
3
3
  type MouseEvent,
4
4
  useCallback,
5
5
  useEffect,
6
- useMemo,
7
6
  useRef,
8
7
  useState,
9
8
  } from 'react';
@@ -35,6 +34,10 @@ import {
35
34
  type MRT_RowData,
36
35
  type MRT_TableInstance,
37
36
  } from '../../types';
37
+ import {
38
+ getColumnFilterInfo,
39
+ useDropdownOptions,
40
+ } from '../../utils/column.utils';
38
41
  import { getValueAndLabel, parseFromValuesOrFunc } from '../../utils/utils';
39
42
  import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
40
43
 
@@ -53,7 +56,6 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
53
56
  }: MRT_FilterTextFieldProps<TData>) => {
54
57
  const {
55
58
  options: {
56
- columnFilterModeOptions,
57
59
  enableColumnFilterModes,
58
60
  icons: { CloseIcon, FilterListIcon },
59
61
  localization,
@@ -112,17 +114,20 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
112
114
  }),
113
115
  };
114
116
 
115
- const isDateFilter =
116
- filterVariant?.startsWith('date') || filterVariant?.startsWith('time');
117
- const isAutocompleteFilter = filterVariant === 'autocomplete';
118
- const isRangeFilter =
119
- filterVariant?.includes('range') || rangeFilterIndex !== undefined;
120
- const isSelectFilter = filterVariant === 'select';
121
- const isMultiSelectFilter = filterVariant === 'multi-select';
122
- const isTextboxFilter =
123
- ['autocomplete', 'text'].includes(filterVariant!) ||
124
- (!isSelectFilter && !isMultiSelectFilter);
125
- const currentFilterOption = columnDef._filterFn;
117
+ const {
118
+ allowedColumnFilterOptions,
119
+ currentFilterOption,
120
+ facetedUniqueValues,
121
+ isAutocompleteFilter,
122
+ isDateFilter,
123
+ isMultiSelectFilter,
124
+ isRangeFilter,
125
+ isSelectFilter,
126
+ isTextboxFilter,
127
+ } = getColumnFilterInfo({ header, table });
128
+
129
+ const dropdownOptions = useDropdownOptions({ header, table });
130
+
126
131
  const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
127
132
  ? //@ts-ignore
128
133
  localization[
@@ -132,6 +137,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
132
137
  }`
133
138
  ]
134
139
  : '';
140
+
135
141
  const filterPlaceholder = !isRangeFilter
136
142
  ? textFieldProps?.placeholder ??
137
143
  localization.filterByColumn?.replace('{column}', String(columnDef.header))
@@ -140,16 +146,14 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
140
146
  : rangeFilterIndex === 1
141
147
  ? localization.max
142
148
  : '';
143
- const allowedColumnFilterOptions =
144
- columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
145
- const showChangeModeButton =
149
+
150
+ const showChangeModeButton = !!(
146
151
  enableColumnFilterModes &&
147
152
  columnDef.enableColumnFilterModes !== false &&
148
153
  !rangeFilterIndex &&
149
154
  (allowedColumnFilterOptions === undefined ||
150
- !!allowedColumnFilterOptions?.length);
151
-
152
- const facetedUniqueValues = column.getFacetedUniqueValues();
155
+ !!allowedColumnFilterOptions?.length)
156
+ );
153
157
 
154
158
  const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
155
159
  const [filterValue, setFilterValue] = useState<string | string[]>(() =>
@@ -257,23 +261,6 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
257
261
  );
258
262
  }
259
263
 
260
- const dropdownOptions = useMemo(
261
- () =>
262
- columnDef.filterSelectOptions ??
263
- ((isSelectFilter || isMultiSelectFilter || isAutocompleteFilter) &&
264
- facetedUniqueValues
265
- ? Array.from(facetedUniqueValues.keys())
266
- .filter((value) => value !== null && value !== undefined)
267
- .sort((a, b) => a.localeCompare(b))
268
- : undefined),
269
- [
270
- columnDef.filterSelectOptions,
271
- facetedUniqueValues,
272
- isMultiSelectFilter,
273
- isSelectFilter,
274
- ],
275
- );
276
-
277
264
  const endAdornment =
278
265
  !isAutocompleteFilter && !isDateFilter && !filterChipLabel ? (
279
266
  <InputAdornment
@@ -447,8 +434,12 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
447
434
  ) : isAutocompleteFilter ? (
448
435
  <Autocomplete
449
436
  freeSolo
450
- getOptionLabel={(option) => getValueAndLabel(option).label}
451
- onChange={(_e, newValue) => handleAutocompleteChange(newValue)}
437
+ getOptionLabel={(option: DropdownOption) =>
438
+ getValueAndLabel(option).label
439
+ }
440
+ onChange={(_e, newValue: DropdownOption) =>
441
+ handleAutocompleteChange(newValue)
442
+ }
452
443
  options={
453
444
  dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
454
445
  }
@@ -58,6 +58,7 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
58
58
  ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
59
59
  : parseFromValuesOrFunc(muiSelectCheckboxProps, {
60
60
  row,
61
+ staticRowIndex,
61
62
  table,
62
63
  })),
63
64
  ...rest,
@@ -87,7 +88,7 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
87
88
  },
88
89
  onChange: (event) => {
89
90
  event.stopPropagation();
90
- row ? onSelectionChange!(event) : onSelectAllChange(event);
91
+ selectAll ? onSelectAllChange(event) : onSelectionChange!(event);
91
92
  },
92
93
  size: (density === 'compact' ? 'small' : 'medium') as 'medium' | 'small',
93
94
  ...checkboxProps,
@@ -1,9 +1,7 @@
1
1
  import Menu, { type MenuProps } from '@mui/material/Menu';
2
- import { useTheme } from '@mui/material/styles';
3
2
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
4
3
  import { type MRT_RowData, type MRT_TableInstance } from '../../types';
5
4
  import { openEditingCell } from '../../utils/cell.utils';
6
- import { getMRTTheme } from '../../utils/style.utils';
7
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
8
6
 
9
7
  export interface MRT_CellActionMenuProps<TData extends MRT_RowData>
@@ -23,6 +21,7 @@ export const MRT_CellActionMenu = <TData extends MRT_RowData>({
23
21
  enableEditing,
24
22
  icons: { ContentCopy, EditIcon },
25
23
  localization,
24
+ mrtTheme: { menuBackgroundColor },
26
25
  renderCellActionMenuItems,
27
26
  },
28
27
  refs: { actionCellRef },
@@ -33,9 +32,6 @@ export const MRT_CellActionMenu = <TData extends MRT_RowData>({
33
32
  const { column } = cell;
34
33
  const { columnDef } = column;
35
34
 
36
- const theme = useTheme();
37
- const { menuBackgroundColor } = getMRTTheme(table, theme);
38
-
39
35
  const handleClose = (event?: any) => {
40
36
  event?.stopPropagation();
41
37
  table.setActionCell(null);
@@ -1,6 +1,5 @@
1
1
  import { type MouseEvent, useState } from 'react';
2
2
  import Menu, { type MenuProps } from '@mui/material/Menu';
3
- import { useTheme } from '@mui/material/styles';
4
3
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
5
4
  import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
6
5
  import {
@@ -8,7 +7,6 @@ import {
8
7
  type MRT_RowData,
9
8
  type MRT_TableInstance,
10
9
  } from '../../types';
11
- import { getMRTTheme } from '../../utils/style.utils';
12
10
 
13
11
  export interface MRT_ColumnActionMenuProps<TData extends MRT_RowData>
14
12
  extends Partial<MenuProps> {
@@ -51,6 +49,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
51
49
  VisibilityOffIcon,
52
50
  },
53
51
  localization,
52
+ mrtTheme: { menuBackgroundColor },
54
53
  renderColumnActionsMenuItems,
55
54
  },
56
55
  refs: { filterInputRefs },
@@ -318,9 +317,6 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
318
317
  : []),
319
318
  ].filter(Boolean);
320
319
 
321
- const theme = useTheme();
322
- const { menuBackgroundColor } = getMRTTheme(table, theme);
323
-
324
320
  return (
325
321
  <Menu
326
322
  MenuListProps={{
@@ -1,6 +1,5 @@
1
1
  import { useMemo } from 'react';
2
2
  import Menu, { type MenuProps } from '@mui/material/Menu';
3
- import { useTheme } from '@mui/material/styles';
4
3
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
5
4
  import {
6
5
  type MRT_FilterOption,
@@ -10,7 +9,6 @@ import {
10
9
  type MRT_RowData,
11
10
  type MRT_TableInstance,
12
11
  } from '../../types';
13
- import { getMRTTheme } from '../../utils/style.utils';
14
12
 
15
13
  export const mrtFilterOptions = (
16
14
  localization: MRT_Localization,
@@ -131,6 +129,7 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
131
129
  columnFilterModeOptions,
132
130
  globalFilterModeOptions,
133
131
  localization,
132
+ mrtTheme: { menuBackgroundColor },
134
133
  renderColumnFilterModeMenuItems,
135
134
  renderGlobalFilterModeMenuItems,
136
135
  },
@@ -239,9 +238,6 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
239
238
  const filterOption =
240
239
  !!header && columnDef ? columnDef._filterFn : globalFilterFn;
241
240
 
242
- const theme = useTheme();
243
- const { menuBackgroundColor } = getMRTTheme(table, theme);
244
-
245
241
  return (
246
242
  <Menu
247
243
  MenuListProps={{
@@ -1,13 +1,11 @@
1
1
  import { type MouseEvent } from 'react';
2
2
  import Menu, { type MenuProps } from '@mui/material/Menu';
3
- import { useTheme } from '@mui/material/styles';
4
3
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
5
4
  import {
6
5
  type MRT_Row,
7
6
  type MRT_RowData,
8
7
  type MRT_TableInstance,
9
8
  } from '../../types';
10
- import { getMRTTheme } from '../../utils/style.utils';
11
9
  import { parseFromValuesOrFunc } from '../../utils/utils';
12
10
 
13
11
  export interface MRT_RowActionMenuProps<TData extends MRT_RowData>
@@ -36,14 +34,12 @@ export const MRT_RowActionMenu = <TData extends MRT_RowData>({
36
34
  enableEditing,
37
35
  icons: { EditIcon },
38
36
  localization,
37
+ mrtTheme: { menuBackgroundColor },
39
38
  renderRowActionMenuItems,
40
39
  },
41
40
  } = table;
42
41
  const { density } = getState();
43
42
 
44
- const theme = useTheme();
45
- const { menuBackgroundColor } = getMRTTheme(table, theme);
46
-
47
43
  return (
48
44
  <Menu
49
45
  MenuListProps={{
@@ -3,7 +3,6 @@ import Box from '@mui/material/Box';
3
3
  import Button from '@mui/material/Button';
4
4
  import Divider from '@mui/material/Divider';
5
5
  import Menu, { type MenuProps } from '@mui/material/Menu';
6
- import { useTheme } from '@mui/material/styles';
7
6
  import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
8
7
  import {
9
8
  type MRT_Column,
@@ -11,7 +10,6 @@ import {
11
10
  type MRT_TableInstance,
12
11
  } from '../../types';
13
12
  import { getDefaultColumnOrderIds } from '../../utils/displayColumn.utils';
14
- import { getMRTTheme } from '../../utils/style.utils';
15
13
 
16
14
  export interface MRT_ShowHideColumnsMenuProps<TData extends MRT_RowData>
17
15
  extends Partial<MenuProps> {
@@ -42,6 +40,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
42
40
  enableColumnPinning,
43
41
  enableHiding,
44
42
  localization,
43
+ mrtTheme: { menuBackgroundColor },
45
44
  },
46
45
  } = table;
47
46
  const { columnOrder, columnPinning, density } = getState();
@@ -84,9 +83,6 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
84
83
  null,
85
84
  );
86
85
 
87
- const theme = useTheme();
88
- const { menuBackgroundColor } = getMRTTheme(table, theme);
89
-
90
86
  return (
91
87
  <Menu
92
88
  MenuListProps={{
@@ -17,7 +17,7 @@ import {
17
17
  type MRT_TableInstance,
18
18
  } from '../../types';
19
19
  import { reorderColumn } from '../../utils/column.utils';
20
- import { getCommonTooltipProps, getMRTTheme } from '../../utils/style.utils';
20
+ import { getCommonTooltipProps } from '../../utils/style.utils';
21
21
  import { parseFromValuesOrFunc } from '../../utils/utils';
22
22
  import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
23
23
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
@@ -48,6 +48,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
48
48
  enableColumnPinning,
49
49
  enableHiding,
50
50
  localization,
51
+ mrtTheme: { draggingBorderColor },
51
52
  },
52
53
  setColumnOrder,
53
54
  } = table;
@@ -116,7 +117,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
116
117
  outline: isDragging
117
118
  ? `2px dashed ${theme.palette.grey[500]}`
118
119
  : hoveredColumn?.id === column.id
119
- ? `2px dashed ${getMRTTheme(table, theme).draggingBorderColor}`
120
+ ? `2px dashed ${draggingBorderColor}`
120
121
  : 'none',
121
122
  outlineOffset: '-2px',
122
123
  pl: `${(column.depth + 0.5) * 2}rem`,
@@ -4,7 +4,6 @@ import CircularProgress, {
4
4
  } from '@mui/material/CircularProgress';
5
5
  import { alpha } from '@mui/material/styles';
6
6
  import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
- import { getMRTTheme } from '../../utils/style.utils';
8
7
  import { parseFromValuesOrFunc } from '../../utils/utils';
9
8
 
10
9
  export interface MRT_TableLoadingOverlayProps<TData extends MRT_RowData>
@@ -17,7 +16,11 @@ export const MRT_TableLoadingOverlay = <TData extends MRT_RowData>({
17
16
  ...rest
18
17
  }: MRT_TableLoadingOverlayProps<TData>) => {
19
18
  const {
20
- options: { localization, muiCircularProgressProps },
19
+ options: {
20
+ localization,
21
+ mrtTheme: { baseBackgroundColor },
22
+ muiCircularProgressProps,
23
+ },
21
24
  } = table;
22
25
 
23
26
  const circularProgressProps = {
@@ -27,12 +30,9 @@ export const MRT_TableLoadingOverlay = <TData extends MRT_RowData>({
27
30
 
28
31
  return (
29
32
  <Box
30
- sx={(theme) => ({
33
+ sx={{
31
34
  alignItems: 'center',
32
- backgroundColor: alpha(
33
- getMRTTheme(table, theme).baseBackgroundColor,
34
- 0.5,
35
- ),
35
+ backgroundColor: alpha(baseBackgroundColor, 0.5),
36
36
  bottom: 0,
37
37
  display: 'flex',
38
38
  justifyContent: 'center',
@@ -43,7 +43,7 @@ export const MRT_TableLoadingOverlay = <TData extends MRT_RowData>({
43
43
  top: 0,
44
44
  width: '100%',
45
45
  zIndex: 3,
46
- })}
46
+ }}
47
47
  >
48
48
  {circularProgressProps?.Component ?? (
49
49
  <CircularProgress
@@ -1,7 +1,6 @@
1
1
  import Paper, { type PaperProps } from '@mui/material/Paper';
2
2
  import { MRT_TableContainer } from './MRT_TableContainer';
3
3
  import { type MRT_RowData, type MRT_TableInstance } from '../../types';
4
- import { getMRTTheme } from '../../utils/style.utils';
5
4
  import { parseFromValuesOrFunc } from '../../utils/utils';
6
5
  import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
7
6
  import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
@@ -20,6 +19,7 @@ export const MRT_TablePaper = <TData extends MRT_RowData>({
20
19
  options: {
21
20
  enableBottomToolbar,
22
21
  enableTopToolbar,
22
+ mrtTheme: { baseBackgroundColor },
23
23
  muiTablePaperProps,
24
24
  renderBottomToolbar,
25
25
  renderTopToolbar,
@@ -48,23 +48,23 @@ export const MRT_TablePaper = <TData extends MRT_RowData>({
48
48
  ...(isFullScreen
49
49
  ? {
50
50
  bottom: 0,
51
- height: '100vh',
51
+ height: '100dvh',
52
52
  left: 0,
53
53
  margin: 0,
54
- maxHeight: '100vh',
55
- maxWidth: '100vw',
54
+ maxHeight: '100dvh',
55
+ maxWidth: '100dvw',
56
56
  padding: 0,
57
57
  position: 'fixed',
58
58
  right: 0,
59
59
  top: 0,
60
- width: '100vw',
60
+ width: '100dvw',
61
61
  zIndex: 999,
62
62
  }
63
63
  : {}),
64
64
  ...paperProps?.style,
65
65
  }}
66
66
  sx={(theme) => ({
67
- backgroundColor: getMRTTheme(table, theme).baseBackgroundColor,
67
+ backgroundColor: baseBackgroundColor,
68
68
  backgroundImage: 'unset',
69
69
  overflow: 'hidden',
70
70
  transition: 'all 100ms ease-in-out',
@@ -68,7 +68,9 @@ export const MRT_ToolbarAlertBanner = <TData extends MRT_RowData>({
68
68
  ?.replace('{selectedCount}', selectedRowCount.toLocaleString())
69
69
  ?.replace('{rowCount}', totalRowCount.toString())}
70
70
  <Button
71
- onClick={(event) => getMRT_SelectAllHandler({ table })(event, false)}
71
+ onClick={(event) =>
72
+ getMRT_SelectAllHandler({ table })(event, false, true)
73
+ }
72
74
  size="small"
73
75
  sx={{ p: '2px' }}
74
76
  >
@@ -29,6 +29,10 @@ export const MRT_ToolbarDropZone = <TData extends MRT_RowData>({
29
29
  setHoveredColumn({ id: 'drop-zone' });
30
30
  };
31
31
 
32
+ const handleDragOver = (e: DragEvent) => {
33
+ e.preventDefault();
34
+ };
35
+
32
36
  useEffect(() => {
33
37
  if (table.options.state?.showToolbarDropZone !== undefined) {
34
38
  setShowToolbarDropZone(
@@ -45,6 +49,7 @@ export const MRT_ToolbarDropZone = <TData extends MRT_RowData>({
45
49
  <Box
46
50
  className="Mui-ToolbarDropZone"
47
51
  onDragEnter={handleDragEnter}
52
+ onDragOver={handleDragOver}
48
53
  {...rest}
49
54
  sx={(theme) => ({
50
55
  alignItems: 'center',
@@ -8,7 +8,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
8
 
9
9
  export const getMRT_RowActionsColumnDef = <TData extends MRT_RowData>(
10
10
  tableOptions: MRT_StatefulTableOptions<TData>,
11
- ): MRT_ColumnDef<TData> | null => {
11
+ ): MRT_ColumnDef<TData> => {
12
12
  return {
13
13
  Cell: ({ cell, row, staticRowIndex, table }) => (
14
14
  <MRT_ToggleRowActionMenuButton
@@ -9,7 +9,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
9
9
 
10
10
  export const getMRT_RowDragColumnDef = <TData extends MRT_RowData>(
11
11
  tableOptions: MRT_StatefulTableOptions<TData>,
12
- ): MRT_ColumnDef<TData> | null => {
12
+ ): MRT_ColumnDef<TData> => {
13
13
  return {
14
14
  Cell: ({ row, rowRef, table }) => (
15
15
  <MRT_TableBodyRowGrabHandle
@@ -13,7 +13,7 @@ import { getCommonTooltipProps } from '../../utils/style.utils';
13
13
 
14
14
  export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
15
15
  tableOptions: MRT_StatefulTableOptions<TData>,
16
- ): MRT_ColumnDef<TData> | null => {
16
+ ): MRT_ColumnDef<TData> => {
17
17
  const {
18
18
  defaultColumn,
19
19
  enableExpandAll,
@@ -7,7 +7,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
7
7
 
8
8
  export const getMRT_RowNumbersColumnDef = <TData extends MRT_RowData>(
9
9
  tableOptions: MRT_StatefulTableOptions<TData>,
10
- ): MRT_ColumnDef<TData> | null => {
10
+ ): MRT_ColumnDef<TData> => {
11
11
  const { localization, rowNumberDisplayMode } = tableOptions;
12
12
  const {
13
13
  pagination: { pageIndex, pageSize },
@@ -8,7 +8,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
8
 
9
9
  export const getMRT_RowPinningColumnDef = <TData extends MRT_RowData>(
10
10
  tableOptions: MRT_StatefulTableOptions<TData>,
11
- ): MRT_ColumnDef<TData> | null => {
11
+ ): MRT_ColumnDef<TData> => {
12
12
  return {
13
13
  Cell: ({ row, table }) => (
14
14
  <MRT_TableBodyRowPinButton row={row} table={table} />
@@ -8,7 +8,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
8
 
9
9
  export const getMRT_RowSelectColumnDef = <TData extends MRT_RowData>(
10
10
  tableOptions: MRT_StatefulTableOptions<TData>,
11
- ): MRT_ColumnDef<TData> | null => {
11
+ ): MRT_ColumnDef<TData> => {
12
12
  const { enableMultiRowSelection, enableSelectAll } = tableOptions;
13
13
 
14
14
  return {
@@ -17,7 +17,7 @@ const blankColProps = {
17
17
 
18
18
  export const getMRT_RowSpacerColumnDef = <TData extends MRT_RowData>(
19
19
  tableOptions: MRT_StatefulTableOptions<TData>,
20
- ): MRT_ColumnDef<TData> | null => {
20
+ ): MRT_ColumnDef<TData> => {
21
21
  return {
22
22
  ...defaultDisplayColumnProps({
23
23
  id: 'mrt-row-spacer',
@@ -21,6 +21,7 @@ import {
21
21
  type MRT_RowData,
22
22
  type MRT_TableOptions,
23
23
  } from '../types';
24
+ import { getMRTTheme } from '../utils/style.utils';
24
25
 
25
26
  export const MRT_DefaultColumn = {
26
27
  filterVariant: 'text',
@@ -96,6 +97,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
96
97
  manualGrouping,
97
98
  manualPagination,
98
99
  manualSorting,
100
+ mrtTheme,
99
101
  paginationDisplayMode = 'default',
100
102
  positionActionsColumn = 'first',
101
103
  positionCreatingRow = 'top',
@@ -120,6 +122,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
120
122
  }),
121
123
  [localization],
122
124
  );
125
+ mrtTheme = useMemo(() => getMRTTheme(mrtTheme, theme), [mrtTheme, theme]);
123
126
  aggregationFns = useMemo(
124
127
  () => ({ ...MRT_AggregationFns, ...aggregationFns }),
125
128
  [],
@@ -241,6 +244,7 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
241
244
  manualGrouping,
242
245
  manualPagination,
243
246
  manualSorting,
247
+ mrtTheme,
244
248
  paginationDisplayMode,
245
249
  positionActionsColumn,
246
250
  positionCreatingRow,
package/src/types.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- type CSSProperties,
3
2
  type Dispatch,
4
3
  type MutableRefObject,
5
4
  type ReactNode,
@@ -257,12 +256,12 @@ export interface MRT_Localization {
257
256
  }
258
257
 
259
258
  export interface MRT_Theme {
260
- baseBackgroundColor?: CSSProperties['backgroundColor'];
261
- draggingBorderColor?: CSSProperties['borderColor'];
262
- matchHighlightColor?: CSSProperties['backgroundColor'];
263
- menuBackgroundColor?: CSSProperties['backgroundColor'];
264
- pinnedRowBackgroundColor?: CSSProperties['backgroundColor'];
265
- selectedRowBackgroundColor?: CSSProperties['backgroundColor'];
259
+ baseBackgroundColor: string;
260
+ draggingBorderColor: string;
261
+ matchHighlightColor: string;
262
+ menuBackgroundColor: string;
263
+ pinnedRowBackgroundColor: string;
264
+ selectedRowBackgroundColor: string;
266
265
  }
267
266
 
268
267
  export interface MRT_RowModel<TData extends MRT_RowData> {
@@ -348,11 +347,14 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
348
347
  setShowToolbarDropZone: Dispatch<SetStateAction<boolean>>;
349
348
  };
350
349
 
351
- export type MRT_DefinedTableOptions<TData extends MRT_RowData> =
352
- MRT_TableOptions<TData> & {
353
- icons: MRT_Icons;
354
- localization: MRT_Localization;
355
- };
350
+ export type MRT_DefinedTableOptions<TData extends MRT_RowData> = Omit<
351
+ MRT_TableOptions<TData>,
352
+ 'icons' | 'localization' | 'mrtTheme'
353
+ > & {
354
+ icons: MRT_Icons;
355
+ localization: MRT_Localization;
356
+ mrtTheme: Required<MRT_Theme>;
357
+ };
356
358
 
357
359
  export type MRT_StatefulTableOptions<TData extends MRT_RowData> =
358
360
  MRT_DefinedTableOptions<TData> & {
@@ -914,7 +916,7 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
914
916
  * @link https://www.material-react-table.com/docs/guides/memoize-components
915
917
  */
916
918
  memoMode?: 'cells' | 'rows' | 'table-body';
917
- mrtTheme?: ((theme: Theme) => MRT_Theme) | MRT_Theme;
919
+ mrtTheme?: ((theme: Theme) => Partial<MRT_Theme>) | Partial<MRT_Theme>;
918
920
  muiBottomToolbarProps?:
919
921
  | ((props: { table: MRT_TableInstance<TData> }) => BoxProps)
920
922
  | BoxProps;