material-react-table 1.13.0 → 1.14.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 +1 -1
- package/dist/cjs/index.js +94 -59
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/_locales/no.d.ts +2 -0
- package/dist/cjs/types/types.d.ts +2 -0
- package/dist/esm/material-react-table.esm.js +91 -58
- 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/types.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- 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 +1 -1
- package/src/_locales/no.ts +94 -0
- package/src/_locales/sv.ts +2 -2
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +1 -1
- package/src/inputs/MRT_FilterRangeSlider.tsx +24 -12
- package/src/inputs/MRT_FilterTextField.tsx +1 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +139 -125
- package/src/types.ts +2 -0
@@ -365,6 +365,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnD
|
|
365
365
|
renderColumnActionsMenuItems?: (props: {
|
366
366
|
closeMenu: () => void;
|
367
367
|
column: MRT_Column<TData>;
|
368
|
+
internalColumnMenuItems: ReactNode[];
|
368
369
|
table: MRT_TableInstance<TData>;
|
369
370
|
}) => ReactNode[];
|
370
371
|
renderColumnFilterModeMenuItems?: (props: {
|
@@ -681,6 +682,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Pr
|
|
681
682
|
renderColumnActionsMenuItems?: (props: {
|
682
683
|
column: MRT_Column<TData>;
|
683
684
|
closeMenu: () => void;
|
685
|
+
internalColumnMenuItems: ReactNode[];
|
684
686
|
table: MRT_TableInstance<TData>;
|
685
687
|
}) => ReactNode[];
|
686
688
|
renderColumnFilterModeMenuItems?: (props: {
|
@@ -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.
|
@@ -784,6 +785,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
784
785
|
const { column } = header;
|
785
786
|
const { columnDef } = column;
|
786
787
|
const { columnSizing, columnVisibility, density, showColumnFilters } = getState();
|
788
|
+
const columnFilterValue = column.getFilterValue();
|
787
789
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] = useState(null);
|
788
790
|
const handleClearSort = () => {
|
789
791
|
column.clearSorting();
|
@@ -839,46 +841,63 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
839
841
|
!isSelectFilter &&
|
840
842
|
(allowedColumnFilterOptions === undefined ||
|
841
843
|
!!(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
|
-
|
844
|
+
const internalColumnMenuItems = [
|
845
|
+
...(enableSorting && column.getCanSort()
|
846
|
+
? [
|
847
|
+
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)),
|
848
|
+
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),
|
849
|
+
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),
|
850
|
+
]
|
851
|
+
: []),
|
852
|
+
...(enableColumnFilters && column.getCanFilter()
|
853
|
+
? [
|
854
|
+
jsx(MenuItem, { disabled: !columnFilterValue ||
|
855
|
+
(Array.isArray(columnFilterValue) &&
|
856
|
+
!columnFilterValue.filter((value) => value).length), onClick: handleClearFilter, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(FilterListOffIcon, {}) }), localization.clearFilter] }) }, 3),
|
857
|
+
jsxs(MenuItem, { disabled: showColumnFilters && !enableColumnFilterModes, divider: enableGrouping || enableHiding, onClick: showColumnFilters
|
858
|
+
? handleOpenFilterModeMenu
|
859
|
+
: 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),
|
860
|
+
showFilterModeSubMenu && (jsx(MRT_FilterOptionMenu, { anchorEl: filterMenuAnchorEl, header: header, onSelect: handleFilterByColumn, setAnchorEl: setFilterMenuAnchorEl, table: table }, 5)),
|
861
|
+
]
|
862
|
+
: []),
|
863
|
+
...(enableGrouping && column.getCanGroup()
|
864
|
+
? [
|
865
|
+
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),
|
866
|
+
]
|
867
|
+
: []),
|
868
|
+
...(enablePinning && column.getCanPin()
|
869
|
+
? [
|
870
|
+
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),
|
871
|
+
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),
|
872
|
+
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),
|
873
|
+
]
|
874
|
+
: []),
|
875
|
+
...(enableColumnResizing && column.getCanResize()
|
876
|
+
? [
|
877
|
+
jsx(MenuItem, { disabled: !columnSizing[column.id], onClick: handleResetColumnSize, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(RestartAltIcon, {}) }), localization.resetColumnSize] }) }, 10),
|
878
|
+
]
|
879
|
+
: []),
|
880
|
+
...(enableHiding
|
881
|
+
? [
|
882
|
+
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
883
|
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
|
-
]
|
884
|
+
.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),
|
885
|
+
]
|
886
|
+
: []),
|
887
|
+
].filter(Boolean);
|
888
|
+
return (jsx(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
|
889
|
+
dense: density === 'compact',
|
890
|
+
}, children: (_k = (_j = (_h = columnDef.renderColumnActionsMenuItems) === null || _h === void 0 ? void 0 : _h.call(columnDef, {
|
891
|
+
closeMenu: () => setAnchorEl(null),
|
892
|
+
column,
|
893
|
+
internalColumnMenuItems,
|
894
|
+
table,
|
895
|
+
})) !== null && _j !== void 0 ? _j : renderColumnActionsMenuItems === null || renderColumnActionsMenuItems === void 0 ? void 0 : renderColumnActionsMenuItems({
|
896
|
+
closeMenu: () => setAnchorEl(null),
|
897
|
+
column,
|
898
|
+
internalColumnMenuItems,
|
899
|
+
table,
|
900
|
+
})) !== null && _k !== void 0 ? _k : internalColumnMenuItems }));
|
882
901
|
};
|
883
902
|
|
884
903
|
const MRT_RowActionMenu = ({ anchorEl, handleEdit, row, setAnchorEl, table, }) => {
|
@@ -1653,6 +1672,8 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
1653
1672
|
? textFieldProps.sx(theme)
|
1654
1673
|
: 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
1674
|
var _a;
|
1675
|
+
if (!option)
|
1676
|
+
return '';
|
1656
1677
|
let value;
|
1657
1678
|
let text;
|
1658
1679
|
if (typeof option !== 'object') {
|
@@ -1733,9 +1754,18 @@ const MRT_FilterRangeSlider = ({ header, table }) => {
|
|
1733
1754
|
})
|
1734
1755
|
: columnDef.muiTableHeadCellFilterSliderProps;
|
1735
1756
|
const sliderProps = Object.assign(Object.assign({}, mTableHeadCellFilterTextFieldProps), mcTableHeadCellFilterTextFieldProps);
|
1736
|
-
|
1757
|
+
let [min, max] = sliderProps.min !== undefined && sliderProps.max !== undefined
|
1737
1758
|
? [sliderProps.min, sliderProps.max]
|
1738
|
-
: (_a = column.getFacetedMinMaxValues()) !== null && _a !== void 0 ? _a : [0,
|
1759
|
+
: (_a = column.getFacetedMinMaxValues()) !== null && _a !== void 0 ? _a : [0, 1];
|
1760
|
+
//fix potential TanStack Table bugs where min or max is an array
|
1761
|
+
if (Array.isArray(min))
|
1762
|
+
min = min[0];
|
1763
|
+
if (Array.isArray(max))
|
1764
|
+
max = max[0];
|
1765
|
+
if (min === null)
|
1766
|
+
min = 0;
|
1767
|
+
if (max === null)
|
1768
|
+
max = 1;
|
1739
1769
|
const [filterValues, setFilterValues] = useState([min, max]);
|
1740
1770
|
const columnFilterValue = column.getFilterValue();
|
1741
1771
|
const isMounted = useRef(false);
|
@@ -1745,20 +1775,23 @@ const MRT_FilterRangeSlider = ({ header, table }) => {
|
|
1745
1775
|
setFilterValues([min, max]);
|
1746
1776
|
}
|
1747
1777
|
else if (Array.isArray(columnFilterValue)) {
|
1748
|
-
|
1749
|
-
column.setFilterValue(undefined);
|
1750
|
-
}
|
1751
|
-
else {
|
1752
|
-
setFilterValues(columnFilterValue);
|
1753
|
-
}
|
1778
|
+
setFilterValues(columnFilterValue);
|
1754
1779
|
}
|
1755
1780
|
}
|
1756
1781
|
isMounted.current = true;
|
1757
|
-
}, [
|
1758
|
-
return (jsxs(Stack, { children: [jsx(Slider, Object.assign({ disableSwap: true, min: min, max: max, onChange: (_event,
|
1759
|
-
setFilterValues(
|
1782
|
+
}, [columnFilterValue, min, max]);
|
1783
|
+
return (jsxs(Stack, { children: [jsx(Slider, Object.assign({ disableSwap: true, min: min, max: max, onChange: (_event, values) => {
|
1784
|
+
setFilterValues(values);
|
1760
1785
|
}, onChangeCommitted: (_event, value) => {
|
1761
|
-
|
1786
|
+
if (Array.isArray(value)) {
|
1787
|
+
if (value[0] <= min && value[1] >= max) {
|
1788
|
+
//if the user has selected the entire range, remove the filter
|
1789
|
+
column.setFilterValue(undefined);
|
1790
|
+
}
|
1791
|
+
else {
|
1792
|
+
column.setFilterValue(value);
|
1793
|
+
}
|
1794
|
+
}
|
1762
1795
|
}, value: filterValues, valueLabelDisplay: "auto" }, sliderProps, { slotProps: {
|
1763
1796
|
input: {
|
1764
1797
|
ref: (node) => {
|
@@ -1796,18 +1829,18 @@ const MRT_TableHeadCellFilterContainer = ({ header, table }) => {
|
|
1796
1829
|
};
|
1797
1830
|
|
1798
1831
|
const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
1799
|
-
var _a, _b, _c;
|
1832
|
+
var _a, _b, _c, _d;
|
1800
1833
|
const { options: { icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs }, setShowColumnFilters, } = table;
|
1801
1834
|
const { column } = header;
|
1802
1835
|
const { columnDef } = column;
|
1803
|
-
const isRangeFilter = columnDef.filterVariant
|
1836
|
+
const isRangeFilter = ['range', 'ranger-slider'].includes((_a = columnDef.filterVariant) !== null && _a !== void 0 ? _a : '') ||
|
1804
1837
|
['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
|
1805
1838
|
const currentFilterOption = columnDef._filterFn;
|
1806
1839
|
const filterTooltip = localization.filteringByColumn
|
1807
1840
|
.replace('{column}', String(columnDef.header))
|
1808
1841
|
.replace('{filterType}',
|
1809
1842
|
// @ts-ignore
|
1810
|
-
localization[`filter${((
|
1843
|
+
localization[`filter${((_b = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) +
|
1811
1844
|
(currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`])
|
1812
1845
|
.replace('{filterValue}', `"${Array.isArray(column.getFilterValue())
|
1813
1846
|
? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
|
@@ -1815,7 +1848,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
|
1815
1848
|
.replace('" "', '');
|
1816
1849
|
return (jsx(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
|
1817
1850
|
(isRangeFilter && // @ts-ignore
|
1818
|
-
(!!((
|
1851
|
+
(!!((_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) => {
|
1819
1852
|
setShowColumnFilters(true);
|
1820
1853
|
queueMicrotask(() => {
|
1821
1854
|
var _a, _b;
|
@@ -2819,7 +2852,7 @@ const MRT_TablePaper = ({ table }) => {
|
|
2819
2852
|
|
2820
2853
|
const MRT_EditRowModal = ({ open, row, table, }) => {
|
2821
2854
|
const { options: { localization }, } = table;
|
2822
|
-
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
|
2855
|
+
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: {
|
2823
2856
|
gap: '1.5rem',
|
2824
2857
|
minWidth: { xs: '300px', sm: '360px', md: '400px' },
|
2825
2858
|
pt: '1rem',
|