material-react-table 2.0.0-beta.13 → 2.0.0-beta.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +53 -4
- package/dist/index.esm.js +34 -41
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +40 -40
- package/dist/index.js.map +1 -1
- package/locales/zh-Hans/index.esm.js +3 -3
- package/locales/zh-Hans/index.js +3 -3
- package/package.json +1 -1
- package/src/column.utils.ts +17 -0
- package/src/hooks/index.ts +4 -0
- package/src/index.ts +1 -0
- package/src/inputs/MRT_EditCellTextField.tsx +20 -30
- package/src/inputs/MRT_FilterTextField.tsx +39 -51
- package/src/locales/zh-Hans.ts +3 -3
- package/src/table/MRT_TablePaper.tsx +6 -6
- package/src/types.ts +22 -3
package/dist/index.js
CHANGED
@@ -404,6 +404,22 @@ function createMRTColumnHelper() {
|
|
404
404
|
group: (column) => column,
|
405
405
|
};
|
406
406
|
}
|
407
|
+
const getValueAndLabel = (option) => {
|
408
|
+
var _a, _b, _c;
|
409
|
+
let label = '';
|
410
|
+
let value = '';
|
411
|
+
if (option) {
|
412
|
+
if (typeof option !== 'object') {
|
413
|
+
label = option;
|
414
|
+
value = option;
|
415
|
+
}
|
416
|
+
else {
|
417
|
+
label = (_b = (_a = option.label) !== null && _a !== void 0 ? _a : option.text) !== null && _b !== void 0 ? _b : option.value;
|
418
|
+
value = (_c = option.value) !== null && _c !== void 0 ? _c : label;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
return { label, value };
|
422
|
+
};
|
407
423
|
|
408
424
|
const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_');
|
409
425
|
const getMRTTheme = (table, theme) => (Object.assign({ baseBackgroundColor: theme.palette.mode === 'dark'
|
@@ -627,10 +643,10 @@ const MRT_EditCellTextField = (_a) => {
|
|
627
643
|
//@ts-ignore
|
628
644
|
row._valuesCache[column.id] = newValue;
|
629
645
|
if (isCreating) {
|
630
|
-
setCreatingRow(
|
646
|
+
setCreatingRow(row);
|
631
647
|
}
|
632
648
|
else if (isEditing) {
|
633
|
-
setEditingRow(
|
649
|
+
setEditingRow(row);
|
634
650
|
}
|
635
651
|
};
|
636
652
|
const handleChange = (event) => {
|
@@ -676,22 +692,13 @@ const MRT_EditCellTextField = (_a) => {
|
|
676
692
|
e.stopPropagation();
|
677
693
|
(_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.onClick) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, e);
|
678
694
|
}, onKeyDown: handleEnterKeyDown, children: (_c = textFieldProps.children) !== null && _c !== void 0 ? _c : (_d = columnDef === null || columnDef === void 0 ? void 0 : columnDef.editSelectOptions) === null || _d === void 0 ? void 0 : _d.map((option) => {
|
679
|
-
|
680
|
-
let text;
|
681
|
-
if (typeof option !== 'object') {
|
682
|
-
value = option;
|
683
|
-
text = option;
|
684
|
-
}
|
685
|
-
else {
|
686
|
-
value = option.value;
|
687
|
-
text = option.text;
|
688
|
-
}
|
695
|
+
const { label, value } = getValueAndLabel(option);
|
689
696
|
return (jsxRuntime.jsx(MenuItem__default["default"], { sx: {
|
690
697
|
alignItems: 'center',
|
691
698
|
display: 'flex',
|
692
699
|
gap: '0.5rem',
|
693
700
|
m: 0,
|
694
|
-
}, value: value, children:
|
701
|
+
}, value: value, children: label }, value));
|
695
702
|
}) })));
|
696
703
|
};
|
697
704
|
|
@@ -1589,7 +1596,7 @@ const MRT_FilterCheckbox = (_a) => {
|
|
1589
1596
|
};
|
1590
1597
|
|
1591
1598
|
const MRT_FilterTextField = (_a) => {
|
1592
|
-
var _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
1599
|
+
var _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
1593
1600
|
var { header, rangeFilterIndex, table } = _a, rest = __rest(_a, ["header", "rangeFilterIndex", "table"]);
|
1594
1601
|
const { options: { columnFilterModeOptions, enableColumnFilterModes, icons: { CloseIcon, FilterListIcon }, localization, manualFiltering, muiFilterAutocompleteProps, muiFilterDatePickerProps, muiFilterTextFieldProps, }, refs: { filterInputRefs }, setColumnFilterFns, } = table;
|
1595
1602
|
const { column } = header;
|
@@ -1749,6 +1756,7 @@ const MRT_FilterTextField = (_a) => {
|
|
1749
1756
|
// @ts-ignore
|
1750
1757
|
localization[`filter${((_l = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _l === void 0 ? void 0 : _l.toUpperCase()) +
|
1751
1758
|
(currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]) })) : null, inputProps: {
|
1759
|
+
'aria-label': filterPlaceholder,
|
1752
1760
|
autoComplete: 'new-password',
|
1753
1761
|
disabled: !!filterChipLabel,
|
1754
1762
|
sx: {
|
@@ -1778,7 +1786,7 @@ const MRT_FilterTextField = (_a) => {
|
|
1778
1786
|
}, value: filterValue || null }, datePickerProps, { slotProps: {
|
1779
1787
|
field: Object.assign({ clearable: true, onClear: () => handleClear() }, (_m = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _m === void 0 ? void 0 : _m.field),
|
1780
1788
|
textField: Object.assign(Object.assign({}, commonTextFieldProps), (_o = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _o === void 0 ? void 0 : _o.textField),
|
1781
|
-
} }))) : isAutocompleteFilter ? (jsxRuntime.jsx(Autocomplete__default["default"], Object.assign({ freeSolo: true, getOptionLabel: (option) => option, onChange: (_e, newValue) => handleChange(newValue), options: dropdownOptions !== null &&
|
1789
|
+
} }))) : isAutocompleteFilter ? (jsxRuntime.jsx(Autocomplete__default["default"], Object.assign({ freeSolo: true, getOptionLabel: (option) => getValueAndLabel(option).label, onChange: (_e, newValue) => handleChange(getValueAndLabel(newValue).value), options: (_p = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option) => getValueAndLabel(option))) !== null && _p !== void 0 ? _p : [] }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
|
1782
1790
|
var _a;
|
1783
1791
|
return (jsxRuntime.jsx(TextField__default["default"], Object.assign({}, builtinTextFieldProps, commonTextFieldProps, { InputProps: Object.assign(Object.assign({}, builtinTextFieldProps.InputProps), { startAdornment: (_a = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.InputProps) === null || _a === void 0 ? void 0 : _a.startAdornment }), inputProps: Object.assign(Object.assign({}, builtinTextFieldProps.inputProps), commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.inputProps), onChange: handleTextFieldChange })));
|
1784
1792
|
}, value: filterValue }))) : (jsxRuntime.jsx(TextField__default["default"], Object.assign({ SelectProps: {
|
@@ -1786,37 +1794,22 @@ const MRT_FilterTextField = (_a) => {
|
|
1786
1794
|
multiple: isMultiSelectFilter,
|
1787
1795
|
renderValue: isMultiSelectFilter
|
1788
1796
|
? (selected) => !(selected === null || selected === void 0 ? void 0 : selected.length) ? (jsxRuntime.jsx(Box__default["default"], { sx: { opacity: 0.5 }, children: filterPlaceholder })) : (jsxRuntime.jsx(Box__default["default"], { sx: { display: 'flex', flexWrap: 'wrap', gap: '2px' }, children: selected === null || selected === void 0 ? void 0 : selected.map((value) => {
|
1789
|
-
const selectedValue = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.find((option) => option
|
1790
|
-
|
1791
|
-
: option === value);
|
1792
|
-
return (jsxRuntime.jsx(Chip__default["default"], { label: selectedValue instanceof Object
|
1793
|
-
? selectedValue.text
|
1794
|
-
: selectedValue }, value));
|
1797
|
+
const selectedValue = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.find((option) => getValueAndLabel(option).value === value);
|
1798
|
+
return (jsxRuntime.jsx(Chip__default["default"], { label: getValueAndLabel(selectedValue).label }, value));
|
1795
1799
|
}) }))
|
1796
1800
|
: undefined,
|
1797
1801
|
}, onChange: handleTextFieldChange, select: isSelectFilter || isMultiSelectFilter }, commonTextFieldProps, { value: filterValue !== null && filterValue !== void 0 ? filterValue : '', children: (isSelectFilter || isMultiSelectFilter) && [
|
1798
1802
|
jsxRuntime.jsx(MenuItem__default["default"], { disabled: true, divider: true, hidden: true, value: "", children: jsxRuntime.jsx(Box__default["default"], { sx: { opacity: 0.5 }, children: filterPlaceholder }) }, "p"),
|
1799
1803
|
...[
|
1800
|
-
(
|
1804
|
+
(_q = textFieldProps.children) !== null && _q !== void 0 ? _q : dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option, index) => {
|
1801
1805
|
var _a;
|
1802
|
-
|
1803
|
-
return '';
|
1804
|
-
let value;
|
1805
|
-
let text;
|
1806
|
-
if (typeof option !== 'object') {
|
1807
|
-
value = option;
|
1808
|
-
text = option;
|
1809
|
-
}
|
1810
|
-
else {
|
1811
|
-
value = option.value;
|
1812
|
-
text = option.text;
|
1813
|
-
}
|
1806
|
+
const { label, value } = getValueAndLabel(option);
|
1814
1807
|
return (jsxRuntime.jsxs(MenuItem__default["default"], { sx: {
|
1815
1808
|
alignItems: 'center',
|
1816
1809
|
display: 'flex',
|
1817
1810
|
gap: '0.5rem',
|
1818
1811
|
m: 0,
|
1819
|
-
}, value: value, children: [isMultiSelectFilter && (jsxRuntime.jsx(Checkbox__default["default"], { checked: ((_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : []).includes(value), sx: { mr: '0.5rem' } })),
|
1812
|
+
}, value: value, children: [isMultiSelectFilter && (jsxRuntime.jsx(Checkbox__default["default"], { checked: ((_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : []).includes(value), sx: { mr: '0.5rem' } })), label, ' ', !columnDef.filterSelectOptions &&
|
1820
1813
|
`(${facetedUniqueValues.get(value)})`] }, `${index}-${value}`));
|
1821
1814
|
}),
|
1822
1815
|
],
|
@@ -2932,12 +2925,12 @@ const MRT_TablePaper = (_a) => {
|
|
2932
2925
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
2933
2926
|
const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps, renderBottomToolbar, renderTopToolbar, }, refs: { tablePaperRef }, } = table;
|
2934
2927
|
const { isFullScreen } = getState();
|
2935
|
-
const
|
2936
|
-
return (jsxRuntime.jsxs(Paper__default["default"], Object.assign({ elevation: 2 },
|
2928
|
+
const paperProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTablePaperProps, { table })), rest);
|
2929
|
+
return (jsxRuntime.jsxs(Paper__default["default"], Object.assign({ elevation: 2 }, paperProps, { ref: (ref) => {
|
2937
2930
|
tablePaperRef.current = ref;
|
2938
|
-
if (
|
2931
|
+
if (paperProps === null || paperProps === void 0 ? void 0 : paperProps.ref) {
|
2939
2932
|
//@ts-ignore
|
2940
|
-
|
2933
|
+
paperProps.ref.current = ref;
|
2941
2934
|
}
|
2942
2935
|
}, style: Object.assign(Object.assign({}, (isFullScreen
|
2943
2936
|
? {
|
@@ -2954,7 +2947,7 @@ const MRT_TablePaper = (_a) => {
|
|
2954
2947
|
width: '100vw',
|
2955
2948
|
zIndex: 999,
|
2956
2949
|
}
|
2957
|
-
: {})),
|
2950
|
+
: {})), paperProps === null || paperProps === void 0 ? void 0 : paperProps.style), sx: (theme) => (Object.assign({ backgroundColor: getMRTTheme(table, theme).baseBackgroundColor, backgroundImage: 'unset', overflow: 'hidden', transition: 'all 100ms ease-in-out' }, parseFromValuesOrFunc(paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx, theme))), children: [enableTopToolbar &&
|
2958
2951
|
((_b = parseFromValuesOrFunc(renderTopToolbar, { table })) !== null && _b !== void 0 ? _b : (jsxRuntime.jsx(MRT_TopToolbar, { table: table }))), jsxRuntime.jsx(MRT_TableContainer, { table: table }), enableBottomToolbar &&
|
2959
2952
|
((_c = parseFromValuesOrFunc(renderBottomToolbar, { table })) !== null && _c !== void 0 ? _c : (jsxRuntime.jsx(MRT_BottomToolbar, { table: table })))] })));
|
2960
2953
|
};
|
@@ -3711,6 +3704,8 @@ exports.MRT_BottomToolbar = MRT_BottomToolbar;
|
|
3711
3704
|
exports.MRT_ColumnActionMenu = MRT_ColumnActionMenu;
|
3712
3705
|
exports.MRT_ColumnPinningButtons = MRT_ColumnPinningButtons;
|
3713
3706
|
exports.MRT_CopyButton = MRT_CopyButton;
|
3707
|
+
exports.MRT_DefaultColumn = MRT_DefaultColumn;
|
3708
|
+
exports.MRT_DefaultDisplayColumn = MRT_DefaultDisplayColumn;
|
3714
3709
|
exports.MRT_EditActionButtons = MRT_EditActionButtons;
|
3715
3710
|
exports.MRT_EditCellTextField = MRT_EditCellTextField;
|
3716
3711
|
exports.MRT_EditRowModal = MRT_EditRowModal;
|
@@ -3790,6 +3785,7 @@ exports.getLeadingDisplayColumnIds = getLeadingDisplayColumnIds;
|
|
3790
3785
|
exports.getMRTTheme = getMRTTheme;
|
3791
3786
|
exports.getTotalRight = getTotalRight;
|
3792
3787
|
exports.getTrailingDisplayColumnIds = getTrailingDisplayColumnIds;
|
3788
|
+
exports.getValueAndLabel = getValueAndLabel;
|
3793
3789
|
exports.mrtFilterOptions = mrtFilterOptions;
|
3794
3790
|
exports.parseCSSVarId = parseCSSVarId;
|
3795
3791
|
exports.parseFromValuesOrFunc = parseFromValuesOrFunc;
|
@@ -3797,5 +3793,9 @@ exports.prepareColumns = prepareColumns;
|
|
3797
3793
|
exports.rankGlobalFuzzy = rankGlobalFuzzy;
|
3798
3794
|
exports.reorderColumn = reorderColumn;
|
3799
3795
|
exports.showExpandColumn = showExpandColumn;
|
3796
|
+
exports.useMRT_DisplayColumns = useMRT_DisplayColumns;
|
3797
|
+
exports.useMRT_Effects = useMRT_Effects;
|
3798
|
+
exports.useMRT_TableInstance = useMRT_TableInstance;
|
3799
|
+
exports.useMRT_TableOptions = useMRT_TableOptions;
|
3800
3800
|
exports.useMaterialReactTable = useMaterialReactTable;
|
3801
3801
|
//# sourceMappingURL=index.js.map
|