material-react-table 2.0.3 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ import { LinearProgressProps } from '@mui/material/LinearProgress';
18
18
  import { PaginationProps } from '@mui/material/Pagination';
19
19
  import { PaperProps } from '@mui/material/Paper';
20
20
  import { RadioProps } from '@mui/material/Radio';
21
+ import { SelectProps } from '@mui/material/Select';
21
22
  import { SkeletonProps } from '@mui/material/Skeleton';
22
23
  import { SliderProps } from '@mui/material/Slider';
23
24
  import { TableProps } from '@mui/material/Table';
@@ -287,7 +288,7 @@ interface MRT_RowModel<TData extends MRT_RowData> {
287
288
  [key: string]: MRT_Row<TData>;
288
289
  };
289
290
  }
290
- 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'> & {
291
+ 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'> & {
291
292
  getAllColumns: () => MRT_Column<TData>[];
292
293
  getAllFlatColumns: () => MRT_Column<TData>[];
293
294
  getAllLeafColumns: () => MRT_Column<TData>[];
@@ -298,6 +299,7 @@ type MRT_TableInstance<TData extends MRT_RowData> = Omit<Table<TData>, 'getAllCo
298
299
  getExpandedRowModel: () => MRT_RowModel<TData>;
299
300
  getFlatHeaders: () => MRT_Header<TData>[];
300
301
  getHeaderGroups: () => MRT_HeaderGroup<TData>[];
302
+ getLeafHeaders: () => MRT_Header<TData>[];
301
303
  getLeftLeafColumns: () => MRT_Column<TData>[];
302
304
  getPaginationRowModel: () => MRT_RowModel<TData>;
303
305
  getPreFilteredRowModel: () => MRT_RowModel<TData>;
@@ -773,10 +775,18 @@ type MRT_TableOptions<TData extends MRT_RowData> = Omit<Partial<TableOptions<TDa
773
775
  muiPaginationProps?: ((props: {
774
776
  table: MRT_TableInstance<TData>;
775
777
  }) => Partial<PaginationProps & {
776
- rowsPerPageOptions?: number[];
778
+ SelectProps?: Partial<SelectProps>;
779
+ rowsPerPageOptions?: {
780
+ label: string;
781
+ value: number;
782
+ }[] | number[];
777
783
  showRowsPerPage?: boolean;
778
784
  }>) | Partial<PaginationProps & {
779
- rowsPerPageOptions?: number[];
785
+ SelectProps?: Partial<SelectProps>;
786
+ rowsPerPageOptions?: {
787
+ label: string;
788
+ value: number;
789
+ }[] | number[];
780
790
  showRowsPerPage?: boolean;
781
791
  }>;
782
792
  muiRowDragHandleProps?: ((props: {
@@ -1530,7 +1540,10 @@ interface Props$5<TData extends MRT_RowData> extends LinearProgressProps {
1530
1540
  declare const MRT_LinearProgressBar: <TData extends MRT_RowData>({ isTopToolbar, table, ...rest }: Props$5<TData>) => react_jsx_runtime.JSX.Element;
1531
1541
 
1532
1542
  interface Props$4<TData extends MRT_RowData> extends Partial<PaginationProps & {
1533
- rowsPerPageOptions?: number[];
1543
+ rowsPerPageOptions?: {
1544
+ label: string;
1545
+ value: number;
1546
+ }[] | number[];
1534
1547
  showRowsPerPage?: boolean;
1535
1548
  }> {
1536
1549
  position?: 'bottom' | 'top';
package/dist/index.esm.js CHANGED
@@ -428,7 +428,7 @@ const MRT_TableBodyCellValue = ({ cell, table, }) => {
428
428
  allowedTypes.includes(typeof renderedCellValue) &&
429
429
  ((filterValue &&
430
430
  allowedTypes.includes(typeof filterValue) &&
431
- columnDef.filterVariant === 'text') ||
431
+ ['autocomplete', 'text'].includes(columnDef.filterVariant)) ||
432
432
  (globalFilter &&
433
433
  allowedTypes.includes(typeof globalFilter) &&
434
434
  column.getCanGlobalFilter()))) {
@@ -987,19 +987,18 @@ const MRT_TableBody = (_a) => {
987
987
  const virtualRows = rowVirtualizer
988
988
  ? rowVirtualizer.getVirtualItems()
989
989
  : undefined;
990
+ const commonRowProps = {
991
+ columnVirtualizer,
992
+ numRows: rows.length,
993
+ table,
994
+ virtualColumns,
995
+ virtualPaddingLeft,
996
+ virtualPaddingRight,
997
+ };
990
998
  return (jsxs(Fragment, { children: [!(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
991
999
  getIsSomeRowsPinned('top') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', top: tableHeadHeight - 1, zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getTopRows().map((row, rowIndex) => {
992
- const props = {
993
- columnVirtualizer,
994
- measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
995
- numRows: rows.length,
996
- row,
997
- rowIndex,
998
- table,
999
- virtualColumns,
1000
- virtualPaddingLeft,
1001
- virtualPaddingRight,
1002
- };
1000
+ const props = Object.assign(Object.assign({}, commonRowProps), { row,
1001
+ rowIndex });
1003
1002
  return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1004
1003
  }) }))), jsxs(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, height: rowVirtualizer
1005
1004
  ? `${rowVirtualizer.getTotalSize()}px`
@@ -1020,36 +1019,16 @@ const MRT_TableBody = (_a) => {
1020
1019
  const row = rowVirtualizer
1021
1020
  ? rows[rowOrVirtualRow.index]
1022
1021
  : rowOrVirtualRow;
1023
- const props = {
1024
- columnVirtualizer,
1025
- measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
1026
- numRows: rows.length,
1027
- pinnedRowIds,
1028
- row,
1029
- rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex,
1030
- table,
1031
- virtualColumns,
1032
- virtualPaddingLeft,
1033
- virtualPaddingRight,
1034
- virtualRow: rowVirtualizer
1022
+ const props = Object.assign(Object.assign({}, commonRowProps), { measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement, pinnedRowIds,
1023
+ row, rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex, virtualRow: rowVirtualizer
1035
1024
  ? rowOrVirtualRow
1036
- : undefined,
1037
- };
1038
- return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1025
+ : undefined });
1026
+ return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), `${row.id}${row.index}`)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), `${row.id}${row.index}`));
1039
1027
  }) })))] })), !(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
1040
1028
  getIsSomeRowsPinned('bottom') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ bottom: tableFooterHeight - 1, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getBottomRows().map((row, rowIndex) => {
1041
- const props = {
1042
- columnVirtualizer,
1043
- measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
1044
- numRows: rows.length,
1045
- row,
1046
- rowIndex,
1047
- table,
1048
- virtualColumns,
1049
- virtualPaddingLeft,
1050
- virtualPaddingRight,
1051
- };
1052
- return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1029
+ const props = Object.assign(Object.assign({}, commonRowProps), { row,
1030
+ rowIndex });
1031
+ return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), `${row.id}`)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1053
1032
  }) })))] }));
1054
1033
  };
1055
1034
  const Memo_MRT_TableBody = memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
@@ -1670,7 +1649,7 @@ const MRT_FilterTextField = (_a) => {
1670
1649
  localization[`filter${((_l = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _l === void 0 ? void 0 : _l.toUpperCase()) +
1671
1650
  (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]) })) : null, inputProps: {
1672
1651
  'aria-label': filterPlaceholder,
1673
- autoComplete: 'new-password',
1652
+ autoComplete: 'new-password', // disable autocomplete and autofill
1674
1653
  disabled: !!filterChipLabel,
1675
1654
  sx: {
1676
1655
  textOverflow: 'ellipsis',
@@ -1952,11 +1931,14 @@ const MRT_TableHeadCellSortLabel = (_a) => {
1952
1931
  : column.getNextSortingOrder() === 'desc'
1953
1932
  ? localization.sortByColumnDesc.replace('{column}', columnDef.header)
1954
1933
  : localization.sortByColumnAsc.replace('{column}', columnDef.header);
1934
+ const direction = isSorted
1935
+ ? column.getIsSorted()
1936
+ : undefined;
1955
1937
  return (jsx(Tooltip, { placement: "top", title: sortTooltip, children: jsx(Badge, { badgeContent: sorting.length > 1 ? column.getSortIndex() + 1 : 0, overlap: "circular", children: jsx(TableSortLabel, Object.assign({ IconComponent: !isSorted
1956
- ? (props) => (jsx(SyncAltIcon, Object.assign({}, props, { style: {
1938
+ ? (props) => (jsx(SyncAltIcon, Object.assign({}, props, { direction: direction, style: {
1957
1939
  transform: 'rotate(-90deg) scaleX(0.9) translateX(-1px)',
1958
1940
  } })))
1959
- : ArrowDownwardIcon, active: true, "aria-label": sortTooltip, direction: isSorted ? column.getIsSorted() : undefined, onClick: (e) => {
1941
+ : ArrowDownwardIcon, active: true, "aria-label": sortTooltip, direction: direction, onClick: (e) => {
1960
1942
  var _a;
1961
1943
  e.stopPropagation();
1962
1944
  (_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(e);
@@ -2154,8 +2136,8 @@ const MRT_TablePagination = (_a) => {
2154
2136
  const showFirstLastPageButtons = numberOfPages > 2;
2155
2137
  const firstRowIndex = pageIndex * pageSize;
2156
2138
  const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
2157
- const _b = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true } = _b, _rest = __rest(_b, ["rowsPerPageOptions", "showFirstButton", "showLastButton", "showRowsPerPage"]);
2158
- return (jsxs(Box, { sx: {
2139
+ const _b = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { SelectProps, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true } = _b, _rest = __rest(_b, ["SelectProps", "rowsPerPageOptions", "showFirstButton", "showLastButton", "showRowsPerPage"]);
2140
+ return (jsxs(Box, { className: "MuiTablePagination-root", sx: {
2159
2141
  alignItems: 'center',
2160
2142
  display: 'flex',
2161
2143
  flexWrap: 'wrap',
@@ -2171,7 +2153,12 @@ const MRT_TablePagination = (_a) => {
2171
2153
  px: '8px',
2172
2154
  py: '12px',
2173
2155
  zIndex: 2,
2174
- }, children: [showRowsPerPage && (jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsx(InputLabel, { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsx(Select, { disableUnderline: true, id: "mrt-rows-per-page", inputProps: { 'aria-label': localization.rowsPerPage }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard", children: rowsPerPageOptions.map((value) => (jsx(MenuItem, { sx: { m: 0 }, value: value, children: value }, value))) })] })), paginationDisplayMode === 'pages' ? (jsx(Pagination, Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsx(PaginationItem, Object.assign({ slots: {
2156
+ }, children: [showRowsPerPage && (jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsx(InputLabel, { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsx(Select, Object.assign({ disableUnderline: true, id: "mrt-rows-per-page", inputProps: { 'aria-label': localization.rowsPerPage }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard" }, SelectProps, { children: rowsPerPageOptions.map((option) => {
2157
+ var _a;
2158
+ const value = typeof option !== 'number' ? option.value : option;
2159
+ const label = typeof option !== 'number' ? option.label : `${option}`;
2160
+ return ((_a = SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.children) !== null && _a !== void 0 ? _a : ((SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.native) ? (jsx("option", { value: value, children: label }, value)) : (jsx(MenuItem, { sx: { m: 0 }, value: value, children: label }, value))));
2161
+ }) }))] })), paginationDisplayMode === 'pages' ? (jsx(Pagination, Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsx(PaginationItem, Object.assign({ slots: {
2175
2162
  first: FirstPageIcon,
2176
2163
  last: LastPageIcon,
2177
2164
  next: ChevronRightIcon,
@@ -2216,10 +2203,10 @@ const MRT_GlobalFilterTextField = (_a) => {
2216
2203
  }
2217
2204
  isMounted.current = true;
2218
2205
  }, [globalFilter]);
2219
- return (jsxs(Collapse, { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsx(TextField, Object.assign({ InputProps: Object.assign(Object.assign({ endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { title: (_b = localization.clearSearch) !== null && _b !== void 0 ? _b : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsx(CloseIcon, {}) }) }) }) })), startAdornment: enableGlobalFilterModes ? (jsx(InputAdornment, { position: "start", children: jsx(Tooltip, { title: localization.changeSearchMode, children: jsx(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(SearchIcon, {}) }) }) })) : (jsx(SearchIcon, { style: { marginRight: '4px' } })) }, textFieldProps.InputProps), { sx: (theme) => {
2206
+ return (jsxs(Collapse, { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsx(TextField, Object.assign({ inputProps: Object.assign({ autoComplete: 'new-password' }, textFieldProps.inputProps), onChange: handleChange, placeholder: localization.search, size: "small", value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "outlined" }, textFieldProps, { InputProps: Object.assign(Object.assign({ endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { title: (_b = localization.clearSearch) !== null && _b !== void 0 ? _b : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsx(CloseIcon, {}) }) }) }) })), startAdornment: enableGlobalFilterModes ? (jsx(InputAdornment, { position: "start", children: jsx(Tooltip, { title: localization.changeSearchMode, children: jsx(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(SearchIcon, {}) }) }) })) : (jsx(SearchIcon, { style: { marginRight: '4px' } })) }, textFieldProps.InputProps), { sx: (theme) => {
2220
2207
  var _a;
2221
2208
  return (Object.assign({ mb: 0 }, parseFromValuesOrFunc((_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.InputProps) === null || _a === void 0 ? void 0 : _a.sx, theme)));
2222
- } }), inputProps: Object.assign({ autoComplete: 'new-password' }, textFieldProps.inputProps), onChange: handleChange, placeholder: localization.search, size: "small", value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "outlined" }, textFieldProps, { inputRef: (inputRef) => {
2209
+ } }), inputRef: (inputRef) => {
2223
2210
  searchInputRef.current = inputRef;
2224
2211
  if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.inputRef) {
2225
2212
  textFieldProps.inputRef = inputRef;