material-react-table 1.13.1 → 1.15.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.
- package/README.md +2 -1
- package/dist/cjs/index.js +96 -66
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/_locales/no.d.ts +2 -0
- package/dist/cjs/types/column.utils.d.ts +4 -4
- package/dist/cjs/types/sortingFns.d.ts +1 -418
- package/dist/cjs/types/types.d.ts +5 -3
- package/dist/esm/material-react-table.esm.js +93 -65
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/_locales/no.d.ts +2 -0
- package/dist/esm/types/column.utils.d.ts +4 -4
- package/dist/esm/types/sortingFns.d.ts +1 -418
- package/dist/esm/types/types.d.ts +5 -3
- package/dist/index.d.ts +16 -14
- package/locales/no.d.ts +2 -0
- package/locales/no.esm.d.ts +2 -0
- package/locales/no.esm.js +94 -0
- package/locales/no.esm.js.map +1 -0
- package/locales/no.js +98 -0
- package/locales/no.js.map +1 -0
- package/locales/sv.esm.js +2 -2
- package/locales/sv.esm.js.map +1 -1
- package/locales/sv.js +2 -2
- package/locales/sv.js.map +1 -1
- package/package.json +35 -35
- package/src/_locales/no.ts +94 -0
- package/src/_locales/sv.ts +2 -2
- package/src/body/MRT_TableBodyCell.tsx +1 -1
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +1 -1
- package/src/inputs/MRT_FilterRangeSlider.tsx +21 -20
- package/src/inputs/MRT_FilterTextField.tsx +1 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +139 -125
- package/src/sortingFns.ts +1 -5
- package/src/types.ts +376 -376
@@ -65,7 +65,9 @@ import Table from '@mui/material/Table';
|
|
65
65
|
import TableHead from '@mui/material/TableHead';
|
66
66
|
import TableRow from '@mui/material/TableRow';
|
67
67
|
import TableCell from '@mui/material/TableCell';
|
68
|
-
import
|
68
|
+
import Slider from '@mui/material/Slider';
|
69
|
+
import Stack from '@mui/material/Stack';
|
70
|
+
import FormHelperText from '@mui/material/FormHelperText';
|
69
71
|
import Badge from '@mui/material/Badge';
|
70
72
|
import TableSortLabel from '@mui/material/TableSortLabel';
|
71
73
|
import TableBody from '@mui/material/TableBody';
|
@@ -75,7 +77,6 @@ import TableFooter from '@mui/material/TableFooter';
|
|
75
77
|
import DialogActions from '@mui/material/DialogActions';
|
76
78
|
import DialogContent from '@mui/material/DialogContent';
|
77
79
|
import DialogTitle from '@mui/material/DialogTitle';
|
78
|
-
import Stack$1 from '@mui/material/Stack';
|
79
80
|
|
80
81
|
/******************************************************************************
|
81
82
|
Copyright (c) Microsoft Corporation.
|
@@ -99,6 +100,10 @@ function __rest(s, e) {
|
|
99
100
|
}
|
100
101
|
return t;
|
101
102
|
}
|
103
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
104
|
+
var e = new Error(message);
|
105
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
106
|
+
};
|
102
107
|
|
103
108
|
const MRT_AggregationFns = Object.assign({}, aggregationFns);
|
104
109
|
|
@@ -784,6 +789,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
784
789
|
const { column } = header;
|
785
790
|
const { columnDef } = column;
|
786
791
|
const { columnSizing, columnVisibility, density, showColumnFilters } = getState();
|
792
|
+
const columnFilterValue = column.getFilterValue();
|
787
793
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] = useState(null);
|
788
794
|
const handleClearSort = () => {
|
789
795
|
column.clearSorting();
|
@@ -839,46 +845,63 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
839
845
|
!isSelectFilter &&
|
840
846
|
(allowedColumnFilterOptions === undefined ||
|
841
847
|
!!(allowedColumnFilterOptions === null || allowedColumnFilterOptions === void 0 ? void 0 : allowedColumnFilterOptions.length));
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
column,
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
jsx(MenuItem, {
|
869
|
-
|
870
|
-
column.
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
column.
|
876
|
-
|
877
|
-
],
|
878
|
-
|
848
|
+
const internalColumnMenuItems = [
|
849
|
+
...(enableSorting && column.getCanSort()
|
850
|
+
? [
|
851
|
+
enableSortingRemoval !== false && (jsx(MenuItem, { disabled: !column.getIsSorted(), onClick: handleClearSort, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(ClearAllIcon, {}) }), localization.clearSort] }) }, 0)),
|
852
|
+
jsx(MenuItem, { disabled: column.getIsSorted() === 'asc', onClick: handleSortAsc, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(SortIcon, { style: { transform: 'rotate(180deg) scaleX(-1)' } }) }), (_b = localization.sortByColumnAsc) === null || _b === void 0 ? void 0 : _b.replace('{column}', String(columnDef.header))] }) }, 1),
|
853
|
+
jsx(MenuItem, { divider: enableColumnFilters || enableGrouping || enableHiding, disabled: column.getIsSorted() === 'desc', onClick: handleSortDesc, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(SortIcon, {}) }), (_c = localization.sortByColumnDesc) === null || _c === void 0 ? void 0 : _c.replace('{column}', String(columnDef.header))] }) }, 2),
|
854
|
+
]
|
855
|
+
: []),
|
856
|
+
...(enableColumnFilters && column.getCanFilter()
|
857
|
+
? [
|
858
|
+
jsx(MenuItem, { disabled: !columnFilterValue ||
|
859
|
+
(Array.isArray(columnFilterValue) &&
|
860
|
+
!columnFilterValue.filter((value) => value).length), onClick: handleClearFilter, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(FilterListOffIcon, {}) }), localization.clearFilter] }) }, 3),
|
861
|
+
jsxs(MenuItem, { disabled: showColumnFilters && !enableColumnFilterModes, divider: enableGrouping || enableHiding, onClick: showColumnFilters
|
862
|
+
? handleOpenFilterModeMenu
|
863
|
+
: handleFilterByColumn, sx: commonMenuItemStyles, children: [jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(FilterListIcon, {}) }), (_d = localization.filterByColumn) === null || _d === void 0 ? void 0 : _d.replace('{column}', String(columnDef.header))] }), showFilterModeSubMenu && (jsx(IconButton, { onClick: handleOpenFilterModeMenu, onMouseEnter: handleOpenFilterModeMenu, size: "small", sx: { p: 0 }, children: jsx(ArrowRightIcon, {}) }))] }, 4),
|
864
|
+
showFilterModeSubMenu && (jsx(MRT_FilterOptionMenu, { anchorEl: filterMenuAnchorEl, header: header, onSelect: handleFilterByColumn, setAnchorEl: setFilterMenuAnchorEl, table: table }, 5)),
|
865
|
+
]
|
866
|
+
: []),
|
867
|
+
...(enableGrouping && column.getCanGroup()
|
868
|
+
? [
|
869
|
+
jsx(MenuItem, { divider: enablePinning, onClick: handleGroupByColumn, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(DynamicFeedIcon, {}) }), (_e = localization[column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn']) === null || _e === void 0 ? void 0 : _e.replace('{column}', String(columnDef.header))] }) }, 6),
|
870
|
+
]
|
871
|
+
: []),
|
872
|
+
...(enablePinning && column.getCanPin()
|
873
|
+
? [
|
874
|
+
jsx(MenuItem, { disabled: column.getIsPinned() === 'left' || !column.getCanPin(), onClick: () => handlePinColumn('left'), sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(PushPinIcon, { style: { transform: 'rotate(90deg)' } }) }), localization.pinToLeft] }) }, 7),
|
875
|
+
jsx(MenuItem, { disabled: column.getIsPinned() === 'right' || !column.getCanPin(), onClick: () => handlePinColumn('right'), sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(PushPinIcon, { style: { transform: 'rotate(-90deg)' } }) }), localization.pinToRight] }) }, 8),
|
876
|
+
jsx(MenuItem, { disabled: !column.getIsPinned(), divider: enableHiding, onClick: () => handlePinColumn(false), sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(PushPinIcon, {}) }), localization.unpin] }) }, 9),
|
877
|
+
]
|
878
|
+
: []),
|
879
|
+
...(enableColumnResizing && column.getCanResize()
|
880
|
+
? [
|
881
|
+
jsx(MenuItem, { disabled: !columnSizing[column.id], onClick: handleResetColumnSize, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(RestartAltIcon, {}) }), localization.resetColumnSize] }) }, 10),
|
882
|
+
]
|
883
|
+
: []),
|
884
|
+
...(enableHiding
|
885
|
+
? [
|
886
|
+
jsx(MenuItem, { disabled: !column.getCanHide(), onClick: handleHideColumn, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(VisibilityOffIcon, {}) }), (_f = localization.hideColumn) === null || _f === void 0 ? void 0 : _f.replace('{column}', String(columnDef.header))] }) }, 11),
|
879
887
|
jsx(MenuItem, { disabled: !Object.values(columnVisibility).filter((visible) => !visible)
|
880
|
-
.length, onClick: handleShowAllColumns, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(ViewColumnIcon, {}) }), (
|
881
|
-
]
|
888
|
+
.length, onClick: handleShowAllColumns, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(ViewColumnIcon, {}) }), (_g = localization.showAllColumns) === null || _g === void 0 ? void 0 : _g.replace('{column}', String(columnDef.header))] }) }, 12),
|
889
|
+
]
|
890
|
+
: []),
|
891
|
+
].filter(Boolean);
|
892
|
+
return (jsx(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
|
893
|
+
dense: density === 'compact',
|
894
|
+
}, children: (_k = (_j = (_h = columnDef.renderColumnActionsMenuItems) === null || _h === void 0 ? void 0 : _h.call(columnDef, {
|
895
|
+
closeMenu: () => setAnchorEl(null),
|
896
|
+
column,
|
897
|
+
internalColumnMenuItems,
|
898
|
+
table,
|
899
|
+
})) !== null && _j !== void 0 ? _j : renderColumnActionsMenuItems === null || renderColumnActionsMenuItems === void 0 ? void 0 : renderColumnActionsMenuItems({
|
900
|
+
closeMenu: () => setAnchorEl(null),
|
901
|
+
column,
|
902
|
+
internalColumnMenuItems,
|
903
|
+
table,
|
904
|
+
})) !== null && _k !== void 0 ? _k : internalColumnMenuItems }));
|
882
905
|
};
|
883
906
|
|
884
907
|
const MRT_RowActionMenu = ({ anchorEl, handleEdit, row, setAnchorEl, table, }) => {
|
@@ -1653,6 +1676,8 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
1653
1676
|
? textFieldProps.sx(theme)
|
1654
1677
|
: textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx))), children: [(isSelectFilter || isMultiSelectFilter) && (jsx(MenuItem, { divider: true, disabled: true, hidden: true, value: "", children: jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder }) })), (_k = textFieldProps.children) !== null && _k !== void 0 ? _k : filterSelectOptions === null || filterSelectOptions === void 0 ? void 0 : filterSelectOptions.map((option) => {
|
1655
1678
|
var _a;
|
1679
|
+
if (!option)
|
1680
|
+
return '';
|
1656
1681
|
let value;
|
1657
1682
|
let text;
|
1658
1683
|
if (typeof option !== 'object') {
|
@@ -1735,16 +1760,16 @@ const MRT_FilterRangeSlider = ({ header, table }) => {
|
|
1735
1760
|
const sliderProps = Object.assign(Object.assign({}, mTableHeadCellFilterTextFieldProps), mcTableHeadCellFilterTextFieldProps);
|
1736
1761
|
let [min, max] = sliderProps.min !== undefined && sliderProps.max !== undefined
|
1737
1762
|
? [sliderProps.min, sliderProps.max]
|
1738
|
-
: (_a = column.getFacetedMinMaxValues()) !== null && _a !== void 0 ? _a : [0,
|
1739
|
-
//
|
1740
|
-
|
1741
|
-
// To be a bit defensive, implement the same check for max, just in case.
|
1742
|
-
if (Array.isArray(min)) {
|
1763
|
+
: (_a = column.getFacetedMinMaxValues()) !== null && _a !== void 0 ? _a : [0, 1];
|
1764
|
+
//fix potential TanStack Table bugs where min or max is an array
|
1765
|
+
if (Array.isArray(min))
|
1743
1766
|
min = min[0];
|
1744
|
-
|
1745
|
-
if (Array.isArray(max)) {
|
1767
|
+
if (Array.isArray(max))
|
1746
1768
|
max = max[0];
|
1747
|
-
|
1769
|
+
if (min === null)
|
1770
|
+
min = 0;
|
1771
|
+
if (max === null)
|
1772
|
+
max = 1;
|
1748
1773
|
const [filterValues, setFilterValues] = useState([min, max]);
|
1749
1774
|
const columnFilterValue = column.getFilterValue();
|
1750
1775
|
const isMounted = useRef(false);
|
@@ -1754,20 +1779,23 @@ const MRT_FilterRangeSlider = ({ header, table }) => {
|
|
1754
1779
|
setFilterValues([min, max]);
|
1755
1780
|
}
|
1756
1781
|
else if (Array.isArray(columnFilterValue)) {
|
1757
|
-
|
1758
|
-
column.setFilterValue(undefined);
|
1759
|
-
}
|
1760
|
-
else {
|
1761
|
-
setFilterValues(columnFilterValue);
|
1762
|
-
}
|
1782
|
+
setFilterValues(columnFilterValue);
|
1763
1783
|
}
|
1764
1784
|
}
|
1765
1785
|
isMounted.current = true;
|
1766
|
-
}, [
|
1767
|
-
return (jsxs(Stack, { children: [jsx(Slider, Object.assign({ disableSwap: true, min: min, max: max, onChange: (_event,
|
1768
|
-
setFilterValues(
|
1786
|
+
}, [columnFilterValue, min, max]);
|
1787
|
+
return (jsxs(Stack, { children: [jsx(Slider, Object.assign({ disableSwap: true, min: min, max: max, onChange: (_event, values) => {
|
1788
|
+
setFilterValues(values);
|
1769
1789
|
}, onChangeCommitted: (_event, value) => {
|
1770
|
-
|
1790
|
+
if (Array.isArray(value)) {
|
1791
|
+
if (value[0] <= min && value[1] >= max) {
|
1792
|
+
//if the user has selected the entire range, remove the filter
|
1793
|
+
column.setFilterValue(undefined);
|
1794
|
+
}
|
1795
|
+
else {
|
1796
|
+
column.setFilterValue(value);
|
1797
|
+
}
|
1798
|
+
}
|
1771
1799
|
}, value: filterValues, valueLabelDisplay: "auto" }, sliderProps, { slotProps: {
|
1772
1800
|
input: {
|
1773
1801
|
ref: (node) => {
|
@@ -1805,18 +1833,18 @@ const MRT_TableHeadCellFilterContainer = ({ header, table }) => {
|
|
1805
1833
|
};
|
1806
1834
|
|
1807
1835
|
const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
1808
|
-
var _a, _b, _c;
|
1836
|
+
var _a, _b, _c, _d;
|
1809
1837
|
const { options: { icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs }, setShowColumnFilters, } = table;
|
1810
1838
|
const { column } = header;
|
1811
1839
|
const { columnDef } = column;
|
1812
|
-
const isRangeFilter = columnDef.filterVariant
|
1840
|
+
const isRangeFilter = ['range', 'ranger-slider'].includes((_a = columnDef.filterVariant) !== null && _a !== void 0 ? _a : '') ||
|
1813
1841
|
['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
|
1814
1842
|
const currentFilterOption = columnDef._filterFn;
|
1815
1843
|
const filterTooltip = localization.filteringByColumn
|
1816
1844
|
.replace('{column}', String(columnDef.header))
|
1817
1845
|
.replace('{filterType}',
|
1818
1846
|
// @ts-ignore
|
1819
|
-
localization[`filter${((
|
1847
|
+
localization[`filter${((_b = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) +
|
1820
1848
|
(currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`])
|
1821
1849
|
.replace('{filterValue}', `"${Array.isArray(column.getFilterValue())
|
1822
1850
|
? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
|
@@ -1824,7 +1852,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
|
1824
1852
|
.replace('" "', '');
|
1825
1853
|
return (jsx(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
|
1826
1854
|
(isRangeFilter && // @ts-ignore
|
1827
|
-
(!!((
|
1855
|
+
(!!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[0]) || !!((_d = column.getFilterValue()) === null || _d === void 0 ? void 0 : _d[1]))), children: jsx(Box, { component: "span", sx: { flex: '0 0' }, children: jsx(Tooltip, { arrow: true, placement: "top", title: filterTooltip, children: jsx(IconButton, { disableRipple: true, onClick: (event) => {
|
1828
1856
|
setShowColumnFilters(true);
|
1829
1857
|
queueMicrotask(() => {
|
1830
1858
|
var _a, _b;
|
@@ -2414,7 +2442,7 @@ const MRT_TableBodyCell = ({ cell, measureElement, numRows, rowIndex, rowRef, ta
|
|
2414
2442
|
table,
|
2415
2443
|
theme,
|
2416
2444
|
tableCellProps,
|
2417
|
-
})), draggingBorders)), children: jsxs(Fragment, { children: [cell.getIsPlaceholder() ? ((_b = (_a = columnDef.PlaceholderCell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) !== null && _b !== void 0 ? _b : null) : isLoading || showSkeletons ? (jsx(Skeleton, Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
|
2445
|
+
})), draggingBorders)), children: jsxs(Fragment, { children: [cell.getIsPlaceholder() ? ((_b = (_a = columnDef.PlaceholderCell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) !== null && _b !== void 0 ? _b : null) : (isLoading || showSkeletons) && cell.getValue() === null ? (jsx(Skeleton, Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
|
2418
2446
|
rowNumberMode === 'static' &&
|
2419
2447
|
column.id === 'mrt-row-numbers' ? (rowIndex + 1) : column.id === 'mrt-row-drag' ? (jsx(MRT_TableBodyRowGrabHandle, { cell: cell, rowRef: rowRef, table: table })) : columnDefType === 'display' &&
|
2420
2448
|
(column.id === 'mrt-row-select' ||
|
@@ -2828,7 +2856,7 @@ const MRT_TablePaper = ({ table }) => {
|
|
2828
2856
|
|
2829
2857
|
const MRT_EditRowModal = ({ open, row, table, }) => {
|
2830
2858
|
const { options: { localization }, } = table;
|
2831
|
-
return (jsxs(Dialog, { open: open, children: [jsx(DialogTitle, { textAlign: "center", children: localization.edit }), jsx(DialogContent, { children: jsx("form", { onSubmit: (e) => e.preventDefault(), children: jsx(Stack
|
2859
|
+
return (jsxs(Dialog, { open: open, children: [jsx(DialogTitle, { textAlign: "center", children: localization.edit }), jsx(DialogContent, { children: jsx("form", { onSubmit: (e) => e.preventDefault(), children: jsx(Stack, { sx: {
|
2832
2860
|
gap: '1.5rem',
|
2833
2861
|
minWidth: { xs: '300px', sm: '360px', md: '400px' },
|
2834
2862
|
pt: '1rem',
|