material-react-table 2.0.0-alpha.2 → 2.0.0-alpha.3

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,2 @@
1
+ import { type MRT_Localization } from '..';
2
+ export declare const MRT_Localization_NP: MRT_Localization;
@@ -1,6 +1,7 @@
1
1
  import { type Dispatch, type MutableRefObject, type ReactNode, type RefObject, type SetStateAction } from 'react';
2
2
  import { type AggregationFn, type Cell, type Column, type ColumnDef, type ColumnFiltersState, type ColumnOrderState, type ColumnPinningState, type ColumnSizingInfoState, type ColumnSizingState, type DeepKeys, type ExpandedState, type FilterFn, type GroupingState, type Header, type HeaderGroup, type OnChangeFn, type PaginationState, type Row, type RowSelectionState, type SortingFn, type SortingState, type Table, type TableOptions, type TableState, type Updater, type VisibilityState } from '@tanstack/react-table';
3
3
  import { type VirtualItem, type Virtualizer, type VirtualizerOptions } from '@tanstack/react-virtual';
4
+ import { type AutocompleteProps } from '@mui/material';
4
5
  import { type AlertProps } from '@mui/material/Alert';
5
6
  import { type ButtonProps } from '@mui/material/Button';
6
7
  import { type CheckboxProps } from '@mui/material/Checkbox';
@@ -22,6 +23,7 @@ import { type TablePaginationProps } from '@mui/material/TablePagination';
22
23
  import { type TableRowProps } from '@mui/material/TableRow';
23
24
  import { type TextFieldProps } from '@mui/material/TextField';
24
25
  import { type ToolbarProps } from '@mui/material/Toolbar';
26
+ import { type DatePickerProps } from '@mui/x-date-pickers';
25
27
  import { type MRT_AggregationFns } from './aggregationFns';
26
28
  import { type MRT_FilterFns } from './filterFns';
27
29
  import { type MRT_Icons } from './icons';
@@ -313,7 +315,7 @@ export type MRT_ColumnDef<TData extends Record<string, any>> = Omit<ColumnDef<TD
313
315
  text: string;
314
316
  value: any;
315
317
  } | string)[];
316
- filterVariant?: 'checkbox' | 'multi-select' | 'range' | 'range-slider' | 'select' | 'text';
318
+ filterVariant?: 'autocomplete' | 'checkbox' | 'date' | 'date-range' | 'multi-select' | 'range' | 'range-slider' | 'select' | 'text';
317
319
  /**
318
320
  * footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
319
321
  */
@@ -352,10 +354,19 @@ export type MRT_ColumnDef<TData extends Record<string, any>> = Omit<ColumnDef<TD
352
354
  row: MRT_Row<TData>;
353
355
  table: MRT_TableInstance<TData>;
354
356
  }) => TextFieldProps) | TextFieldProps;
357
+ muiFilterAutocompleteProps?: ((props: {
358
+ column: MRT_Column<TData>;
359
+ table: MRT_TableInstance<TData>;
360
+ }) => AutocompleteProps<any, any, any, any>) | AutocompleteProps<any, any, any, any>;
355
361
  muiFilterCheckboxProps?: ((props: {
356
362
  column: MRT_Column<TData>;
357
363
  table: MRT_TableInstance<TData>;
358
364
  }) => CheckboxProps) | CheckboxProps;
365
+ muiFilterDatePickerProps?: ((props: {
366
+ column: MRT_Column<TData>;
367
+ rangeFilterIndex?: number;
368
+ table: MRT_TableInstance<TData>;
369
+ }) => DatePickerProps<any>) | DatePickerProps<any>;
359
370
  muiFilterSliderProps?: ((props: {
360
371
  column: MRT_Column<TData>;
361
372
  table: MRT_TableInstance<TData>;
@@ -576,10 +587,19 @@ export type MRT_TableOptions<TData extends Record<string, any>> = Omit<Partial<T
576
587
  row: MRT_Row<TData>;
577
588
  table: MRT_TableInstance<TData>;
578
589
  }) => IconButtonProps) | IconButtonProps;
590
+ muiFilterAutocompleteProps?: ((props: {
591
+ column: MRT_Column<TData>;
592
+ table: MRT_TableInstance<TData>;
593
+ }) => AutocompleteProps<any, any, any, any>) | AutocompleteProps<any, any, any, any>;
579
594
  muiFilterCheckboxProps?: ((props: {
580
595
  column: MRT_Column<TData>;
581
596
  table: MRT_TableInstance<TData>;
582
597
  }) => CheckboxProps) | CheckboxProps;
598
+ muiFilterDatePickerProps?: ((props: {
599
+ column: MRT_Column<TData>;
600
+ rangeFilterIndex?: number;
601
+ table: MRT_TableInstance<TData>;
602
+ }) => DatePickerProps<any>) | DatePickerProps<any>;
583
603
  muiFilterSliderProps?: ((props: {
584
604
  column: MRT_Column<TData>;
585
605
  table: MRT_TableInstance<TData>;
@@ -26,9 +26,11 @@ import ListItemIcon from '@mui/material/ListItemIcon';
26
26
  import Menu from '@mui/material/Menu';
27
27
  import Checkbox from '@mui/material/Checkbox';
28
28
  import FormControlLabel from '@mui/material/FormControlLabel';
29
+ import Autocomplete from '@mui/material/Autocomplete';
29
30
  import Chip from '@mui/material/Chip';
30
31
  import InputAdornment from '@mui/material/InputAdornment';
31
32
  import { debounce } from '@mui/material/utils';
33
+ import { DatePicker } from '@mui/x-date-pickers/DatePicker';
32
34
  import FormHelperText from '@mui/material/FormHelperText';
33
35
  import Slider from '@mui/material/Slider';
34
36
  import Stack from '@mui/material/Stack';
@@ -265,10 +267,10 @@ const getDefaultColumnOrderIds = (props) => {
265
267
  return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
266
268
  };
267
269
  const getDefaultColumnFilterFn = (columnDef) => {
270
+ var _a;
268
271
  if (columnDef.filterVariant === 'multi-select')
269
272
  return 'arrIncludesSome';
270
- if (columnDef.filterVariant === 'range' ||
271
- columnDef.filterVariant === 'range-slider')
273
+ if ((_a = columnDef.filterVariant) === null || _a === void 0 ? void 0 : _a.includes('range'))
272
274
  return 'betweenInclusive';
273
275
  if (columnDef.filterVariant === 'select' ||
274
276
  columnDef.filterVariant === 'checkbox')
@@ -1136,7 +1138,7 @@ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilt
1136
1138
  globalFilterModeOptions.includes(filterOption.option)) &&
1137
1139
  ['contains', 'fuzzy', 'startsWith'].includes(filterOption.option)), []);
1138
1140
  const handleSelectFilterMode = (option) => {
1139
- var _a;
1141
+ var _a, _b;
1140
1142
  const prevFilterMode = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef._filterFn) !== null && _a !== void 0 ? _a : '';
1141
1143
  if (!header || !column) {
1142
1144
  // global filter mode
@@ -1168,7 +1170,7 @@ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilt
1168
1170
  column.setFilterValue(currentFilterValue); // perform new filter render
1169
1171
  }
1170
1172
  }
1171
- else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'range' ||
1173
+ else if (((_b = columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === null || _b === void 0 ? void 0 : _b.includes('range')) ||
1172
1174
  rangeModes.includes(option)) {
1173
1175
  // will now be range filter mode
1174
1176
  if (!Array.isArray(currentFilterValue) ||
@@ -1235,7 +1237,7 @@ const commonListItemStyles = {
1235
1237
  };
1236
1238
  const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
1237
1239
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1238
- const { getState, options: { columnFilterModeOptions, enableColumnFilterModes, enableColumnFilters, enableColumnPinning, enableColumnResizing, enableGrouping, enableHiding, enableSorting, enableSortingRemoval, icons: { ArrowRightIcon, ClearAllIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, RestartAltIcon, SortIcon, ViewColumnIcon, VisibilityOffIcon, }, localization, renderColumnActionsMenuItems, }, refs: { filterInputRefs }, setColumnOrder, setColumnSizingInfo, setShowColumnFilters, toggleAllColumnsVisible, } = table;
1240
+ const { getState, options: { columnFilterDisplayMode, columnFilterModeOptions, enableColumnFilterModes, enableColumnFilters, enableColumnPinning, enableColumnResizing, enableGrouping, enableHiding, enableSorting, enableSortingRemoval, icons: { ArrowRightIcon, ClearAllIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, RestartAltIcon, SortIcon, ViewColumnIcon, VisibilityOffIcon, }, localization, renderColumnActionsMenuItems, }, refs: { filterInputRefs }, setColumnOrder, setColumnSizingInfo, setShowColumnFilters, toggleAllColumnsVisible, } = table;
1239
1241
  const { column } = header;
1240
1242
  const { columnDef } = column;
1241
1243
  const { columnSizing, columnVisibility, density, showColumnFilters } = getState();
@@ -1308,11 +1310,11 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
1308
1310
  jsx(MenuItem, { disabled: !columnFilterValue ||
1309
1311
  (Array.isArray(columnFilterValue) &&
1310
1312
  !columnFilterValue.filter((value) => value).length), onClick: handleClearFilter, sx: commonMenuItemStyles, children: jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(FilterListOffIcon, {}) }), localization.clearFilter] }) }, 3),
1311
- jsxs(MenuItem, { disabled: showColumnFilters && !enableColumnFilterModes, divider: enableGrouping || enableHiding, onClick: showColumnFilters
1313
+ columnFilterDisplayMode === 'subheader' && (jsxs(MenuItem, { disabled: showColumnFilters && !enableColumnFilterModes, divider: enableGrouping || enableHiding, onClick: showColumnFilters
1312
1314
  ? handleOpenFilterModeMenu
1313
- : handleFilterByColumn, sx: commonMenuItemStyles, children: [jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(FilterListIcon, {}) }), (_d = localization.filterByColumn) === null || _d === void 0 ? void 0 : _d.replace('{column}', String(columnDef.header))] }), showFilterModeSubMenu && (jsx(IconButton, { onClick: handleOpenFilterModeMenu, onMouseEnter: handleOpenFilterModeMenu, size: "small", sx: { p: 0 }, children: jsx(ArrowRightIcon, {}) }))] }, 4),
1315
+ : handleFilterByColumn, sx: commonMenuItemStyles, children: [jsxs(Box, { sx: commonListItemStyles, children: [jsx(ListItemIcon, { children: jsx(FilterListIcon, {}) }), (_d = localization.filterByColumn) === null || _d === void 0 ? void 0 : _d.replace('{column}', String(columnDef.header))] }), showFilterModeSubMenu && (jsx(IconButton, { onClick: handleOpenFilterModeMenu, onMouseEnter: handleOpenFilterModeMenu, size: "small", sx: { p: 0 }, children: jsx(ArrowRightIcon, {}) }))] }, 4)),
1314
1316
  showFilterModeSubMenu && (jsx(MRT_FilterOptionMenu, { anchorEl: filterMenuAnchorEl, header: header, onSelect: handleFilterByColumn, setAnchorEl: setFilterMenuAnchorEl, table: table }, 5)),
1315
- ]
1317
+ ].filter(Boolean)
1316
1318
  : []),
1317
1319
  ...(enableGrouping && column.getCanGroup()
1318
1320
  ? [
@@ -1406,18 +1408,29 @@ const MRT_FilterCheckbox = ({ column, table, }) => {
1406
1408
  };
1407
1409
 
1408
1410
  const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1409
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1410
- const { options: { columnFilterModeOptions, enableColumnFilterModes, icons: { CloseIcon, FilterListIcon }, localization, manualFiltering, muiFilterTextFieldProps, }, refs: { filterInputRefs }, setColumnFilterFns, } = table;
1411
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o;
1412
+ const { options: { columnFilterModeOptions, enableColumnFilterModes, icons: { CloseIcon, FilterListIcon }, localization, manualFiltering, muiFilterAutocompleteProps, muiFilterDatePickerProps, muiFilterTextFieldProps, }, refs: { filterInputRefs }, setColumnFilterFns, } = table;
1411
1413
  const { column } = header;
1412
1414
  const { columnDef } = column;
1415
+ const { filterVariant } = columnDef;
1413
1416
  const textFieldProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterTextFieldProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterTextFieldProps, {
1414
1417
  column,
1415
1418
  table,
1416
1419
  }));
1417
- const isRangeFilter = columnDef.filterVariant === 'range' || rangeFilterIndex !== undefined;
1418
- const isSelectFilter = columnDef.filterVariant === 'select';
1419
- const isMultiSelectFilter = columnDef.filterVariant === 'multi-select';
1420
- const isTextboxFilter = columnDef.filterVariant === 'text' ||
1420
+ const autocompleteProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterAutocompleteProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterAutocompleteProps, {
1421
+ column,
1422
+ table,
1423
+ }));
1424
+ const datePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterDatePickerProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterDatePickerProps, {
1425
+ column,
1426
+ table,
1427
+ }));
1428
+ const isDateFilter = filterVariant === null || filterVariant === void 0 ? void 0 : filterVariant.startsWith('date');
1429
+ const isAutocompleteFilter = filterVariant === 'autocomplete';
1430
+ const isRangeFilter = (filterVariant === null || filterVariant === void 0 ? void 0 : filterVariant.includes('range')) || rangeFilterIndex !== undefined;
1431
+ const isSelectFilter = filterVariant === 'select';
1432
+ const isMultiSelectFilter = filterVariant === 'multi-select';
1433
+ const isTextboxFilter = ['autocomplete', 'text'].includes(filterVariant) ||
1421
1434
  (!isSelectFilter && !isMultiSelectFilter);
1422
1435
  const currentFilterOption = columnDef._filterFn;
1423
1436
  const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
@@ -1432,55 +1445,48 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1432
1445
  : rangeFilterIndex === 1
1433
1446
  ? localization.max
1434
1447
  : '';
1435
- const allowedColumnFilterOptions = (_e = columnDef === null || columnDef === void 0 ? void 0 : columnDef.columnFilterModeOptions) !== null && _e !== void 0 ? _e : columnFilterModeOptions;
1448
+ const allowedColumnFilterOptions = (_f = columnDef === null || columnDef === void 0 ? void 0 : columnDef.columnFilterModeOptions) !== null && _f !== void 0 ? _f : columnFilterModeOptions;
1436
1449
  const showChangeModeButton = enableColumnFilterModes &&
1437
1450
  columnDef.enableColumnFilterModes !== false &&
1438
1451
  !rangeFilterIndex &&
1439
1452
  (allowedColumnFilterOptions === undefined ||
1440
1453
  !!(allowedColumnFilterOptions === null || allowedColumnFilterOptions === void 0 ? void 0 : allowedColumnFilterOptions.length));
1441
1454
  const facetedUniqueValues = column.getFacetedUniqueValues();
1442
- const filterSelectOptions = useMemo(() => {
1443
- var _a;
1444
- return (_a = columnDef.filterSelectOptions) !== null && _a !== void 0 ? _a : ((isSelectFilter || isMultiSelectFilter) && facetedUniqueValues
1445
- ? Array.from(facetedUniqueValues.keys())
1446
- .filter((value) => value !== null && value !== undefined)
1447
- .sort((a, b) => a.localeCompare(b))
1448
- : undefined);
1449
- }, [
1450
- columnDef.filterSelectOptions,
1451
- facetedUniqueValues,
1452
- isMultiSelectFilter,
1453
- isSelectFilter,
1454
- ]);
1455
1455
  const [anchorEl, setAnchorEl] = useState(null);
1456
1456
  const [filterValue, setFilterValue] = useState(() => {
1457
1457
  var _a, _b;
1458
1458
  return isMultiSelectFilter
1459
1459
  ? column.getFilterValue() || []
1460
1460
  : isRangeFilter
1461
- ? ((_a = column.getFilterValue()) === null || _a === void 0 ? void 0 : _a[rangeFilterIndex]) || []
1461
+ ? ((_a = column.getFilterValue()) === null || _a === void 0 ? void 0 : _a[rangeFilterIndex]) || ''
1462
1462
  : (_b = column.getFilterValue()) !== null && _b !== void 0 ? _b : '';
1463
1463
  });
1464
- const handleChangeDebounced = useCallback(debounce((event) => {
1465
- const value = textFieldProps.type === 'date'
1466
- ? event.target.valueAsDate
1467
- : textFieldProps.type === 'number'
1468
- ? event.target.valueAsNumber
1469
- : event.target.value;
1464
+ const handleChangeDebounced = useCallback(debounce((newValue) => {
1470
1465
  if (isRangeFilter) {
1471
1466
  column.setFilterValue((old) => {
1472
1467
  const newFilterValues = old !== null && old !== void 0 ? old : ['', ''];
1473
- newFilterValues[rangeFilterIndex] = value;
1468
+ newFilterValues[rangeFilterIndex] = newValue;
1474
1469
  return newFilterValues;
1475
1470
  });
1476
1471
  }
1477
1472
  else {
1478
- column.setFilterValue(value !== null && value !== void 0 ? value : undefined);
1473
+ column.setFilterValue(newValue !== null && newValue !== void 0 ? newValue : undefined);
1479
1474
  }
1480
1475
  }, isTextboxFilter ? (manualFiltering ? 400 : 200) : 1), []);
1481
- const handleChange = (event) => {
1482
- setFilterValue(event.target.value);
1483
- handleChangeDebounced(event);
1476
+ const handleChange = (newValue) => {
1477
+ var _a;
1478
+ setFilterValue((_a = newValue === null || newValue === void 0 ? void 0 : newValue.toString()) !== null && _a !== void 0 ? _a : '');
1479
+ handleChangeDebounced(newValue);
1480
+ };
1481
+ const handleTextFieldChange = (event) => {
1482
+ var _a;
1483
+ const newValue = textFieldProps.type === 'date'
1484
+ ? event.target.valueAsDate
1485
+ : textFieldProps.type === 'number'
1486
+ ? event.target.valueAsNumber
1487
+ : event.target.value;
1488
+ handleChange(newValue);
1489
+ (_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.onChange) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1484
1490
  };
1485
1491
  const handleClear = () => {
1486
1492
  if (isMultiSelectFilter) {
@@ -1528,26 +1534,76 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1528
1534
  isMounted.current = true;
1529
1535
  }, [column.getFilterValue()]);
1530
1536
  if (columnDef.Filter) {
1531
- return (jsx(Fragment, { children: (_f = columnDef.Filter) === null || _f === void 0 ? void 0 : _f.call(columnDef, { column, header, rangeFilterIndex, table }) }));
1537
+ return (jsx(Fragment, { children: (_g = columnDef.Filter) === null || _g === void 0 ? void 0 : _g.call(columnDef, { column, header, rangeFilterIndex, table }) }));
1532
1538
  }
1533
- return (jsxs(Fragment, { children: [jsxs(TextField, Object.assign({ FormHelperTextProps: {
1534
- sx: {
1535
- fontSize: '0.75rem',
1536
- lineHeight: '0.8rem',
1537
- whiteSpace: 'nowrap',
1538
- },
1539
- }, InputProps: {
1540
- endAdornment: !filterChipLabel && (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { arrow: true, placement: "right", title: (_g = localization.clearFilter) !== null && _g !== void 0 ? _g : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearFilter, disabled: !((_h = filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString()) === null || _h === void 0 ? void 0 : _h.length), onClick: handleClear, size: "small", sx: {
1541
- height: '1.75rem',
1542
- width: '1.75rem',
1543
- }, children: jsx(CloseIcon, {}) }) }) }) })),
1544
- startAdornment: showChangeModeButton ? (jsxs(InputAdornment, { position: "start", children: [jsx(Tooltip, { arrow: true, title: localization.changeFilterMode, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.changeFilterMode, onClick: handleFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(FilterListIcon, {}) }) }) }), filterChipLabel && (jsx(Chip, { label: filterChipLabel, onDelete: handleClearEmptyFilterChip }))] })) : null,
1545
- }, SelectProps: {
1539
+ const dropdownOptions = useMemo(() => {
1540
+ var _a;
1541
+ return (_a = columnDef.filterSelectOptions) !== null && _a !== void 0 ? _a : ((isSelectFilter || isMultiSelectFilter || isAutocompleteFilter) &&
1542
+ facetedUniqueValues
1543
+ ? Array.from(facetedUniqueValues.keys())
1544
+ .filter((value) => value !== null && value !== undefined)
1545
+ .sort((a, b) => a.localeCompare(b))
1546
+ : undefined);
1547
+ }, [
1548
+ columnDef.filterSelectOptions,
1549
+ facetedUniqueValues,
1550
+ isMultiSelectFilter,
1551
+ isSelectFilter,
1552
+ ]);
1553
+ const endAdornment = !isAutocompleteFilter && !isDateFilter && !filterChipLabel ? (jsx(InputAdornment, { position: "end", sx: { mr: isSelectFilter || isMultiSelectFilter ? '20px' : undefined }, children: jsx(Tooltip, { arrow: true, placement: "right", title: (_h = localization.clearFilter) !== null && _h !== void 0 ? _h : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearFilter, disabled: !((_j = filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString()) === null || _j === void 0 ? void 0 : _j.length), onClick: handleClear, size: "small", sx: {
1554
+ height: '2rem',
1555
+ transform: 'scale(0.9)',
1556
+ width: '2rem'
1557
+ }, children: jsx(CloseIcon, {}) }) }) }) })) : null;
1558
+ const startAdornment = showChangeModeButton ? (jsxs(InputAdornment, { position: "start", children: [jsx(Tooltip, { arrow: true, title: localization.changeFilterMode, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.changeFilterMode, onClick: handleFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(FilterListIcon, {}) }) }) }), filterChipLabel && (jsx(Chip, { label: filterChipLabel, onDelete: handleClearEmptyFilterChip }))] })) : null;
1559
+ const commonTextFieldProps = Object.assign(Object.assign({ FormHelperTextProps: {
1560
+ sx: {
1561
+ fontSize: '0.75rem',
1562
+ lineHeight: '0.8rem',
1563
+ whiteSpace: 'nowrap',
1564
+ },
1565
+ }, InputProps: endAdornment //hack because mui looks for presense of endAdornment key instead of undefined
1566
+ ? { endAdornment, startAdornment }
1567
+ : { startAdornment }, fullWidth: true, helperText: showChangeModeButton ? (jsx("label", { children: localization.filterMode.replace('{filterType}',
1568
+ // @ts-ignore
1569
+ localization[`filter${((_k = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _k === void 0 ? void 0 : _k.toUpperCase()) +
1570
+ (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]) })) : null, inputProps: {
1571
+ autoComplete: 'new-password',
1572
+ disabled: !!filterChipLabel,
1573
+ sx: {
1574
+ textOverflow: 'ellipsis',
1575
+ width: filterChipLabel ? 0 : undefined,
1576
+ },
1577
+ title: filterPlaceholder,
1578
+ }, inputRef: (inputRef) => {
1579
+ filterInputRefs.current[`${column.id}-${rangeFilterIndex !== null && rangeFilterIndex !== void 0 ? rangeFilterIndex : 0}`] =
1580
+ inputRef;
1581
+ if (textFieldProps.inputRef) {
1582
+ textFieldProps.inputRef = inputRef;
1583
+ }
1584
+ }, margin: 'none', onClick: (e) => e.stopPropagation(), placeholder: filterChipLabel || isSelectFilter || isMultiSelectFilter
1585
+ ? undefined
1586
+ : filterPlaceholder, variant: 'standard' }, textFieldProps), { sx: (theme) => (Object.assign({ minWidth: isDateFilter
1587
+ ? '160px'
1588
+ : isRangeFilter
1589
+ ? '100px'
1590
+ : !filterChipLabel
1591
+ ? '120px'
1592
+ : 'auto', mx: '-2px', p: 0, width: 'calc(100% + 4px)' }, parseFromValuesOrFunc(textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx, theme))) });
1593
+ return (jsxs(Fragment, { children: [isDateFilter ? (jsx(DatePicker, Object.assign({ onChange: (newDate) => {
1594
+ handleChange(newDate);
1595
+ }, value: filterValue || null }, datePickerProps, { slotProps: {
1596
+ field: Object.assign({ clearable: true, onClear: () => handleClear() }, (_l = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _l === void 0 ? void 0 : _l.field),
1597
+ textField: Object.assign(Object.assign({}, commonTextFieldProps), (_m = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _m === void 0 ? void 0 : _m.textField),
1598
+ } }))) : isAutocompleteFilter ? (jsx(Autocomplete, Object.assign({ getOptionLabel: (option) => option, onChange: (_e, newValue) => handleChange(newValue), options: dropdownOptions !== null && dropdownOptions !== void 0 ? dropdownOptions : [] }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
1599
+ var _a;
1600
+ return (jsx(TextField, 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 })));
1601
+ }, value: filterValue }))) : (jsx(TextField, Object.assign({ SelectProps: {
1546
1602
  displayEmpty: true,
1547
1603
  multiple: isMultiSelectFilter,
1548
1604
  renderValue: isMultiSelectFilter
1549
1605
  ? (selected) => !(selected === null || selected === void 0 ? void 0 : selected.length) ? (jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder })) : (jsx(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: '2px' }, children: selected === null || selected === void 0 ? void 0 : selected.map((value) => {
1550
- const selectedValue = filterSelectOptions === null || filterSelectOptions === void 0 ? void 0 : filterSelectOptions.find((option) => option instanceof Object
1606
+ const selectedValue = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.find((option) => option instanceof Object
1551
1607
  ? option.value === value
1552
1608
  : option === value);
1553
1609
  return (jsx(Chip, { label: selectedValue instanceof Object
@@ -1555,52 +1611,33 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1555
1611
  : selectedValue }, value));
1556
1612
  }) }))
1557
1613
  : undefined,
1558
- }, fullWidth: true, helperText: showChangeModeButton ? (jsx("label", { children: localization.filterMode.replace('{filterType}',
1559
- // @ts-ignore
1560
- localization[`filter${((_j = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _j === void 0 ? void 0 : _j.toUpperCase()) +
1561
- (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]) })) : null, inputProps: {
1562
- disabled: !!filterChipLabel,
1563
- sx: {
1564
- textOverflow: 'ellipsis',
1565
- width: filterChipLabel ? 0 : undefined,
1566
- },
1567
- title: filterPlaceholder,
1568
- }, margin: "none", onChange: handleChange, onClick: (e) => e.stopPropagation(), placeholder: filterChipLabel || isSelectFilter || isMultiSelectFilter
1569
- ? undefined
1570
- : filterPlaceholder, select: isSelectFilter || isMultiSelectFilter, value: filterValue !== null && filterValue !== void 0 ? filterValue : '', variant: "standard" }, textFieldProps, { inputRef: (inputRef) => {
1571
- filterInputRefs.current[`${column.id}-${rangeFilterIndex !== null && rangeFilterIndex !== void 0 ? rangeFilterIndex : 0}`] =
1572
- inputRef;
1573
- if (textFieldProps.inputRef) {
1574
- textFieldProps.inputRef = inputRef;
1575
- }
1576
- }, sx: (theme) => (Object.assign({ '& .MuiSelect-icon': {
1577
- mr: '1.5rem',
1578
- }, minWidth: isRangeFilter
1579
- ? '100px'
1580
- : !filterChipLabel
1581
- ? '120px'
1582
- : 'auto', mx: '-2px', p: 0, width: 'calc(100% + 4px)' }, parseFromValuesOrFunc(textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx, theme))), children: [(isSelectFilter || isMultiSelectFilter) && (jsx(MenuItem, { disabled: true, divider: true, hidden: true, value: "", children: jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder }) })), (_k = textFieldProps.children) !== null && _k !== void 0 ? _k : filterSelectOptions === null || filterSelectOptions === void 0 ? void 0 : filterSelectOptions.map((option) => {
1583
- var _a;
1584
- if (!option)
1585
- return '';
1586
- let value;
1587
- let text;
1588
- if (typeof option !== 'object') {
1589
- value = option;
1590
- text = option;
1591
- }
1592
- else {
1593
- value = option.value;
1594
- text = option.text;
1595
- }
1596
- return (jsxs(MenuItem, { sx: {
1597
- alignItems: 'center',
1598
- display: 'flex',
1599
- gap: '0.5rem',
1600
- m: 0,
1601
- }, value: value, children: [isMultiSelectFilter && (jsx(Checkbox, { checked: ((_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : []).includes(value), sx: { mr: '0.5rem' } })), text, ' ', !columnDef.filterSelectOptions &&
1602
- `(${facetedUniqueValues.get(value)})`] }, value));
1603
- })] })), jsx(MRT_FilterOptionMenu, { anchorEl: anchorEl, header: header, setAnchorEl: setAnchorEl, setFilterValue: setFilterValue, table: table })] }));
1614
+ }, onChange: handleTextFieldChange, select: isSelectFilter || isMultiSelectFilter }, commonTextFieldProps, { value: filterValue !== null && filterValue !== void 0 ? filterValue : '', children: (isSelectFilter || isMultiSelectFilter) && [
1615
+ jsx(MenuItem, { disabled: true, divider: true, hidden: true, value: "", children: jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder }) }, "p"),
1616
+ ...[
1617
+ (_o = textFieldProps.children) !== null && _o !== void 0 ? _o : dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option, index) => {
1618
+ var _a;
1619
+ if (!option)
1620
+ return '';
1621
+ let value;
1622
+ let text;
1623
+ if (typeof option !== 'object') {
1624
+ value = option;
1625
+ text = option;
1626
+ }
1627
+ else {
1628
+ value = option.value;
1629
+ text = option.text;
1630
+ }
1631
+ return (jsxs(MenuItem, { sx: {
1632
+ alignItems: 'center',
1633
+ display: 'flex',
1634
+ gap: '0.5rem',
1635
+ m: 0,
1636
+ }, value: value, children: [isMultiSelectFilter && (jsx(Checkbox, { checked: ((_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : []).includes(value), sx: { mr: '0.5rem' } })), text, ' ', !columnDef.filterSelectOptions &&
1637
+ `(${facetedUniqueValues.get(value)})`] }, `${index}-${value}`));
1638
+ }),
1639
+ ],
1640
+ ] }))), jsx(MRT_FilterOptionMenu, { anchorEl: anchorEl, header: header, setAnchorEl: setAnchorEl, setFilterValue: setFilterValue, table: table })] }));
1604
1641
  };
1605
1642
 
1606
1643
  const MRT_FilterRangeFields = ({ header, table, }) => {
@@ -1679,16 +1716,17 @@ const MRT_FilterRangeSlider = ({ header, table, }) => {
1679
1716
  };
1680
1717
 
1681
1718
  const MRT_TableHeadCellFilterContainer = ({ header, table, }) => {
1719
+ var _a;
1682
1720
  const { getState, options: { columnFilterDisplayMode }, } = table;
1683
1721
  const { showColumnFilters } = getState();
1684
1722
  const { column } = header;
1685
1723
  const { columnDef } = column;
1686
- return (jsx(Collapse, { in: showColumnFilters || columnFilterDisplayMode === 'popover', mountOnEnter: true, unmountOnExit: true, children: columnDef.filterVariant === 'checkbox' ? (jsx(MRT_FilterCheckbox, { column: column, table: table })) : columnDef.filterVariant === 'range-slider' ? (jsx(MRT_FilterRangeSlider, { header: header, table: table })) : columnDef.filterVariant === 'range' ||
1724
+ return (jsx(Collapse, { in: showColumnFilters || columnFilterDisplayMode === 'popover', mountOnEnter: true, unmountOnExit: true, children: columnDef.filterVariant === 'checkbox' ? (jsx(MRT_FilterCheckbox, { column: column, table: table })) : columnDef.filterVariant === 'range-slider' ? (jsx(MRT_FilterRangeSlider, { header: header, table: table })) : ((_a = columnDef.filterVariant) === null || _a === void 0 ? void 0 : _a.includes('range')) ||
1687
1725
  ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn) ? (jsx(MRT_FilterRangeFields, { header: header, table: table })) : (jsx(MRT_FilterTextField, { header: header, table: table })) }));
1688
1726
  };
1689
1727
 
1690
1728
  const MRT_TableHeadCellFilterLabel = ({ header, table, }) => {
1691
- var _a, _b, _c, _d;
1729
+ var _a, _b, _c;
1692
1730
  const { options: { columnFilterDisplayMode, icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs }, setShowColumnFilters, } = table;
1693
1731
  const { column } = header;
1694
1732
  const { columnDef } = column;
@@ -1696,26 +1734,26 @@ const MRT_TableHeadCellFilterLabel = ({ header, table, }) => {
1696
1734
  const [anchorEl, setAnchorEl] = useState(null);
1697
1735
  const isFilterActive = (Array.isArray(filterValue) && filterValue.some(Boolean)) ||
1698
1736
  (!!filterValue && !Array.isArray(filterValue));
1699
- const isRangeFilter = columnDef.filterVariant === 'range' ||
1737
+ const isRangeFilter = ((_a = columnDef.filterVariant) === null || _a === void 0 ? void 0 : _a.includes('range')) ||
1700
1738
  ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
1701
1739
  const currentFilterOption = columnDef._filterFn;
1702
1740
  const filterTooltip = columnFilterDisplayMode === 'popover' && !isFilterActive
1703
- ? (_a = localization.filterByColumn) === null || _a === void 0 ? void 0 : _a.replace('{column}', String(columnDef.header))
1741
+ ? (_b = localization.filterByColumn) === null || _b === void 0 ? void 0 : _b.replace('{column}', String(columnDef.header))
1704
1742
  : localization.filteringByColumn
1705
1743
  .replace('{column}', String(columnDef.header))
1706
1744
  .replace('{filterType}', currentFilterOption
1707
1745
  ? // @ts-ignore
1708
- localization[`filter${((_b = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) +
1746
+ localization[`filter${((_c = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _c === void 0 ? void 0 : _c.toUpperCase()) +
1709
1747
  (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]
1710
1748
  : '')
1711
- .replace('{filterValue}', `"${Array.isArray(column.getFilterValue())
1712
- ? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1713
- : column.getFilterValue()}"`)
1749
+ .replace('{filterValue}', `"${Array.isArray(filterValue)
1750
+ ? filterValue.join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1751
+ : filterValue}"`)
1714
1752
  .replace('" "', '');
1715
1753
  return (jsxs(Fragment, { children: [jsx(Grow, { in: columnFilterDisplayMode === 'popover' ||
1716
- (!!column.getFilterValue() && !isRangeFilter) ||
1754
+ (!!filterValue && !isRangeFilter) ||
1717
1755
  (isRangeFilter && // @ts-ignore
1718
- (!!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[0]) || !!((_d = column.getFilterValue()) === null || _d === void 0 ? void 0 : _d[1]))), unmountOnExit: true, children: jsx(Box, { component: "span", sx: { flex: '0 0' }, children: jsx(Tooltip, { arrow: true, placement: "top", title: filterTooltip, children: jsx(IconButton, { disableRipple: true, onClick: (event) => {
1756
+ (!!(filterValue === null || filterValue === void 0 ? void 0 : filterValue[0]) || !!(filterValue === null || filterValue === void 0 ? void 0 : filterValue[1]))), unmountOnExit: true, children: jsx(Box, { component: "span", sx: { flex: '0 0' }, children: jsx(Tooltip, { arrow: true, placement: "top", title: filterTooltip, children: jsx(IconButton, { disableRipple: true, onClick: (event) => {
1719
1757
  if (columnFilterDisplayMode === 'popover') {
1720
1758
  setAnchorEl(event.currentTarget);
1721
1759
  }