material-react-table 1.9.0 → 1.9.2
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/dist/cjs/index.js +55 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +1 -1
- package/dist/cjs/types/body/MRT_TableBody.d.ts +1 -1
- package/dist/cjs/types/column.utils.d.ts +1 -1
- package/dist/cjs/types/filterFns.d.ts +1 -1
- package/dist/cjs/types/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/cjs/types/sortingFns.d.ts +300 -8
- package/dist/esm/material-react-table.esm.js +55 -21
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +1 -1
- package/dist/esm/types/body/MRT_TableBody.d.ts +1 -1
- package/dist/esm/types/column.utils.d.ts +1 -1
- package/dist/esm/types/filterFns.d.ts +1 -1
- package/dist/esm/types/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/esm/types/sortingFns.d.ts +300 -8
- package/dist/index.d.ts +1 -1
- package/package.json +15 -15
- package/src/MaterialReactTable.tsx +2 -2
- package/src/body/MRT_TableBody.tsx +2 -2
- package/src/body/MRT_TableBodyCellValue.tsx +7 -3
- package/src/body/MRT_TableBodyRow.tsx +4 -2
- package/src/column.utils.ts +1 -1
- package/src/filterFns.ts +1 -1
- package/src/footer/MRT_TableFooterRow.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +1 -1
- package/src/menus/MRT_FilterOptionMenu.tsx +39 -15
- package/src/sortingFns.ts +3 -3
- package/src/table/MRT_Table.tsx +2 -2
- package/src/table/MRT_TableRoot.tsx +1 -1
package/dist/cjs/index.js
CHANGED
@@ -631,6 +631,9 @@ const mrtFilterOptions = (localization) => [
|
|
631
631
|
divider: false,
|
632
632
|
},
|
633
633
|
];
|
634
|
+
const rangeModes = ['between', 'betweenInclusive', 'inNumberRange'];
|
635
|
+
const emptyModes = ['empty', 'notEmpty'];
|
636
|
+
const arrModes = ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'];
|
634
637
|
const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilterValue, table, }) => {
|
635
638
|
var _a, _b, _c, _d;
|
636
639
|
const { getState, options: { columnFilterModeOptions, globalFilterModeOptions, localization, renderColumnFilterModeMenuItems, renderGlobalFilterModeMenuItems, }, setColumnFilterFns, setGlobalFilterFn, } = table;
|
@@ -646,36 +649,62 @@ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilt
|
|
646
649
|
globalFilterModeOptions.includes(filterOption.option)) &&
|
647
650
|
['fuzzy', 'contains', 'startsWith'].includes(filterOption.option)), []);
|
648
651
|
const handleSelectFilterMode = (option) => {
|
649
|
-
|
652
|
+
var _a;
|
653
|
+
const prevFilterMode = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef._filterFn) !== null && _a !== void 0 ? _a : '';
|
654
|
+
if (!header || !column) {
|
655
|
+
// global filter mode
|
656
|
+
setGlobalFilterFn(option);
|
657
|
+
}
|
658
|
+
else if (option !== prevFilterMode) {
|
659
|
+
// column filter mode
|
650
660
|
setColumnFilterFns((prev) => (Object.assign(Object.assign({}, prev), { [header.id]: option })));
|
651
|
-
|
652
|
-
|
661
|
+
// reset filter value and/or perform new filter render
|
662
|
+
if (emptyModes.includes(option)) {
|
663
|
+
// will now be empty/notEmpty filter mode
|
664
|
+
if (currentFilterValue !== ' ' &&
|
665
|
+
!emptyModes.includes(prevFilterMode)) {
|
666
|
+
column.setFilterValue(' ');
|
667
|
+
}
|
668
|
+
else if (currentFilterValue) {
|
669
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
670
|
+
}
|
653
671
|
}
|
654
672
|
else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'multi-select' ||
|
655
|
-
|
673
|
+
arrModes.includes(option)) {
|
674
|
+
// will now be array filter mode
|
656
675
|
if (currentFilterValue instanceof String ||
|
657
676
|
(currentFilterValue === null || currentFilterValue === void 0 ? void 0 : currentFilterValue.length)) {
|
658
677
|
column.setFilterValue([]);
|
659
678
|
setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue([]);
|
660
679
|
}
|
680
|
+
else if (currentFilterValue) {
|
681
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
682
|
+
}
|
661
683
|
}
|
662
684
|
else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'range' ||
|
663
|
-
|
664
|
-
|
685
|
+
rangeModes.includes(option)) {
|
686
|
+
// will now be range filter mode
|
687
|
+
if (!Array.isArray(currentFilterValue) ||
|
688
|
+
(!(currentFilterValue === null || currentFilterValue === void 0 ? void 0 : currentFilterValue.every((v) => v === '')) &&
|
689
|
+
!rangeModes.includes(prevFilterMode))) {
|
665
690
|
column.setFilterValue(['', '']);
|
666
691
|
setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
|
667
692
|
}
|
693
|
+
else {
|
694
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
695
|
+
}
|
668
696
|
}
|
669
697
|
else {
|
670
|
-
|
698
|
+
// will now be single value filter mode
|
699
|
+
if (Array.isArray(currentFilterValue)) {
|
671
700
|
column.setFilterValue('');
|
672
701
|
setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
|
673
702
|
}
|
703
|
+
else {
|
704
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
705
|
+
}
|
674
706
|
}
|
675
707
|
}
|
676
|
-
else {
|
677
|
-
setGlobalFilterFn(option);
|
678
|
-
}
|
679
708
|
setAnchorEl(null);
|
680
709
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect();
|
681
710
|
};
|
@@ -1644,7 +1673,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
1644
1673
|
else if (isRangeFilter) {
|
1645
1674
|
setFilterValue('');
|
1646
1675
|
column.setFilterValue((old) => {
|
1647
|
-
const newFilterValues = old
|
1676
|
+
const newFilterValues = (Array.isArray(old) && old) || ['', ''];
|
1648
1677
|
newFilterValues[rangeFilterIndex] = undefined;
|
1649
1678
|
return newFilterValues;
|
1650
1679
|
});
|
@@ -2264,11 +2293,11 @@ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table }) => {
|
|
2264
2293
|
|
2265
2294
|
const allowedTypes = ['string', 'number'];
|
2266
2295
|
const MRT_TableBodyCellValue = ({ cell, table }) => {
|
2267
|
-
var _a, _b, _c
|
2296
|
+
var _a, _b, _c;
|
2268
2297
|
const { getState, options: { enableFilterMatchHighlighting }, } = table;
|
2269
2298
|
const { column, row } = cell;
|
2270
2299
|
const { columnDef } = column;
|
2271
|
-
const { globalFilter } = getState();
|
2300
|
+
const { globalFilter, globalFilterFn } = getState();
|
2272
2301
|
const filterValue = column.getFilterValue();
|
2273
2302
|
let renderedCellValue = cell.getIsAggregated() && columnDef.AggregatedCell
|
2274
2303
|
? columnDef.AggregatedCell({
|
@@ -2298,13 +2327,16 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
2298
2327
|
((filterValue &&
|
2299
2328
|
allowedTypes.includes(typeof filterValue) &&
|
2300
2329
|
columnDef.filterVariant === 'text') ||
|
2301
|
-
(globalFilter &&
|
2330
|
+
(globalFilter &&
|
2331
|
+
allowedTypes.includes(typeof globalFilter) &&
|
2332
|
+
column.getCanGlobalFilter()))) {
|
2302
2333
|
const chunks = highlightWords__default["default"] === null || highlightWords__default["default"] === void 0 ? void 0 : highlightWords__default["default"]({
|
2303
2334
|
text: renderedCellValue === null || renderedCellValue === void 0 ? void 0 : renderedCellValue.toString(),
|
2304
|
-
query: ((
|
2335
|
+
query: ((_a = filterValue !== null && filterValue !== void 0 ? filterValue : globalFilter) !== null && _a !== void 0 ? _a : '').toString(),
|
2336
|
+
matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
2305
2337
|
});
|
2306
|
-
if ((chunks === null || chunks === void 0 ? void 0 : chunks.length) > 1 || ((
|
2307
|
-
renderedCellValue = (React__default["default"].createElement("span", { "aria-label": renderedCellValue, role: "note" }, (
|
2338
|
+
if ((chunks === null || chunks === void 0 ? void 0 : chunks.length) > 1 || ((_b = chunks === null || chunks === void 0 ? void 0 : chunks[0]) === null || _b === void 0 ? void 0 : _b.match)) {
|
2339
|
+
renderedCellValue = (React__default["default"].createElement("span", { "aria-label": renderedCellValue, role: "note" }, (_c = chunks === null || chunks === void 0 ? void 0 : chunks.map(({ key, match, text }) => (React__default["default"].createElement(Box__default["default"], { "aria-hidden": "true", component: "span", key: key, sx: match
|
2308
2340
|
? {
|
2309
2341
|
backgroundColor: (theme) => theme.palette.mode === 'dark'
|
2310
2342
|
? styles.darken(theme.palette.warning.dark, 0.25)
|
@@ -2313,7 +2345,7 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
2313
2345
|
color: (theme) => theme.palette.mode === 'dark' ? 'white' : 'black',
|
2314
2346
|
padding: '2px 1px',
|
2315
2347
|
}
|
2316
|
-
: undefined }, text)))) !== null &&
|
2348
|
+
: undefined }, text)))) !== null && _c !== void 0 ? _c : renderedCellValue));
|
2317
2349
|
}
|
2318
2350
|
}
|
2319
2351
|
if (columnDef.Cell && !isGroupedValue) {
|
@@ -2523,9 +2555,11 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2523
2555
|
? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
|
2524
2556
|
: undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', width: '100%', '&:hover td': {
|
2525
2557
|
backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false
|
2526
|
-
?
|
2527
|
-
? `${styles.
|
2528
|
-
:
|
2558
|
+
? row.getIsSelected()
|
2559
|
+
? `${styles.alpha(theme.palette.primary.main, 0.2)}`
|
2560
|
+
: theme.palette.mode === 'dark'
|
2561
|
+
? `${styles.lighten(theme.palette.background.default, 0.12)}`
|
2562
|
+
: `${styles.darken(theme.palette.background.default, 0.05)}`
|
2529
2563
|
: undefined,
|
2530
2564
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
2531
2565
|
? tableRowProps.sx(theme)
|