material-react-table 1.0.0-beta.11 → 1.0.0-beta.14

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.
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import type { MRT_Column, MRT_TableInstance } from '..';
3
+ interface Props {
4
+ column: MRT_Column;
5
+ table: MRT_TableInstance;
6
+ }
7
+ export declare const MRT_FilterCheckbox: FC<Props>;
8
+ export {};
@@ -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>;
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import type { MRT_Column, MRT_TableInstance } from '..';
3
+ interface Props {
4
+ column: MRT_Column;
5
+ table: MRT_TableInstance;
6
+ }
7
+ export declare const MRT_FilterCheckbox: FC<Props>;
8
+ export {};
@@ -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) => {
@@ -1457,8 +1458,10 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1457
1458
  });
1458
1459
  const handleChangeDebounced = useCallback(debounce((event) => {
1459
1460
  let value = textFieldProps.type === 'date'
1460
- ? new Date(event.target.value)
1461
- : event.target.value;
1461
+ ? event.target.valueAsDate
1462
+ : textFieldProps.type === 'number'
1463
+ ? event.target.valueAsNumber
1464
+ : event.target.value;
1462
1465
  if (isRangeFilter) {
1463
1466
  column.setFilterValue((old) => {
1464
1467
  const newFilterValues = old !== null && old !== void 0 ? old : ['', ''];
@@ -1506,7 +1509,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1506
1509
  }
1507
1510
  }, [column.getFilterValue()]);
1508
1511
  if (columnDef.Filter) {
1509
- 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 })));
1510
1513
  }
1511
1514
  return (React.createElement(React.Fragment, null,
1512
1515
  React.createElement(TextField, Object.assign({ fullWidth: true, inputProps: {
@@ -1521,7 +1524,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1521
1524
  localization[`filter${((_f = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _f === void 0 ? void 0 : _f.toUpperCase()) +
1522
1525
  (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]))) : null, FormHelperTextProps: {
1523
1526
  sx: {
1524
- fontSize: '0.6rem',
1527
+ fontSize: '0.75rem',
1525
1528
  lineHeight: '0.8rem',
1526
1529
  whiteSpace: 'nowrap',
1527
1530
  },
@@ -1562,8 +1565,8 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1562
1565
  if (textFieldProps.inputRef) {
1563
1566
  textFieldProps.inputRef = inputRef;
1564
1567
  }
1565
- }, sx: (theme) => (Object.assign({ p: 0, minWidth: columnDef.filterVariant === 'range'
1566
- ? '90px'
1568
+ }, sx: (theme) => (Object.assign({ p: 0, minWidth: isRangeFilter
1569
+ ? '100px'
1567
1570
  : !filterChipLabel
1568
1571
  ? '120px'
1569
1572
  : 'auto', width: '100%', '& .MuiSelect-icon': {
@@ -1603,12 +1606,50 @@ const MRT_FilterRangeFields = ({ header, table }) => {
1603
1606
  React.createElement(MRT_FilterTextField, { header: header, rangeFilterIndex: 1, table: table })));
1604
1607
  };
1605
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
+
1606
1646
  const MRT_TableHeadCellFilterContainer = ({ header, table, }) => {
1607
1647
  const { getState } = table;
1608
1648
  const { showColumnFilters } = getState();
1609
1649
  const { column } = header;
1610
1650
  const { columnDef } = column;
1611
- return (React.createElement(Collapse, { in: showColumnFilters, mountOnEnter: true, unmountOnExit: true }, ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn) ? (React.createElement(MRT_FilterRangeFields, { header: header, table: table })) : (React.createElement(MRT_FilterTextField, { header: header, table: table }))));
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 }))));
1612
1653
  };
1613
1654
 
1614
1655
  const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
@@ -2012,7 +2053,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2012
2053
  ? muiTableBodyCellProps({ cell, column, row, table })
2013
2054
  : muiTableBodyCellProps;
2014
2055
  const mcTableCellBodyProps = columnDef.muiTableBodyCellProps instanceof Function
2015
- ? columnDef.muiTableBodyCellProps({ cell, table })
2056
+ ? columnDef.muiTableBodyCellProps({ cell, column, row, table })
2016
2057
  : columnDef.muiTableBodyCellProps;
2017
2058
  const tableCellProps = Object.assign(Object.assign({}, mTableCellBodyProps), mcTableCellBodyProps);
2018
2059
  const skeletonProps = muiTableBodyCellSkeletonProps instanceof Function