material-react-table 1.0.0-beta.10 → 1.0.0-beta.13
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/MaterialReactTable.d.ts +15 -4
- package/dist/cjs/index.js +65 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_FilterCheckbox.d.ts +8 -0
- package/dist/cjs/table/MRT_TableRoot.d.ts +4 -0
- package/dist/esm/MaterialReactTable.d.ts +15 -4
- package/dist/esm/inputs/MRT_FilterCheckbox.d.ts +8 -0
- package/dist/esm/material-react-table.esm.js +66 -15
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +4 -0
- package/dist/index.d.ts +16 -5
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +26 -2
- package/src/body/MRT_TableBodyCell.tsx +1 -1
- package/src/column.utils.ts +5 -1
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +7 -3
- package/src/inputs/MRT_FilterCheckbox.tsx +96 -0
- package/src/inputs/MRT_FilterTextField.tsx +21 -11
- package/src/inputs/MRT_GlobalFilterTextField.tsx +17 -5
|
@@ -130,6 +130,10 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
130
130
|
table: MRT_TableInstance<TData>;
|
|
131
131
|
column: MRT_Column<TData>;
|
|
132
132
|
}) => import("@mui/material").IconButtonProps<"button", {}>) | undefined;
|
|
133
|
+
muiTableHeadCellFilterCheckboxProps?: import("@mui/material").CheckboxProps | (({ column, table, }: {
|
|
134
|
+
column: MRT_Column<TData>;
|
|
135
|
+
table: MRT_TableInstance<TData>;
|
|
136
|
+
}) => import("@mui/material").CheckboxProps) | undefined;
|
|
133
137
|
muiTableHeadCellFilterTextFieldProps?: import("@mui/material").TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
134
138
|
table: MRT_TableInstance<TData>;
|
|
135
139
|
column: MRT_Column<TData>;
|
|
@@ -186,9 +186,10 @@ export declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit
|
|
|
186
186
|
row: MRT_Row<TData>;
|
|
187
187
|
table: MRT_TableInstance<TData>;
|
|
188
188
|
}) => ReactNode;
|
|
189
|
-
Filter?: ({ column, header, table, }: {
|
|
189
|
+
Filter?: ({ column, header, rangeFilterIndex, table, }: {
|
|
190
190
|
column: MRT_Column<TData>;
|
|
191
191
|
header: MRT_Header<TData>;
|
|
192
|
+
rangeFilterIndex?: number;
|
|
192
193
|
table: MRT_TableInstance<TData>;
|
|
193
194
|
}) => ReactNode;
|
|
194
195
|
Footer?: ReactNode | (({ column, footer, table, }: {
|
|
@@ -245,7 +246,7 @@ export declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit
|
|
|
245
246
|
text: string;
|
|
246
247
|
value: any;
|
|
247
248
|
})[];
|
|
248
|
-
filterVariant?: 'text' | 'select' | 'multi-select' | 'range';
|
|
249
|
+
filterVariant?: 'text' | 'select' | 'multi-select' | 'range' | 'checkbox';
|
|
249
250
|
/**
|
|
250
251
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
|
251
252
|
*/
|
|
@@ -276,9 +277,11 @@ export declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit
|
|
|
276
277
|
row: MRT_Row<TData>;
|
|
277
278
|
table: MRT_TableInstance<TData>;
|
|
278
279
|
}) => TextFieldProps);
|
|
279
|
-
muiTableBodyCellProps?: TableCellProps | (({ cell, table, }: {
|
|
280
|
-
table: MRT_TableInstance<TData>;
|
|
280
|
+
muiTableBodyCellProps?: TableCellProps | (({ cell, column, row, table, }: {
|
|
281
281
|
cell: MRT_Cell<TData>;
|
|
282
|
+
column: MRT_Column<TData>;
|
|
283
|
+
row: MRT_Row<TData>;
|
|
284
|
+
table: MRT_TableInstance<TData>;
|
|
282
285
|
}) => TableCellProps);
|
|
283
286
|
muiTableFooterCellProps?: TableCellProps | (({ table, column, }: {
|
|
284
287
|
table: MRT_TableInstance<TData>;
|
|
@@ -292,6 +295,10 @@ export declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit
|
|
|
292
295
|
table: MRT_TableInstance<TData>;
|
|
293
296
|
column: MRT_Column<TData>;
|
|
294
297
|
}) => IconButtonProps);
|
|
298
|
+
muiTableHeadCellFilterCheckboxProps?: CheckboxProps | (({ column, table, }: {
|
|
299
|
+
column: MRT_Column<TData>;
|
|
300
|
+
table: MRT_TableInstance<TData>;
|
|
301
|
+
}) => CheckboxProps);
|
|
295
302
|
muiTableHeadCellFilterTextFieldProps?: TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
296
303
|
table: MRT_TableInstance<TData>;
|
|
297
304
|
column: MRT_Column<TData>;
|
|
@@ -488,6 +495,10 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
|
|
|
488
495
|
table: MRT_TableInstance<TData>;
|
|
489
496
|
column: MRT_Column<TData>;
|
|
490
497
|
}) => IconButtonProps);
|
|
498
|
+
muiTableHeadCellFilterCheckboxProps?: CheckboxProps | (({ column, table, }: {
|
|
499
|
+
column: MRT_Column<TData>;
|
|
500
|
+
table: MRT_TableInstance<TData>;
|
|
501
|
+
}) => CheckboxProps);
|
|
491
502
|
muiTableHeadCellFilterTextFieldProps?: TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
492
503
|
table: MRT_TableInstance<TData>;
|
|
493
504
|
column: MRT_Column<TData>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo, useRef, useState, useCallback, Fragment, memo,
|
|
1
|
+
import React, { useMemo, useRef, useState, useCallback, useEffect, Fragment, memo, useLayoutEffect } from 'react';
|
|
2
2
|
import { aggregationFns, filterFns, sortingFns, useReactTable, getCoreRowModel, getExpandedRowModel, getFacetedRowModel, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel } from '@tanstack/react-table';
|
|
3
3
|
import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityLarge, DensityMedium, DensitySmall, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, KeyboardDoubleArrowDown, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
|
|
4
4
|
import { rankItem, rankings, compareItems } from '@tanstack/match-sorter-utils';
|
|
@@ -591,10 +591,11 @@ const getDefaultColumnOrderIds = (props) => [
|
|
|
591
591
|
const getDefaultColumnFilterFn = (columnDef) => {
|
|
592
592
|
if (columnDef.filterVariant === 'multi-select')
|
|
593
593
|
return 'arrIncludesSome';
|
|
594
|
-
if (columnDef.filterVariant === 'select')
|
|
595
|
-
return 'equals';
|
|
596
594
|
if (columnDef.filterVariant === 'range')
|
|
597
595
|
return 'betweenInclusive';
|
|
596
|
+
if (columnDef.filterVariant === 'select' ||
|
|
597
|
+
columnDef.filterVariant === 'checkbox')
|
|
598
|
+
return 'equals';
|
|
598
599
|
return 'fuzzy';
|
|
599
600
|
};
|
|
600
601
|
const getIsLastLeftPinnedColumn = (table, column) => {
|
|
@@ -1043,6 +1044,9 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
|
|
|
1043
1044
|
var _a;
|
|
1044
1045
|
const { getState, setGlobalFilter, options: { enableGlobalFilterModes, icons: { SearchIcon, CloseIcon }, localization, muiSearchTextFieldProps, }, refs: { searchInputRef }, } = table;
|
|
1045
1046
|
const { globalFilter, showGlobalFilter } = getState();
|
|
1047
|
+
const textFieldProps = muiSearchTextFieldProps instanceof Function
|
|
1048
|
+
? muiSearchTextFieldProps({ table })
|
|
1049
|
+
: muiSearchTextFieldProps;
|
|
1046
1050
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
1047
1051
|
const [searchValue, setSearchValue] = useState(globalFilter !== null && globalFilter !== void 0 ? globalFilter : '');
|
|
1048
1052
|
const handleChangeDebounced = useCallback(debounce((event) => {
|
|
@@ -1060,9 +1064,11 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
|
|
|
1060
1064
|
setSearchValue('');
|
|
1061
1065
|
setGlobalFilter(undefined);
|
|
1062
1066
|
};
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1067
|
+
useEffect(() => {
|
|
1068
|
+
if (globalFilter === undefined) {
|
|
1069
|
+
handleClear();
|
|
1070
|
+
}
|
|
1071
|
+
}, [globalFilter]);
|
|
1066
1072
|
return (React.createElement(Collapse, { in: showGlobalFilter, orientation: "horizontal", unmountOnExit: true, mountOnEnter: true },
|
|
1067
1073
|
React.createElement(TextField, Object.assign({ placeholder: localization.search, onChange: handleChange, value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "standard", InputProps: {
|
|
1068
1074
|
startAdornment: enableGlobalFilterModes ? (React.createElement(InputAdornment, { position: "start" },
|
|
@@ -1452,8 +1458,10 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
|
1452
1458
|
});
|
|
1453
1459
|
const handleChangeDebounced = useCallback(debounce((event) => {
|
|
1454
1460
|
let value = textFieldProps.type === 'date'
|
|
1455
|
-
?
|
|
1456
|
-
:
|
|
1461
|
+
? event.target.valueAsDate
|
|
1462
|
+
: textFieldProps.type === 'number'
|
|
1463
|
+
? event.target.valueAsNumber
|
|
1464
|
+
: event.target.value;
|
|
1457
1465
|
if (isRangeFilter) {
|
|
1458
1466
|
column.setFilterValue((old) => {
|
|
1459
1467
|
const newFilterValues = old !== null && old !== void 0 ? old : ['', ''];
|
|
@@ -1495,8 +1503,13 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
|
1495
1503
|
const handleFilterMenuOpen = (event) => {
|
|
1496
1504
|
setAnchorEl(event.currentTarget);
|
|
1497
1505
|
};
|
|
1506
|
+
useEffect(() => {
|
|
1507
|
+
if (column.getFilterValue() === undefined) {
|
|
1508
|
+
handleClear();
|
|
1509
|
+
}
|
|
1510
|
+
}, [column.getFilterValue()]);
|
|
1498
1511
|
if (columnDef.Filter) {
|
|
1499
|
-
return React.createElement(React.Fragment, null, (_e = columnDef.Filter) === null || _e === void 0 ? void 0 : _e.call(columnDef, { column, header, table }));
|
|
1512
|
+
return (React.createElement(React.Fragment, null, (_e = columnDef.Filter) === null || _e === void 0 ? void 0 : _e.call(columnDef, { column, header, rangeFilterIndex, table })));
|
|
1500
1513
|
}
|
|
1501
1514
|
return (React.createElement(React.Fragment, null,
|
|
1502
1515
|
React.createElement(TextField, Object.assign({ fullWidth: true, inputProps: {
|
|
@@ -1511,7 +1524,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
|
1511
1524
|
localization[`filter${((_f = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _f === void 0 ? void 0 : _f.toUpperCase()) +
|
|
1512
1525
|
(currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]))) : null, FormHelperTextProps: {
|
|
1513
1526
|
sx: {
|
|
1514
|
-
fontSize: '0.
|
|
1527
|
+
fontSize: '0.75rem',
|
|
1515
1528
|
lineHeight: '0.8rem',
|
|
1516
1529
|
whiteSpace: 'nowrap',
|
|
1517
1530
|
},
|
|
@@ -1552,11 +1565,11 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
|
1552
1565
|
if (textFieldProps.inputRef) {
|
|
1553
1566
|
textFieldProps.inputRef = inputRef;
|
|
1554
1567
|
}
|
|
1555
|
-
}, sx: (theme) => (Object.assign({ p: 0, minWidth:
|
|
1556
|
-
? '
|
|
1568
|
+
}, sx: (theme) => (Object.assign({ p: 0, minWidth: isRangeFilter
|
|
1569
|
+
? '100px'
|
|
1557
1570
|
: !filterChipLabel
|
|
1558
1571
|
? '120px'
|
|
1559
|
-
: 'auto', width: '100%', '&
|
|
1572
|
+
: 'auto', width: '100%', '& .MuiSelect-icon': {
|
|
1560
1573
|
mr: '1.5rem',
|
|
1561
1574
|
} }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
|
|
1562
1575
|
? textFieldProps.sx(theme)
|
|
@@ -1593,12 +1606,50 @@ const MRT_FilterRangeFields = ({ header, table }) => {
|
|
|
1593
1606
|
React.createElement(MRT_FilterTextField, { header: header, rangeFilterIndex: 1, table: table })));
|
|
1594
1607
|
};
|
|
1595
1608
|
|
|
1609
|
+
const MRT_FilterCheckbox = ({ column, table }) => {
|
|
1610
|
+
var _a, _b, _c;
|
|
1611
|
+
const { getState, options: { localization, muiTableHeadCellFilterCheckboxProps }, } = table;
|
|
1612
|
+
const { density } = getState();
|
|
1613
|
+
const { columnDef } = column;
|
|
1614
|
+
const mTableHeadCellFilterCheckboxProps = muiTableHeadCellFilterCheckboxProps instanceof Function
|
|
1615
|
+
? muiTableHeadCellFilterCheckboxProps({
|
|
1616
|
+
column,
|
|
1617
|
+
table,
|
|
1618
|
+
})
|
|
1619
|
+
: muiTableHeadCellFilterCheckboxProps;
|
|
1620
|
+
const mcTableHeadCellFilterCheckboxProps = columnDef.muiTableHeadCellFilterCheckboxProps instanceof Function
|
|
1621
|
+
? columnDef.muiTableHeadCellFilterCheckboxProps({
|
|
1622
|
+
column,
|
|
1623
|
+
table,
|
|
1624
|
+
})
|
|
1625
|
+
: columnDef.muiTableHeadCellFilterCheckboxProps;
|
|
1626
|
+
const checkboxProps = Object.assign(Object.assign({}, mTableHeadCellFilterCheckboxProps), mcTableHeadCellFilterCheckboxProps);
|
|
1627
|
+
const filterLabel = (_a = localization.filterByColumn) === null || _a === void 0 ? void 0 : _a.replace('{column}', columnDef.header);
|
|
1628
|
+
return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : filterLabel },
|
|
1629
|
+
React.createElement(FormControlLabel, { control: React.createElement(Checkbox, Object.assign({ checked: column.getFilterValue() === 'true', indeterminate: column.getFilterValue() === undefined, color: column.getFilterValue() === undefined ? 'default' : 'primary', size: density === 'compact' ? 'small' : 'medium' }, checkboxProps, { onClick: (e) => {
|
|
1630
|
+
var _a;
|
|
1631
|
+
e.stopPropagation();
|
|
1632
|
+
(_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
|
|
1633
|
+
}, onChange: (e, checked) => {
|
|
1634
|
+
var _a;
|
|
1635
|
+
column.setFilterValue(column.getFilterValue() === undefined
|
|
1636
|
+
? 'true'
|
|
1637
|
+
: column.getFilterValue() === 'true'
|
|
1638
|
+
? 'false'
|
|
1639
|
+
: undefined);
|
|
1640
|
+
(_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onChange) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e, checked);
|
|
1641
|
+
}, sx: (theme) => (Object.assign({ height: '2.5rem', width: '2.5rem' }, ((checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx) instanceof Function
|
|
1642
|
+
? checkboxProps.sx(theme)
|
|
1643
|
+
: checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx))) })), disableTypography: true, label: (_c = checkboxProps.title) !== null && _c !== void 0 ? _c : filterLabel, sx: { color: 'text.secondary', mt: '-4px', fontWeight: 'normal' }, title: undefined })));
|
|
1644
|
+
};
|
|
1645
|
+
|
|
1596
1646
|
const MRT_TableHeadCellFilterContainer = ({ header, table, }) => {
|
|
1597
1647
|
const { getState } = table;
|
|
1598
1648
|
const { showColumnFilters } = getState();
|
|
1599
1649
|
const { column } = header;
|
|
1600
1650
|
const { columnDef } = column;
|
|
1601
|
-
return (React.createElement(Collapse, { in: showColumnFilters, mountOnEnter: true, unmountOnExit: true },
|
|
1651
|
+
return (React.createElement(Collapse, { in: showColumnFilters, mountOnEnter: true, unmountOnExit: true }, columnDef.filterVariant === 'checkbox' ? (React.createElement(MRT_FilterCheckbox, { column: column, table: table })) : columnDef.filterVariant === 'range' ||
|
|
1652
|
+
['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn) ? (React.createElement(MRT_FilterRangeFields, { header: header, table: table })) : (React.createElement(MRT_FilterTextField, { header: header, table: table }))));
|
|
1602
1653
|
};
|
|
1603
1654
|
|
|
1604
1655
|
const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
|
@@ -2002,7 +2053,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2002
2053
|
? muiTableBodyCellProps({ cell, column, row, table })
|
|
2003
2054
|
: muiTableBodyCellProps;
|
|
2004
2055
|
const mcTableCellBodyProps = columnDef.muiTableBodyCellProps instanceof Function
|
|
2005
|
-
? columnDef.muiTableBodyCellProps({ cell, table })
|
|
2056
|
+
? columnDef.muiTableBodyCellProps({ cell, column, row, table })
|
|
2006
2057
|
: columnDef.muiTableBodyCellProps;
|
|
2007
2058
|
const tableCellProps = Object.assign(Object.assign({}, mTableCellBodyProps), mcTableCellBodyProps);
|
|
2008
2059
|
const skeletonProps = muiTableBodyCellSkeletonProps instanceof Function
|