material-react-table 1.9.0 → 1.9.1

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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
2
+ import { type VirtualItem, type Virtualizer } from '@tanstack/react-virtual';
3
3
  import type { MRT_TableInstance } from '..';
4
4
  interface Props {
5
5
  columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
@@ -1,7 +1,7 @@
1
- import type { Row } from '@tanstack/react-table';
2
1
  import { MRT_AggregationFns } from './aggregationFns';
3
2
  import { MRT_FilterFns } from './filterFns';
4
3
  import { MRT_SortingFns } from './sortingFns';
4
+ import type { Row } from '@tanstack/react-table';
5
5
  import type { TableCellProps } from '@mui/material/TableCell';
6
6
  import type { Theme } from '@mui/material/styles';
7
7
  import type { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_ColumnOrderState, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterOption, MRT_GroupingState, MRT_Header, MRT_TableInstance } from '.';
@@ -1,5 +1,5 @@
1
1
  import { RankingInfo } from '@tanstack/match-sorter-utils';
2
- import { Row } from '@tanstack/react-table';
2
+ import { type Row } from '@tanstack/react-table';
3
3
  export declare const MRT_FilterFns: {
4
4
  between: {
5
5
  <TData extends Record<string, any> = {}>(row: Row<TData>, id: string, filterValues: [string | number, string | number]): boolean;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { VirtualItem } from '@tanstack/react-virtual';
2
+ import type { VirtualItem } from '@tanstack/react-virtual';
3
3
  import type { MRT_HeaderGroup, MRT_TableInstance } from '..';
4
4
  interface Props {
5
5
  footerGroup: MRT_HeaderGroup;
@@ -1,5 +1,5 @@
1
- import { Row } from '@tanstack/react-table';
2
- import { MRT_Row } from '.';
1
+ import { type Row } from '@tanstack/react-table';
2
+ import type { MRT_Row } from '.';
3
3
  export declare const MRT_SortingFns: {
4
4
  fuzzy: <TData extends Record<string, any> = {}>(rowA: Row<TData>, rowB: Row<TData>, columnId: string) => number;
5
5
  alphanumeric: import("@tanstack/react-table").SortingFn<any>;
@@ -553,6 +553,9 @@ const mrtFilterOptions = (localization) => [
553
553
  divider: false,
554
554
  },
555
555
  ];
556
+ const rangeModes = ['between', 'betweenInclusive', 'inNumberRange'];
557
+ const emptyModes = ['empty', 'notEmpty'];
558
+ const arrModes = ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'];
556
559
  const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilterValue, table, }) => {
557
560
  var _a, _b, _c, _d;
558
561
  const { getState, options: { columnFilterModeOptions, globalFilterModeOptions, localization, renderColumnFilterModeMenuItems, renderGlobalFilterModeMenuItems, }, setColumnFilterFns, setGlobalFilterFn, } = table;
@@ -568,36 +571,62 @@ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilt
568
571
  globalFilterModeOptions.includes(filterOption.option)) &&
569
572
  ['fuzzy', 'contains', 'startsWith'].includes(filterOption.option)), []);
570
573
  const handleSelectFilterMode = (option) => {
571
- if (header && column) {
574
+ var _a;
575
+ const prevFilterMode = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef._filterFn) !== null && _a !== void 0 ? _a : '';
576
+ if (!header || !column) {
577
+ // global filter mode
578
+ setGlobalFilterFn(option);
579
+ }
580
+ else if (option !== prevFilterMode) {
581
+ // column filter mode
572
582
  setColumnFilterFns((prev) => (Object.assign(Object.assign({}, prev), { [header.id]: option })));
573
- if (['empty', 'notEmpty'].includes(option)) {
574
- column.setFilterValue(' ');
583
+ // reset filter value and/or perform new filter render
584
+ if (emptyModes.includes(option)) {
585
+ // will now be empty/notEmpty filter mode
586
+ if (currentFilterValue !== ' ' &&
587
+ !emptyModes.includes(prevFilterMode)) {
588
+ column.setFilterValue(' ');
589
+ }
590
+ else if (currentFilterValue) {
591
+ column.setFilterValue(currentFilterValue); // perform new filter render
592
+ }
575
593
  }
576
594
  else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'multi-select' ||
577
- ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'].includes(option)) {
595
+ arrModes.includes(option)) {
596
+ // will now be array filter mode
578
597
  if (currentFilterValue instanceof String ||
579
598
  (currentFilterValue === null || currentFilterValue === void 0 ? void 0 : currentFilterValue.length)) {
580
599
  column.setFilterValue([]);
581
600
  setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue([]);
582
601
  }
602
+ else if (currentFilterValue) {
603
+ column.setFilterValue(currentFilterValue); // perform new filter render
604
+ }
583
605
  }
584
606
  else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'range' ||
585
- ['between', 'betweenInclusive', 'inNumberRange'].includes(option)) {
586
- if (!(currentFilterValue === null || currentFilterValue === void 0 ? void 0 : currentFilterValue.every((v) => v === ''))) {
607
+ rangeModes.includes(option)) {
608
+ // will now be range filter mode
609
+ if (!Array.isArray(currentFilterValue) ||
610
+ (!(currentFilterValue === null || currentFilterValue === void 0 ? void 0 : currentFilterValue.every((v) => v === '')) &&
611
+ !rangeModes.includes(prevFilterMode))) {
587
612
  column.setFilterValue(['', '']);
588
613
  setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
589
614
  }
615
+ else {
616
+ column.setFilterValue(currentFilterValue); // perform new filter render
617
+ }
590
618
  }
591
619
  else {
592
- if (!['', undefined].includes(currentFilterValue)) {
620
+ // will now be single value filter mode
621
+ if (Array.isArray(currentFilterValue)) {
593
622
  column.setFilterValue('');
594
623
  setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
595
624
  }
625
+ else {
626
+ column.setFilterValue(currentFilterValue); // perform new filter render
627
+ }
596
628
  }
597
629
  }
598
- else {
599
- setGlobalFilterFn(option);
600
- }
601
630
  setAnchorEl(null);
602
631
  onSelect === null || onSelect === void 0 ? void 0 : onSelect();
603
632
  };
@@ -1566,7 +1595,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1566
1595
  else if (isRangeFilter) {
1567
1596
  setFilterValue('');
1568
1597
  column.setFilterValue((old) => {
1569
- const newFilterValues = old !== null && old !== void 0 ? old : ['', ''];
1598
+ const newFilterValues = (Array.isArray(old) && old) || ['', ''];
1570
1599
  newFilterValues[rangeFilterIndex] = undefined;
1571
1600
  return newFilterValues;
1572
1601
  });
@@ -2445,9 +2474,11 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
2445
2474
  ? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
2446
2475
  : undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', width: '100%', '&:hover td': {
2447
2476
  backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false
2448
- ? theme.palette.mode === 'dark'
2449
- ? `${lighten(theme.palette.background.default, 0.12)}`
2450
- : `${darken(theme.palette.background.default, 0.05)}`
2477
+ ? row.getIsSelected()
2478
+ ? `${alpha(theme.palette.primary.main, 0.2)}`
2479
+ : theme.palette.mode === 'dark'
2480
+ ? `${lighten(theme.palette.background.default, 0.12)}`
2481
+ : `${darken(theme.palette.background.default, 0.05)}`
2451
2482
  : undefined,
2452
2483
  } }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
2453
2484
  ? tableRowProps.sx(theme)