material-react-table 0.5.8 → 0.6.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.
Files changed (67) hide show
  1. package/dist/MaterialReactTable.d.ts +1 -10
  2. package/dist/body/MRT_TableBodyCell.d.ts +1 -1
  3. package/dist/body/MRT_TableBodyRow.d.ts +1 -1
  4. package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
  5. package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
  6. package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
  7. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +1 -1
  8. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
  9. package/dist/enums.d.ts +12 -0
  10. package/dist/filtersFNs.d.ts +20 -0
  11. package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
  12. package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
  13. package/dist/head/MRT_TableHeadCell.d.ts +1 -1
  14. package/dist/head/MRT_TableHeadRow.d.ts +1 -1
  15. package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
  16. package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
  17. package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
  18. package/dist/localization.d.ts +43 -44
  19. package/dist/material-react-table.cjs.development.js +375 -227
  20. package/dist/material-react-table.cjs.development.js.map +1 -1
  21. package/dist/material-react-table.cjs.production.min.js +1 -1
  22. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  23. package/dist/material-react-table.esm.js +367 -221
  24. package/dist/material-react-table.esm.js.map +1 -1
  25. package/dist/menus/MRT_ColumnActionMenu.d.ts +1 -1
  26. package/dist/menus/MRT_FilterTypeMenu.d.ts +1 -1
  27. package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
  28. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +3 -2
  29. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -0
  30. package/dist/useMRT.d.ts +1 -1
  31. package/package.json +3 -3
  32. package/src/MaterialReactTable.tsx +1 -11
  33. package/src/body/MRT_TableBody.tsx +1 -1
  34. package/src/body/MRT_TableBodyCell.tsx +1 -1
  35. package/src/body/MRT_TableBodyRow.tsx +1 -1
  36. package/src/body/MRT_TableDetailPanel.tsx +1 -1
  37. package/src/buttons/MRT_EditActionButtons.tsx +5 -8
  38. package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
  39. package/src/buttons/MRT_ExpandButton.tsx +3 -3
  40. package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
  41. package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -52
  42. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
  43. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
  44. package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
  45. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +4 -8
  46. package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
  47. package/src/enums.ts +12 -0
  48. package/src/filtersFNs.ts +31 -0
  49. package/src/footer/MRT_TableFooter.tsx +1 -1
  50. package/src/footer/MRT_TableFooterCell.tsx +1 -1
  51. package/src/footer/MRT_TableFooterRow.tsx +1 -1
  52. package/src/head/MRT_TableHead.tsx +1 -1
  53. package/src/head/MRT_TableHeadCell.tsx +20 -7
  54. package/src/head/MRT_TableHeadCellActions.tsx +1 -1
  55. package/src/head/MRT_TableHeadRow.tsx +1 -1
  56. package/src/inputs/MRT_EditCellTextField.tsx +1 -1
  57. package/src/inputs/MRT_FilterTextField.tsx +35 -11
  58. package/src/inputs/MRT_SearchTextField.tsx +3 -3
  59. package/src/inputs/MRT_SelectCheckbox.tsx +5 -5
  60. package/src/localization.ts +87 -88
  61. package/src/menus/MRT_ColumnActionMenu.tsx +60 -15
  62. package/src/menus/MRT_FilterTypeMenu.tsx +45 -11
  63. package/src/menus/MRT_RowActionMenu.tsx +2 -2
  64. package/src/menus/MRT_ShowHideColumnsMenu.tsx +53 -36
  65. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
  66. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
  67. package/src/useMRT.tsx +22 -4
@@ -1,48 +1,65 @@
1
1
  import React, { FC } from 'react';
2
- import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
- import { ColumnInstance } from 'react-table';
4
- import { MRT_ColumnInstance } from '..';
5
- import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
2
+ import { Button, Menu, Divider, Box } from '@mui/material';
3
+ import type { MRT_ColumnInstance } from '..';
4
+ import { useMRT } from '../useMRT';
5
+ import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
6
6
 
7
7
  interface Props {
8
- column: MRT_ColumnInstance;
8
+ anchorEl: HTMLElement | null;
9
+ isSubMenu?: boolean;
10
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
9
11
  }
10
12
 
11
- export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
12
- const isParentHeader = !!column?.columns?.length;
13
-
14
- const allChildColumnsVisible =
15
- isParentHeader &&
16
- !!column.columns?.every((childColumn) => childColumn.isVisible);
17
-
18
- const switchChecked = column.isVisible ?? allChildColumnsVisible;
19
-
20
- const handleToggleColumnHidden = (column: ColumnInstance) => {
21
- if (isParentHeader) {
22
- column?.columns?.forEach?.((childColumn) => {
23
- childColumn.toggleHidden(switchChecked);
24
- });
25
- } else {
26
- column.toggleHidden();
27
- }
28
- };
13
+ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
14
+ anchorEl,
15
+ isSubMenu,
16
+ setAnchorEl,
17
+ }) => {
18
+ const { localization, tableInstance } = useMRT();
29
19
 
30
20
  return (
31
- <>
32
- <MenuItem
33
- sx={{ ...commonMenuItemStyles, pl: `${(column.depth + 0.5) * 2}rem` }}
21
+ <Menu
22
+ anchorEl={anchorEl}
23
+ open={!!anchorEl}
24
+ onClose={() => setAnchorEl(null)}
25
+ MenuListProps={{
26
+ dense: tableInstance.state.densePadding,
27
+ }}
28
+ >
29
+ <Box
30
+ sx={{
31
+ display: 'flex',
32
+ justifyContent: isSubMenu ? 'center' : 'space-between',
33
+ p: '0.5rem',
34
+ pt: 0,
35
+ }}
34
36
  >
35
- <FormControlLabel
36
- componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
37
- checked={switchChecked}
38
- control={<Switch />}
39
- label={column.Header as string}
40
- onChange={() => handleToggleColumnHidden(column)}
37
+ {!isSubMenu && (
38
+ <Button
39
+ disabled={
40
+ !tableInstance.getToggleHideAllColumnsProps().checked &&
41
+ !tableInstance.getToggleHideAllColumnsProps().indeterminate
42
+ }
43
+ onClick={() => tableInstance.toggleHideAllColumns(true)}
44
+ >
45
+ {localization.hideAll}
46
+ </Button>
47
+ )}
48
+ <Button
49
+ disabled={tableInstance.getToggleHideAllColumnsProps().checked}
50
+ onClick={() => tableInstance.toggleHideAllColumns(false)}
51
+ >
52
+ {localization.showAll}
53
+ </Button>
54
+ </Box>
55
+ <Divider />
56
+ {tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
57
+ <MRT_ShowHideColumnsMenuItems
58
+ column={column}
59
+ isSubMenu={isSubMenu}
60
+ key={`${index}-${column.id}`}
41
61
  />
42
- </MenuItem>
43
- {column.columns?.map((c: MRT_ColumnInstance, i) => (
44
- <MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
45
62
  ))}
46
- </>
63
+ </Menu>
47
64
  );
48
65
  };
@@ -0,0 +1,57 @@
1
+ import React, { FC } from 'react';
2
+ import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
+ import { ColumnInstance } from 'react-table';
4
+ import type { MRT_ColumnInstance } from '..';
5
+ import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
6
+
7
+ interface Props {
8
+ column: MRT_ColumnInstance;
9
+ isSubMenu?: boolean;
10
+ }
11
+
12
+ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
13
+ column,
14
+ isSubMenu,
15
+ }) => {
16
+ const isParentHeader = !!column?.columns?.length;
17
+
18
+ const allChildColumnsVisible =
19
+ isParentHeader &&
20
+ !!column.columns?.every((childColumn) => childColumn.isVisible);
21
+
22
+ const switchChecked = column.isVisible ?? allChildColumnsVisible;
23
+
24
+ const handleToggleColumnHidden = (column: ColumnInstance) => {
25
+ if (isParentHeader) {
26
+ column?.columns?.forEach?.((childColumn) => {
27
+ childColumn.toggleHidden(switchChecked);
28
+ });
29
+ } else {
30
+ column.toggleHidden();
31
+ }
32
+ };
33
+
34
+ return (
35
+ <>
36
+ <MenuItem
37
+ sx={{ ...commonMenuItemStyles, pl: `${(column.depth + 0.5) * 2}rem` }}
38
+ >
39
+ <FormControlLabel
40
+ componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
41
+ checked={switchChecked}
42
+ control={<Switch />}
43
+ disabled={isSubMenu && switchChecked}
44
+ label={column.Header as string}
45
+ onChange={() => handleToggleColumnHidden(column)}
46
+ />
47
+ </MenuItem>
48
+ {column.columns?.map((c: MRT_ColumnInstance, i) => (
49
+ <MRT_ShowHideColumnsMenuItems
50
+ key={`${i}-${c.id}`}
51
+ column={c}
52
+ isSubMenu={isSubMenu}
53
+ />
54
+ ))}
55
+ </>
56
+ );
57
+ };
@@ -23,7 +23,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
23
23
 
24
24
  const selectMessage =
25
25
  tableInstance.selectedFlatRows.length > 0
26
- ? localization.toolbarAlertSelectionMessage
26
+ ? localization.selectedCountOfRowCountRowsSelected
27
27
  ?.replace(
28
28
  '{selectedCount}',
29
29
  tableInstance.selectedFlatRows.length.toString(),
@@ -34,10 +34,10 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
34
34
  const groupedByMessage =
35
35
  tableInstance.state.groupBy.length > 0 ? (
36
36
  <span>
37
- {localization.toolbarAlertGroupedByMessage}{' '}
37
+ {localization.groupedBy}{' '}
38
38
  {tableInstance.state.groupBy.map((columnId, index) => (
39
39
  <Fragment key={`${index}-${columnId}`}>
40
- {index > 0 ? localization.toolbarAlertGroupedThenByMessage : ''}
40
+ {index > 0 ? localization.thenBy : ''}
41
41
  <Chip
42
42
  color="secondary"
43
43
  label={
package/src/useMRT.tsx CHANGED
@@ -7,6 +7,7 @@ import React, {
7
7
  useState,
8
8
  Dispatch,
9
9
  SetStateAction,
10
+ useCallback,
10
11
  } from 'react';
11
12
  import {
12
13
  PluginHook,
@@ -21,7 +22,8 @@ import {
21
22
  useSortBy,
22
23
  useTable,
23
24
  } from 'react-table';
24
- import { MRT_FilterType, MRT_FILTER_TYPE, MRT_Row, MRT_TableInstance } from '.';
25
+ import type { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
26
+ import { MRT_FILTER_TYPE } from './enums';
25
27
  import { defaultFilterFNs } from './filtersFNs';
26
28
  import { MRT_Icons } from './icons';
27
29
  import { MRT_Localization } from './localization';
@@ -91,12 +93,28 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
91
93
  [props.filterTypes],
92
94
  );
93
95
 
96
+ const findLowestLevelCols = useCallback(() => {
97
+ let lowestLevelColumns: any[] = props.columns;
98
+ let currentCols: any[] = props.columns;
99
+ while (!!currentCols.length && currentCols.some((col) => col.columns)) {
100
+ const nextCols = currentCols
101
+ .filter((col) => !!col.columns)
102
+ .map((col) => col.columns)
103
+ .flat();
104
+ if (nextCols.every((col) => !col.columns)) {
105
+ lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
106
+ }
107
+ currentCols = nextCols;
108
+ }
109
+ return lowestLevelColumns.filter((col) => !col.columns);
110
+ }, [props.columns]);
111
+
94
112
  const [currentFilterTypes, setCurrentFilterTypes] = useState<{
95
113
  [key: string]: MRT_FilterType;
96
114
  }>(() =>
97
115
  Object.assign(
98
116
  {},
99
- ...props.columns.map((c) => ({
117
+ ...findLowestLevelCols().map((c) => ({
100
118
  [c.accessor as string]:
101
119
  c.filter ??
102
120
  props?.initialState?.filters?.[c.accessor as any] ??
@@ -107,7 +125,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
107
125
 
108
126
  const columns = useMemo(
109
127
  () =>
110
- props.columns.map((column) => {
128
+ findLowestLevelCols().map((column) => {
111
129
  column.filter =
112
130
  filterTypes[
113
131
  currentFilterTypes[column.accessor as string] as MRT_FILTER_TYPE
@@ -123,7 +141,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
123
141
  columns,
124
142
  // @ts-ignore
125
143
  filterTypes,
126
- globalFilterValue: 'fuzzy',
144
+ globalFilter: props.globalFilter ?? 'globalFuzzy',
127
145
  useControlledState: (state) =>
128
146
  useMemo(
129
147
  () => ({