material-react-table 2.0.3 → 2.0.5

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.
@@ -1,7 +1,10 @@
1
1
  import { type PaginationProps } from '@mui/material/Pagination';
2
2
  import { type MRT_RowData, type MRT_TableInstance } from '../types';
3
3
  interface Props<TData extends MRT_RowData> extends Partial<PaginationProps & {
4
- rowsPerPageOptions?: number[];
4
+ rowsPerPageOptions?: {
5
+ label: string;
6
+ value: number;
7
+ }[] | number[];
5
8
  showRowsPerPage?: boolean;
6
9
  }> {
7
10
  position?: 'bottom' | 'top';
@@ -14,6 +14,7 @@ import { type LinearProgressProps } from '@mui/material/LinearProgress';
14
14
  import { type PaginationProps } from '@mui/material/Pagination';
15
15
  import { type PaperProps } from '@mui/material/Paper';
16
16
  import { type RadioProps } from '@mui/material/Radio';
17
+ import { type SelectProps } from '@mui/material/Select';
17
18
  import { type SkeletonProps } from '@mui/material/Skeleton';
18
19
  import { type SliderProps } from '@mui/material/Slider';
19
20
  import { type TableProps } from '@mui/material/Table';
@@ -154,7 +155,7 @@ export interface MRT_RowModel<TData extends MRT_RowData> {
154
155
  [key: string]: MRT_Row<TData>;
155
156
  };
156
157
  }
157
- export type MRT_TableInstance<TData extends MRT_RowData> = Omit<Table<TData>, 'getAllColumns' | 'getAllFlatColumns' | 'getAllLeafColumns' | 'getBottomRows' | 'getCenterLeafColumns' | 'getCenterRows' | 'getColumn' | 'getExpandedRowModel' | 'getFlatHeaders' | 'getHeaderGroups' | 'getLeftLeafColumns' | 'getPaginationRowModel' | 'getPreFilteredRowModel' | 'getPrePaginationRowModel' | 'getRightLeafColumns' | 'getRowModel' | 'getSelectedRowModel' | 'getState' | 'getTopRows' | 'options'> & {
158
+ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<Table<TData>, 'getAllColumns' | 'getAllFlatColumns' | 'getAllLeafColumns' | 'getBottomRows' | 'getCenterLeafColumns' | 'getCenterRows' | 'getColumn' | 'getExpandedRowModel' | 'getFlatHeaders' | 'getHeaderGroups' | 'getLeafHeaders' | 'getLeftLeafColumns' | 'getPaginationRowModel' | 'getPreFilteredRowModel' | 'getPrePaginationRowModel' | 'getRightLeafColumns' | 'getRowModel' | 'getSelectedRowModel' | 'getState' | 'getTopRows' | 'options'> & {
158
159
  getAllColumns: () => MRT_Column<TData>[];
159
160
  getAllFlatColumns: () => MRT_Column<TData>[];
160
161
  getAllLeafColumns: () => MRT_Column<TData>[];
@@ -165,6 +166,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<Table<TData>, 'g
165
166
  getExpandedRowModel: () => MRT_RowModel<TData>;
166
167
  getFlatHeaders: () => MRT_Header<TData>[];
167
168
  getHeaderGroups: () => MRT_HeaderGroup<TData>[];
169
+ getLeafHeaders: () => MRT_Header<TData>[];
168
170
  getLeftLeafColumns: () => MRT_Column<TData>[];
169
171
  getPaginationRowModel: () => MRT_RowModel<TData>;
170
172
  getPreFilteredRowModel: () => MRT_RowModel<TData>;
@@ -640,10 +642,18 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<Partial<TableOpti
640
642
  muiPaginationProps?: ((props: {
641
643
  table: MRT_TableInstance<TData>;
642
644
  }) => Partial<PaginationProps & {
643
- rowsPerPageOptions?: number[];
645
+ SelectProps?: Partial<SelectProps>;
646
+ rowsPerPageOptions?: {
647
+ label: string;
648
+ value: number;
649
+ }[] | number[];
644
650
  showRowsPerPage?: boolean;
645
651
  }>) | Partial<PaginationProps & {
646
- rowsPerPageOptions?: number[];
652
+ SelectProps?: Partial<SelectProps>;
653
+ rowsPerPageOptions?: {
654
+ label: string;
655
+ value: number;
656
+ }[] | number[];
647
657
  showRowsPerPage?: boolean;
648
658
  }>;
649
659
  muiRowDragHandleProps?: ((props: {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.3",
2
+ "version": "2.0.5",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -35,11 +35,11 @@
35
35
  "size-limit": [
36
36
  {
37
37
  "path": "dist/index.js",
38
- "limit": "59 KB"
38
+ "limit": "53 KB"
39
39
  },
40
40
  {
41
41
  "path": "dist/index.esm.js",
42
- "limit": "55 KB"
42
+ "limit": "50 KB"
43
43
  }
44
44
  ],
45
45
  "engines": {
@@ -61,34 +61,34 @@
61
61
  "storybook:dev": "storybook dev -p 6006"
62
62
  },
63
63
  "devDependencies": {
64
- "@babel/core": "^7.23.2",
65
- "@babel/preset-react": "^7.22.15",
64
+ "@babel/core": "^7.23.5",
65
+ "@babel/preset-react": "^7.23.3",
66
66
  "@emotion/react": "^11.11.1",
67
67
  "@emotion/styled": "^11.11.0",
68
- "@faker-js/faker": "^8.2.0",
69
- "@mui/icons-material": "^5.14.16",
70
- "@mui/material": "^5.14.17",
71
- "@mui/x-date-pickers": "^6.18.0",
68
+ "@faker-js/faker": "^8.3.1",
69
+ "@mui/icons-material": "^5.14.19",
70
+ "@mui/material": "^5.14.19",
71
+ "@mui/x-date-pickers": "^6.18.3",
72
72
  "@rollup/plugin-typescript": "^11.1.5",
73
- "@size-limit/preset-small-lib": "^10.0.2",
74
- "@storybook/addon-a11y": "^7.5.3",
75
- "@storybook/addon-essentials": "^7.5.3",
76
- "@storybook/addon-interactions": "^7.5.3",
77
- "@storybook/addon-links": "^7.5.3",
78
- "@storybook/addon-storysource": "^7.5.3",
79
- "@storybook/blocks": "^7.5.3",
80
- "@storybook/react": "^7.5.3",
81
- "@storybook/react-vite": "^7.5.3",
73
+ "@size-limit/preset-small-lib": "^11.0.0",
74
+ "@storybook/addon-a11y": "^7.6.3",
75
+ "@storybook/addon-essentials": "^7.6.3",
76
+ "@storybook/addon-interactions": "^7.6.3",
77
+ "@storybook/addon-links": "^7.6.3",
78
+ "@storybook/addon-storysource": "^7.6.3",
79
+ "@storybook/blocks": "^7.6.3",
80
+ "@storybook/react": "^7.6.3",
81
+ "@storybook/react-vite": "^7.6.3",
82
82
  "@storybook/testing-library": "^0.2.2",
83
- "@types/node": "^20.8.10",
84
- "@types/react": "^18.2.36",
85
- "@types/react-dom": "^18.2.14",
86
- "@typescript-eslint/eslint-plugin": "^6.10.0",
87
- "@typescript-eslint/parser": "^6.10.0",
88
- "@vitejs/plugin-react": "^4.1.1",
89
- "eslint": "^8.53.0",
83
+ "@types/node": "^20.10.3",
84
+ "@types/react": "^18.2.42",
85
+ "@types/react-dom": "^18.2.17",
86
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
87
+ "@typescript-eslint/parser": "^6.13.2",
88
+ "@vitejs/plugin-react": "^4.2.1",
89
+ "eslint": "^8.55.0",
90
90
  "eslint-plugin-mui-path-imports": "^0.0.15",
91
- "eslint-plugin-perfectionist": "^2.2.0",
91
+ "eslint-plugin-perfectionist": "^2.5.0",
92
92
  "prop-types": "^15.8.1",
93
93
  "react": "^18.2.0",
94
94
  "react-dom": "^18.2.0",
@@ -96,12 +96,12 @@
96
96
  "rollup": "^2.79.1",
97
97
  "rollup-plugin-dts": "^6.1.0",
98
98
  "rollup-plugin-peer-deps-external": "^2.2.4",
99
- "size-limit": "^10.0.2",
100
- "storybook": "^7.5.3",
101
- "storybook-dark-mode": "^3.0.1",
99
+ "size-limit": "^11.0.0",
100
+ "storybook": "^7.6.3",
101
+ "storybook-dark-mode": "^3.0.3",
102
102
  "tslib": "^2.6.2",
103
- "typescript": "^5.2.2",
104
- "vite": "^4.5.0"
103
+ "typescript": "^5.3.2",
104
+ "vite": "^5.0.5"
105
105
  },
106
106
  "peerDependencies": {
107
107
  "@emotion/react": ">=11.11",
@@ -115,7 +115,7 @@
115
115
  "dependencies": {
116
116
  "@tanstack/match-sorter-utils": "8.8.4",
117
117
  "@tanstack/react-table": "8.10.7",
118
- "@tanstack/react-virtual": "3.0.0-beta.68",
118
+ "@tanstack/react-virtual": "3.0.1",
119
119
  "highlight-words": "1.2.2"
120
120
  }
121
121
  }
@@ -186,6 +186,15 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
186
186
  ? rowVirtualizer.getVirtualItems()
187
187
  : undefined;
188
188
 
189
+ const commonRowProps = {
190
+ columnVirtualizer,
191
+ numRows: rows.length,
192
+ table,
193
+ virtualColumns,
194
+ virtualPaddingLeft,
195
+ virtualPaddingRight,
196
+ };
197
+
189
198
  return (
190
199
  <>
191
200
  {!rowPinningDisplayMode?.includes('sticky') &&
@@ -202,15 +211,9 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
202
211
  >
203
212
  {getTopRows().map((row, rowIndex) => {
204
213
  const props = {
205
- columnVirtualizer,
206
- measureElement: rowVirtualizer?.measureElement,
207
- numRows: rows.length,
214
+ ...commonRowProps,
208
215
  row,
209
216
  rowIndex,
210
- table,
211
- virtualColumns,
212
- virtualPaddingLeft,
213
- virtualPaddingRight,
214
217
  };
215
218
  return memoMode === 'rows' ? (
216
219
  <Memo_MRT_TableBodyRow key={row.id} {...props} />
@@ -275,24 +278,22 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
275
278
  ? rows[rowOrVirtualRow.index]
276
279
  : (rowOrVirtualRow as MRT_Row<TData>);
277
280
  const props = {
278
- columnVirtualizer,
281
+ ...commonRowProps,
279
282
  measureElement: rowVirtualizer?.measureElement,
280
- numRows: rows.length,
281
283
  pinnedRowIds,
282
284
  row,
283
285
  rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex,
284
- table,
285
- virtualColumns,
286
- virtualPaddingLeft,
287
- virtualPaddingRight,
288
286
  virtualRow: rowVirtualizer
289
287
  ? (rowOrVirtualRow as VirtualItem)
290
288
  : undefined,
291
289
  };
292
290
  return memoMode === 'rows' ? (
293
- <Memo_MRT_TableBodyRow key={row.id} {...props} />
291
+ <Memo_MRT_TableBodyRow
292
+ key={`${row.id}${row.index}`}
293
+ {...props}
294
+ />
294
295
  ) : (
295
- <MRT_TableBodyRow key={row.id} {...props} />
296
+ <MRT_TableBodyRow key={`${row.id}${row.index}`} {...props} />
296
297
  );
297
298
  })}
298
299
  </>
@@ -312,18 +313,12 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
312
313
  >
313
314
  {getBottomRows().map((row, rowIndex) => {
314
315
  const props = {
315
- columnVirtualizer,
316
- measureElement: rowVirtualizer?.measureElement,
317
- numRows: rows.length,
316
+ ...commonRowProps,
318
317
  row,
319
318
  rowIndex,
320
- table,
321
- virtualColumns,
322
- virtualPaddingLeft,
323
- virtualPaddingRight,
324
319
  };
325
320
  return memoMode === 'rows' ? (
326
- <Memo_MRT_TableBodyRow key={row.id} {...props} />
321
+ <Memo_MRT_TableBodyRow key={`${row.id}`} {...props} />
327
322
  ) : (
328
323
  <MRT_TableBodyRow key={row.id} {...props} />
329
324
  );
@@ -60,7 +60,7 @@ export const MRT_TableBodyCellValue = <TData extends MRT_RowData>({
60
60
  allowedTypes.includes(typeof renderedCellValue) &&
61
61
  ((filterValue &&
62
62
  allowedTypes.includes(typeof filterValue) &&
63
- columnDef.filterVariant === 'text') ||
63
+ ['autocomplete', 'text'].includes(columnDef.filterVariant!)) ||
64
64
  (globalFilter &&
65
65
  allowedTypes.includes(typeof globalFilter) &&
66
66
  column.getCanGlobalFilter()))
@@ -37,12 +37,19 @@ export const MRT_TableHeadCellSortLabel = <TData extends MRT_RowData>({
37
37
  isLoading || showSkeletons
38
38
  ? ''
39
39
  : column.getIsSorted()
40
- ? column.getIsSorted() === 'desc'
41
- ? localization.sortedByColumnDesc.replace('{column}', columnDef.header)
42
- : localization.sortedByColumnAsc.replace('{column}', columnDef.header)
43
- : column.getNextSortingOrder() === 'desc'
44
- ? localization.sortByColumnDesc.replace('{column}', columnDef.header)
45
- : localization.sortByColumnAsc.replace('{column}', columnDef.header);
40
+ ? column.getIsSorted() === 'desc'
41
+ ? localization.sortedByColumnDesc.replace(
42
+ '{column}',
43
+ columnDef.header,
44
+ )
45
+ : localization.sortedByColumnAsc.replace('{column}', columnDef.header)
46
+ : column.getNextSortingOrder() === 'desc'
47
+ ? localization.sortByColumnDesc.replace('{column}', columnDef.header)
48
+ : localization.sortByColumnAsc.replace('{column}', columnDef.header);
49
+
50
+ const direction = isSorted
51
+ ? (column.getIsSorted() as 'asc' | 'desc')
52
+ : undefined;
46
53
 
47
54
  return (
48
55
  <Tooltip placement="top" title={sortTooltip}>
@@ -56,6 +63,7 @@ export const MRT_TableHeadCellSortLabel = <TData extends MRT_RowData>({
56
63
  ? (props) => (
57
64
  <SyncAltIcon
58
65
  {...props}
66
+ direction={direction}
59
67
  style={{
60
68
  transform: 'rotate(-90deg) scaleX(0.9) translateX(-1px)',
61
69
  }}
@@ -65,9 +73,7 @@ export const MRT_TableHeadCellSortLabel = <TData extends MRT_RowData>({
65
73
  }
66
74
  active
67
75
  aria-label={sortTooltip}
68
- direction={
69
- isSorted ? (column.getIsSorted() as 'asc' | 'desc') : undefined
70
- }
76
+ direction={direction}
71
77
  onClick={(e) => {
72
78
  e.stopPropagation();
73
79
  header.column.getToggleSortingHandler()?.(e);
@@ -92,6 +92,16 @@ export const MRT_GlobalFilterTextField = <TData extends MRT_RowData>({
92
92
  unmountOnExit
93
93
  >
94
94
  <TextField
95
+ inputProps={{
96
+ autoComplete: 'new-password', // disable autocomplete and autofill
97
+ ...textFieldProps.inputProps,
98
+ }}
99
+ onChange={handleChange}
100
+ placeholder={localization.search}
101
+ size="small"
102
+ value={searchValue ?? ''}
103
+ variant="outlined"
104
+ {...textFieldProps}
95
105
  InputProps={{
96
106
  endAdornment: (
97
107
  <InputAdornment position="end">
@@ -134,16 +144,6 @@ export const MRT_GlobalFilterTextField = <TData extends MRT_RowData>({
134
144
  ) as any),
135
145
  }),
136
146
  }}
137
- inputProps={{
138
- autoComplete: 'new-password', // disable autocomplete and autofill
139
- ...textFieldProps.inputProps,
140
- }}
141
- onChange={handleChange}
142
- placeholder={localization.search}
143
- size="small"
144
- value={searchValue ?? ''}
145
- variant="outlined"
146
- {...textFieldProps}
147
147
  inputRef={(inputRef) => {
148
148
  searchInputRef.current = inputRef;
149
149
  if (textFieldProps?.inputRef) {
@@ -14,7 +14,7 @@ const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
14
14
  interface Props<TData extends MRT_RowData>
15
15
  extends Partial<
16
16
  PaginationProps & {
17
- rowsPerPageOptions?: number[];
17
+ rowsPerPageOptions?: { label: string; value: number }[] | number[];
18
18
  showRowsPerPage?: boolean;
19
19
  }
20
20
  > {
@@ -60,6 +60,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
60
60
  const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
61
61
 
62
62
  const {
63
+ SelectProps,
63
64
  rowsPerPageOptions = defaultRowsPerPage,
64
65
  showFirstButton = showFirstLastPageButtons,
65
66
  showLastButton = showFirstLastPageButtons,
@@ -69,6 +70,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
69
70
 
70
71
  return (
71
72
  <Box
73
+ className="MuiTablePagination-root"
72
74
  sx={{
73
75
  alignItems: 'center',
74
76
  display: 'flex',
@@ -98,16 +100,29 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
98
100
  id="mrt-rows-per-page"
99
101
  inputProps={{ 'aria-label': localization.rowsPerPage }}
100
102
  label={localization.rowsPerPage}
101
- onChange={(event) => setPageSize(+event.target.value)}
103
+ onChange={(event) => setPageSize(+(event.target.value as any))}
102
104
  sx={{ mb: 0 }}
103
105
  value={pageSize}
104
106
  variant="standard"
107
+ {...SelectProps}
105
108
  >
106
- {rowsPerPageOptions.map((value) => (
107
- <MenuItem key={value} sx={{ m: 0 }} value={value}>
108
- {value}
109
- </MenuItem>
110
- ))}
109
+ {rowsPerPageOptions.map((option) => {
110
+ const value = typeof option !== 'number' ? option.value : option;
111
+ const label =
112
+ typeof option !== 'number' ? option.label : `${option}`;
113
+ return (
114
+ SelectProps?.children ??
115
+ (SelectProps?.native ? (
116
+ <option key={value} value={value}>
117
+ {label}
118
+ </option>
119
+ ) : (
120
+ <MenuItem key={value} sx={{ m: 0 }} value={value}>
121
+ {label}
122
+ </MenuItem>
123
+ ))
124
+ );
125
+ })}
111
126
  </Select>
112
127
  </Box>
113
128
  )}
package/src/types.ts CHANGED
@@ -54,6 +54,7 @@ import { type LinearProgressProps } from '@mui/material/LinearProgress';
54
54
  import { type PaginationProps } from '@mui/material/Pagination';
55
55
  import { type PaperProps } from '@mui/material/Paper';
56
56
  import { type RadioProps } from '@mui/material/Radio';
57
+ import { type SelectProps } from '@mui/material/Select';
57
58
  import { type SkeletonProps } from '@mui/material/Skeleton';
58
59
  import { type SliderProps } from '@mui/material/Slider';
59
60
  import { type TableProps } from '@mui/material/Table';
@@ -240,6 +241,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
240
241
  | 'getExpandedRowModel'
241
242
  | 'getFlatHeaders'
242
243
  | 'getHeaderGroups'
244
+ | 'getLeafHeaders'
243
245
  | 'getLeftLeafColumns'
244
246
  | 'getPaginationRowModel'
245
247
  | 'getPreFilteredRowModel'
@@ -261,6 +263,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
261
263
  getExpandedRowModel: () => MRT_RowModel<TData>;
262
264
  getFlatHeaders: () => MRT_Header<TData>[];
263
265
  getHeaderGroups: () => MRT_HeaderGroup<TData>[];
266
+ getLeafHeaders: () => MRT_Header<TData>[];
264
267
  getLeftLeafColumns: () => MRT_Column<TData>[];
265
268
  getPaginationRowModel: () => MRT_RowModel<TData>;
266
269
  getPreFilteredRowModel: () => MRT_RowModel<TData>;
@@ -904,13 +907,15 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
904
907
  muiPaginationProps?:
905
908
  | ((props: { table: MRT_TableInstance<TData> }) => Partial<
906
909
  PaginationProps & {
907
- rowsPerPageOptions?: number[];
910
+ SelectProps?: Partial<SelectProps>;
911
+ rowsPerPageOptions?: { label: string; value: number }[] | number[];
908
912
  showRowsPerPage?: boolean;
909
913
  }
910
914
  >)
911
915
  | Partial<
912
916
  PaginationProps & {
913
- rowsPerPageOptions?: number[];
917
+ SelectProps?: Partial<SelectProps>;
918
+ rowsPerPageOptions?: { label: string; value: number }[] | number[];
914
919
  showRowsPerPage?: boolean;
915
920
  }
916
921
  >;