material-react-table 0.12.2 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/icons.ts CHANGED
@@ -4,9 +4,9 @@ import {
4
4
  CheckBox,
5
5
  ClearAll,
6
6
  Close,
7
+ DensityLarge,
7
8
  DensityMedium,
8
9
  DensitySmall,
9
- KeyboardDoubleArrowDown,
10
10
  DragHandle,
11
11
  DynamicFeed,
12
12
  Edit,
@@ -16,8 +16,9 @@ import {
16
16
  FilterAltOff,
17
17
  FilterList,
18
18
  FilterListOff,
19
- FullscreenExit,
20
19
  Fullscreen,
20
+ FullscreenExit,
21
+ KeyboardDoubleArrowDown,
21
22
  MoreHoriz,
22
23
  MoreVert,
23
24
  PushPin,
@@ -36,6 +37,7 @@ export interface MRT_Icons {
36
37
  CheckBoxIcon: any;
37
38
  ClearAllIcon: any;
38
39
  CloseIcon: any;
40
+ DensityLargeIcon: any;
39
41
  DensityMediumIcon: any;
40
42
  DensitySmallIcon: any;
41
43
  KeyboardDoubleArrowDownIcon: any;
@@ -68,9 +70,9 @@ export const MRT_Default_Icons: MRT_Icons = {
68
70
  CheckBoxIcon: CheckBox,
69
71
  ClearAllIcon: ClearAll,
70
72
  CloseIcon: Close,
73
+ DensityLargeIcon: DensityLarge,
71
74
  DensityMediumIcon: DensityMedium,
72
75
  DensitySmallIcon: DensitySmall,
73
- KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
74
76
  DragHandleIcon: DragHandle,
75
77
  DynamicFeedIcon: DynamicFeed,
76
78
  EditIcon: Edit,
@@ -82,6 +84,7 @@ export const MRT_Default_Icons: MRT_Icons = {
82
84
  FilterListOffIcon: FilterListOff,
83
85
  FullscreenExitIcon: FullscreenExit,
84
86
  FullscreenIcon: Fullscreen,
87
+ KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
85
88
  MoreHorizIcon: MoreHoriz,
86
89
  MoreVertIcon: MoreVert,
87
90
  PushPinIcon: PushPin,
@@ -90,11 +90,13 @@ export const MRT_FilterTextField: FC<Props> = ({
90
90
  column,
91
91
  event,
92
92
  filterValue: event.target.value,
93
+ instance,
93
94
  });
94
95
  columnDef.onColumnFilterValueChangedDebounced?.({
95
96
  column,
96
97
  event,
97
98
  filterValue: event.target.value,
99
+ instance,
98
100
  });
99
101
  }, 200),
100
102
  [],
@@ -107,11 +109,13 @@ export const MRT_FilterTextField: FC<Props> = ({
107
109
  column,
108
110
  event,
109
111
  filterValue: event.target.value,
112
+ instance,
110
113
  });
111
114
  columnDef.onColumnFilterValueChanged?.({
112
115
  column,
113
116
  event,
114
117
  filterValue: event.target.value,
118
+ instance,
115
119
  });
116
120
  };
117
121
 
@@ -11,18 +11,20 @@ interface Props {
11
11
  export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
12
12
  const {
13
13
  getRowModel,
14
+ getPaginationRowModel,
14
15
  getSelectedRowModel,
15
16
  getState,
16
17
  options: {
17
18
  localization,
18
19
  muiSelectCheckboxProps,
20
+ muiSelectAllCheckboxProps,
19
21
  onRowSelectionChanged,
20
22
  onRowSelectAllChanged,
21
23
  selectAllMode,
22
24
  },
23
25
  } = instance;
24
26
 
25
- const { isDensePadding } = getState();
27
+ const { density } = getState();
26
28
 
27
29
  const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
28
30
  if (selectAll) {
@@ -33,7 +35,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
33
35
  }
34
36
  onRowSelectAllChanged?.({
35
37
  event,
36
- selectedRows: event.target.checked ? getRowModel().flatRows : [],
38
+ selectedRows: event.target.checked
39
+ ? selectAllMode === 'all'
40
+ ? getRowModel().flatRows
41
+ : getPaginationRowModel().flatRows
42
+ : [],
37
43
  instance,
38
44
  });
39
45
  } else if (row) {
@@ -51,10 +57,13 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
51
57
  }
52
58
  };
53
59
 
54
- const checkboxProps =
55
- muiSelectCheckboxProps instanceof Function
56
- ? muiSelectCheckboxProps({ isSelectAll: !!selectAll, row, instance })
57
- : muiSelectCheckboxProps;
60
+ const checkboxProps = selectAll
61
+ ? muiSelectAllCheckboxProps instanceof Function
62
+ ? muiSelectAllCheckboxProps({ instance })
63
+ : muiSelectAllCheckboxProps
64
+ : muiSelectCheckboxProps instanceof Function
65
+ ? muiSelectCheckboxProps({ row: row as MRT_Row, instance })
66
+ : muiSelectCheckboxProps;
58
67
 
59
68
  return (
60
69
  <Tooltip
@@ -80,11 +89,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
80
89
  : localization.toggleSelectRow,
81
90
  }}
82
91
  onChange={handleSelectChange}
83
- size={isDensePadding ? 'small' : 'medium'}
92
+ size={density === 'compact' ? 'small' : 'medium'}
84
93
  {...checkboxProps}
85
94
  sx={{
86
- height: isDensePadding ? '1.75rem' : '2.25rem',
87
- width: isDensePadding ? '1.75rem' : '2.25rem',
95
+ height: density === 'compact' ? '1.75rem' : '2.25rem',
96
+ width: density === 'compact' ? '1.75rem' : '2.25rem',
88
97
  ...checkboxProps?.sx,
89
98
  }}
90
99
  />
@@ -56,7 +56,7 @@ export interface MRT_Localization {
56
56
  sortedByColumnDesc: string;
57
57
  thenBy: string;
58
58
  to: string;
59
- toggleDensePadding: string;
59
+ toggleDensity: string;
60
60
  toggleFullScreen: string;
61
61
  toggleSelectAll: string;
62
62
  toggleSelectRow: string;
@@ -125,7 +125,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
125
125
  sortedByColumnDesc: 'Sorted by {column} descending',
126
126
  thenBy: ', then by ',
127
127
  to: 'to',
128
- toggleDensePadding: 'Toggle dense padding',
128
+ toggleDensity: 'Toggle density',
129
129
  toggleFullScreen: 'Toggle full screen',
130
130
  toggleSelectAll: 'Toggle select all',
131
131
  toggleSelectRow: 'Toggle select row',
@@ -62,7 +62,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
62
62
 
63
63
  const { columnDef } = column;
64
64
 
65
- const { columnSizing, columnVisibility, isDensePadding } = getState();
65
+ const { columnSizing, columnVisibility, density } = getState();
66
66
 
67
67
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
68
68
  useState<null | HTMLElement>(null);
@@ -150,7 +150,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
150
150
  open={!!anchorEl}
151
151
  onClose={() => setAnchorEl(null)}
152
152
  MenuListProps={{
153
- dense: isDensePadding,
153
+ dense: density === 'compact',
154
154
  }}
155
155
  >
156
156
  {enableSorting &&
@@ -52,8 +52,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
52
52
  setCurrentGlobalFilterFn,
53
53
  } = instance;
54
54
 
55
- const { isDensePadding, currentFilterFns, currentGlobalFilterFn } =
56
- getState();
55
+ const { density, currentFilterFns, currentGlobalFilterFn } = getState();
57
56
 
58
57
  const { column } = header ?? {};
59
58
 
@@ -178,7 +177,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
178
177
  onClose={() => setAnchorEl(null)}
179
178
  open={!!anchorEl}
180
179
  MenuListProps={{
181
- dense: isDensePadding,
180
+ dense: density === 'compact',
182
181
  }}
183
182
  >
184
183
  {filterOptions.map(({ option, label, divider, fn }, index) => (
@@ -31,7 +31,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
31
31
  },
32
32
  } = instance;
33
33
 
34
- const { isDensePadding } = getState();
34
+ const { density } = getState();
35
35
 
36
36
  return (
37
37
  <Menu
@@ -39,7 +39,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
39
39
  open={!!anchorEl}
40
40
  onClose={() => setAnchorEl(null)}
41
41
  MenuListProps={{
42
- dense: isDensePadding,
42
+ dense: density === 'compact',
43
43
  }}
44
44
  >
45
45
  {enableEditing && (
@@ -30,7 +30,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
30
30
  options: { localization, enablePinning, enableColumnOrdering },
31
31
  } = instance;
32
32
 
33
- const { isDensePadding, columnOrder, columnPinning } = getState();
33
+ const { density, columnOrder, columnPinning } = getState();
34
34
 
35
35
  const hideAllColumns = () => {
36
36
  getAllLeafColumns()
@@ -68,7 +68,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
68
68
  open={!!anchorEl}
69
69
  onClose={() => setAnchorEl(null)}
70
70
  MenuListProps={{
71
- dense: isDensePadding,
71
+ dense: density === 'compact',
72
72
  }}
73
73
  >
74
74
  <Box
@@ -102,8 +102,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
102
102
  const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row<D> | null>(
103
103
  initialState?.currentEditingRow ?? null,
104
104
  );
105
- const [isDensePadding, setIsDensePadding] = useState(
106
- initialState?.isDensePadding ?? false,
105
+ const [density, setDensity] = useState(
106
+ initialState?.density ?? 'comfortable',
107
107
  );
108
108
  const [isFullScreen, setIsFullScreen] = useState(
109
109
  initialState?.isFullScreen ?? false,
@@ -288,7 +288,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
288
288
  currentEditingRow,
289
289
  currentFilterFns,
290
290
  currentGlobalFilterFn,
291
- isDensePadding,
291
+ density,
292
292
  isFullScreen,
293
293
  showFilters,
294
294
  showGlobalFilter,
@@ -302,7 +302,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
302
302
  setCurrentFilterFns: props.onCurrentFilterFnsChange ?? setCurrentFilterFns,
303
303
  setCurrentGlobalFilterFn:
304
304
  props.onCurrentGlobalFilterFnChange ?? setCurrentGlobalFilterFn,
305
- setIsDensePadding: props.onIsDensePaddingChange ?? setIsDensePadding,
305
+ setDensity: props.onDensityChange ?? setDensity,
306
306
  setIsFullScreen: props.onIsFullScreenChange ?? setIsFullScreen,
307
307
  setShowFilters: props.onShowFiltersChange ?? setShowFilters,
308
308
  setShowGlobalFilter: props.onShowGlobalFilterChange ?? setShowGlobalFilter,
@@ -16,7 +16,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
16
16
  const {
17
17
  options: {
18
18
  enableColumnFilters,
19
- enableDensePaddingToggle,
19
+ enableDensityToggle,
20
20
  enableFilters,
21
21
  enableFullScreenToggle,
22
22
  enableGlobalFilter,
@@ -53,7 +53,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
53
53
  <MRT_ToggleFiltersButton instance={instance} />
54
54
  )}
55
55
  {enableHiding && <MRT_ShowHideColumnsButton instance={instance} />}
56
- {enableDensePaddingToggle && (
56
+ {enableDensityToggle && (
57
57
  <MRT_ToggleDensePaddingButton instance={instance} />
58
58
  )}
59
59
  {enableFullScreenToggle && (