material-react-table 2.11.2 → 2.11.3

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.
@@ -7,7 +7,6 @@ import {
7
7
  type MRT_DefinedTableOptions,
8
8
  type MRT_FilterOption,
9
9
  type MRT_RowData,
10
- type MRT_TableInstance,
11
10
  } from '../types';
12
11
 
13
12
  export const getColumnId = <TData extends MRT_RowData>(
@@ -122,50 +121,3 @@ export const getDefaultColumnFilterFn = <TData extends MRT_RowData>(
122
121
  return 'equals';
123
122
  return 'fuzzy';
124
123
  };
125
-
126
- export const getIsFirstColumn = <TData extends MRT_RowData>(
127
- column: MRT_Column<TData>,
128
- table: MRT_TableInstance<TData>,
129
- ) => {
130
- const leftColumns = table.getLeftVisibleLeafColumns();
131
- return leftColumns.length
132
- ? leftColumns[0].id === column.id
133
- : table.getVisibleLeafColumns()[0].id === column.id;
134
- };
135
-
136
- export const getIsLastColumn = <TData extends MRT_RowData>(
137
- column: MRT_Column<TData>,
138
- table: MRT_TableInstance<TData>,
139
- ) => {
140
- const rightColumns = table.getRightVisibleLeafColumns();
141
- const columns = table.getVisibleLeafColumns();
142
- return rightColumns.length
143
- ? rightColumns[rightColumns.length - 1].id === column.id
144
- : columns[columns.length - 1].id === column.id;
145
- };
146
-
147
- export const getIsLastLeftPinnedColumn = <TData extends MRT_RowData>(
148
- table: MRT_TableInstance<TData>,
149
- column: MRT_Column<TData>,
150
- ) => {
151
- return (
152
- column.getIsPinned() === 'left' &&
153
- table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
154
- );
155
- };
156
-
157
- export const getIsFirstRightPinnedColumn = <TData extends MRT_RowData>(
158
- column: MRT_Column<TData>,
159
- ) => {
160
- return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
161
- };
162
-
163
- export const getTotalRight = <TData extends MRT_RowData>(
164
- table: MRT_TableInstance<TData>,
165
- column: MRT_Column<TData>,
166
- ) => {
167
- return table
168
- .getRightLeafHeaders()
169
- .slice(column.getPinnedIndex() + 1)
170
- .reduce((acc, col) => acc + col.getSize(), 0);
171
- };
@@ -243,13 +243,14 @@ export const getMRT_SelectAllHandler =
243
243
  (
244
244
  event: ChangeEvent<HTMLInputElement> | MouseEvent<HTMLButtonElement>,
245
245
  value?: boolean,
246
+ forceAll?: boolean,
246
247
  ) => {
247
248
  const {
248
249
  options: { enableRowPinning, rowPinningDisplayMode, selectAllMode },
249
250
  refs: { lastSelectedRowId },
250
251
  } = table;
251
252
 
252
- selectAllMode === 'all'
253
+ selectAllMode === 'all' || forceAll
253
254
  ? table.toggleAllRowsSelected(value ?? (event as any).target.checked)
254
255
  : table.toggleAllPageRowsSelected(value ?? (event as any).target.checked);
255
256
  if (enableRowPinning && rowPinningDisplayMode?.includes('select')) {
@@ -8,37 +8,34 @@ import {
8
8
  type MRT_Header,
9
9
  type MRT_RowData,
10
10
  type MRT_TableInstance,
11
+ type MRT_TableOptions,
12
+ type MRT_Theme,
11
13
  } from '../types';
12
- import {
13
- getIsFirstRightPinnedColumn,
14
- getIsLastLeftPinnedColumn,
15
- getTotalRight,
16
- } from '../utils/column.utils';
17
14
  import { parseFromValuesOrFunc } from './utils';
18
15
 
19
16
  export const parseCSSVarId = (id: string) => id.replace(/[^a-zA-Z0-9]/g, '_');
20
17
 
21
18
  export const getMRTTheme = <TData extends MRT_RowData>(
22
- table: MRT_TableInstance<TData>,
23
- theme: Theme,
24
- ) => {
25
- const themeOverrides = parseFromValuesOrFunc(table.options.mrtTheme, theme);
19
+ mrtTheme: MRT_TableOptions<TData>['mrtTheme'],
20
+ muiTheme: Theme,
21
+ ): MRT_Theme => {
22
+ const mrtThemeOverrides = parseFromValuesOrFunc(mrtTheme, muiTheme);
26
23
  const baseBackgroundColor =
27
- themeOverrides?.baseBackgroundColor ??
28
- (theme.palette.mode === 'dark'
29
- ? lighten(theme.palette.background.default, 0.05)
30
- : theme.palette.background.default);
24
+ mrtThemeOverrides?.baseBackgroundColor ??
25
+ (muiTheme.palette.mode === 'dark'
26
+ ? lighten(muiTheme.palette.background.default, 0.05)
27
+ : muiTheme.palette.background.default);
31
28
  return {
32
29
  baseBackgroundColor,
33
- draggingBorderColor: theme.palette.primary.main,
30
+ draggingBorderColor: muiTheme.palette.primary.main,
34
31
  matchHighlightColor:
35
- theme.palette.mode === 'dark'
36
- ? darken(theme.palette.warning.dark, 0.25)
37
- : lighten(theme.palette.warning.light, 0.5),
32
+ muiTheme.palette.mode === 'dark'
33
+ ? darken(muiTheme.palette.warning.dark, 0.25)
34
+ : lighten(muiTheme.palette.warning.light, 0.5),
38
35
  menuBackgroundColor: lighten(baseBackgroundColor, 0.07),
39
- pinnedRowBackgroundColor: alpha(theme.palette.primary.main, 0.1),
40
- selectedRowBackgroundColor: alpha(theme.palette.primary.main, 0.2),
41
- ...themeOverrides,
36
+ pinnedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.1),
37
+ selectedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.2),
38
+ ...mrtThemeOverrides,
42
39
  };
43
40
  };
44
41
 
@@ -61,7 +58,9 @@ export const getCommonPinnedCellStyles = <TData extends MRT_RowData>({
61
58
  table: MRT_TableInstance<TData>;
62
59
  theme: Theme;
63
60
  }) => {
64
- const { baseBackgroundColor } = getMRTTheme(table, theme);
61
+ const { baseBackgroundColor } = table.options.mrtTheme;
62
+ const isPinned = column?.getIsPinned();
63
+
65
64
  return {
66
65
  '&[data-pinned="true"]': {
67
66
  '&:before': {
@@ -73,9 +72,9 @@ export const getCommonPinnedCellStyles = <TData extends MRT_RowData>({
73
72
  0.97,
74
73
  ),
75
74
  boxShadow: column
76
- ? getIsLastLeftPinnedColumn(table, column)
75
+ ? isPinned === 'left' && column.getIsLastColumn(isPinned)
77
76
  ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
78
- : getIsFirstRightPinnedColumn(column)
77
+ : isPinned === 'right' && column.getIsFirstColumn(isPinned)
79
78
  ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
80
79
  : undefined
81
80
  : undefined,
@@ -141,7 +140,7 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
141
140
  position: 'sticky',
142
141
  right:
143
142
  isColumnPinned === 'right'
144
- ? `${getTotalRight(table, column)}px`
143
+ ? `${column.getAfter('right')}px`
145
144
  : undefined,
146
145
  }
147
146
  : {};
@@ -179,13 +178,12 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
179
178
 
180
179
  export const getCommonToolbarStyles = <TData extends MRT_RowData>({
181
180
  table,
182
- theme,
183
181
  }: {
184
182
  table: MRT_TableInstance<TData>;
185
183
  theme: Theme;
186
184
  }) => ({
187
185
  alignItems: 'flex-start',
188
- backgroundColor: getMRTTheme(table, theme).baseBackgroundColor,
186
+ backgroundColor: table.options.mrtTheme.baseBackgroundColor,
189
187
  display: 'grid',
190
188
  flexWrap: 'wrap-reverse',
191
189
  minHeight: '3.5rem',