material-react-table 0.3.2 → 0.4.0

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 +15 -7
  2. package/dist/body/MRT_TableBodyCell.d.ts +3 -0
  3. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +4 -0
  4. package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
  5. package/dist/head/MRT_TableHeadCell.d.ts +1 -1
  6. package/dist/head/MRT_TableHeadCellActions.d.ts +5 -0
  7. package/dist/inputs/{MRT_EditCellTextfield.d.ts → MRT_EditCellTextField.d.ts} +1 -1
  8. package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
  9. package/dist/material-react-table.cjs.development.js +604 -372
  10. package/dist/material-react-table.cjs.development.js.map +1 -1
  11. package/dist/material-react-table.cjs.production.min.js +1 -1
  12. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  13. package/dist/material-react-table.esm.js +607 -375
  14. package/dist/material-react-table.esm.js.map +1 -1
  15. package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
  16. package/dist/menus/MRT_RowActionMenu.d.ts +1 -0
  17. package/dist/table/MRT_TableButtonCell.d.ts +3 -0
  18. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +5 -0
  19. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +5 -0
  20. package/dist/{useMaterialReactTable.d.ts → useMRT.d.ts} +8 -3
  21. package/dist/utils/localization.d.ts +8 -0
  22. package/package.json +21 -19
  23. package/src/@types/react-table-config.d.ts +37 -34
  24. package/src/MaterialReactTable.tsx +22 -6
  25. package/src/body/MRT_TableBody.tsx +2 -3
  26. package/src/body/MRT_TableBodyCell.tsx +8 -8
  27. package/src/body/MRT_TableBodyRow.tsx +13 -15
  28. package/src/body/MRT_TableDetailPanel.tsx +2 -2
  29. package/src/buttons/MRT_EditActionButtons.tsx +3 -2
  30. package/src/buttons/MRT_ExpandAllButton.tsx +8 -16
  31. package/src/buttons/MRT_ExpandButton.tsx +8 -9
  32. package/src/buttons/MRT_FullScreenToggleButton.tsx +23 -0
  33. package/src/buttons/MRT_ShowHideColumnsButton.tsx +34 -3
  34. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -5
  35. package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
  36. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +48 -26
  37. package/src/buttons/MRT_ToggleSearchButton.tsx +33 -0
  38. package/src/footer/MRT_TableFooter.tsx +2 -2
  39. package/src/footer/MRT_TableFooterCell.tsx +2 -2
  40. package/src/footer/MRT_TableFooterRow.tsx +9 -4
  41. package/src/head/MRT_TableHead.tsx +2 -2
  42. package/src/head/MRT_TableHeadCell.tsx +20 -16
  43. package/src/head/MRT_TableHeadCellActions.tsx +18 -0
  44. package/src/head/MRT_TableHeadRow.tsx +16 -11
  45. package/src/inputs/MRT_DensePaddingSwitch.tsx +5 -3
  46. package/src/inputs/{MRT_EditCellTextfield.tsx → MRT_EditCellTextField.tsx} +23 -16
  47. package/src/inputs/MRT_FilterTextField.tsx +43 -17
  48. package/src/inputs/MRT_SearchTextField.tsx +39 -34
  49. package/src/inputs/MRT_SelectAllCheckbox.tsx +9 -13
  50. package/src/inputs/MRT_SelectCheckbox.tsx +11 -14
  51. package/src/menus/MRT_ColumnActionMenu.tsx +66 -23
  52. package/src/menus/MRT_RowActionMenu.tsx +4 -8
  53. package/src/menus/MRT_ShowHideColumnsMenu.tsx +24 -15
  54. package/src/table/MRT_Table.tsx +2 -2
  55. package/src/table/MRT_TableButtonCell.tsx +9 -0
  56. package/src/table/MRT_TableContainer.tsx +34 -8
  57. package/src/table/MRT_TableSpacerCell.tsx +2 -2
  58. package/src/toolbar/MRT_TablePagination.tsx +3 -2
  59. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +102 -0
  60. package/src/toolbar/MRT_ToolbarBottom.tsx +9 -5
  61. package/src/toolbar/{MRT_ToolbarButtons.tsx → MRT_ToolbarInternalButtons.tsx} +13 -4
  62. package/src/toolbar/MRT_ToolbarTop.tsx +14 -15
  63. package/src/{useMaterialReactTable.tsx → useMRT.tsx} +40 -23
  64. package/src/utils/localization.ts +22 -6
  65. package/dist/toolbar/MRT_ToolbarButtons.d.ts +0 -5
  66. package/dist/utils/useMRTCalcs.d.ts +0 -11
  67. package/src/utils/useMRTCalcs.tsx +0 -42
@@ -1,16 +1,16 @@
1
1
  import React, { ChangeEvent, FC, useState } from 'react';
2
- import { IconButton, InputAdornment, TextField } from '@mui/material';
2
+ import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
3
3
  import CloseIcon from '@mui/icons-material/Close';
4
4
  import FilterIcon from '@mui/icons-material/FilterList';
5
5
  import { HeaderGroup, useAsyncDebounce } from 'react-table';
6
- import { useMaterialReactTable } from '../useMaterialReactTable';
6
+ import { useMRT } from '../useMRT';
7
7
 
8
8
  interface Props {
9
9
  column: HeaderGroup;
10
10
  }
11
11
 
12
- export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
13
- const { localization } = useMaterialReactTable();
12
+ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
13
+ const { localization } = useMRT();
14
14
 
15
15
  const [filterValue, setFilterValue] = useState('');
16
16
 
@@ -24,13 +24,23 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
24
24
  };
25
25
 
26
26
  if (column.Filter) {
27
- return <>{column.Filter({ column })}</>;
27
+ return <>{column.Filter?.({ column })}</>;
28
28
  }
29
29
 
30
30
  return (
31
31
  <TextField
32
+ fullWidth
33
+ id={`filter-${column.id}-column`}
34
+ inputProps={{
35
+ style: {
36
+ textOverflow: 'ellipsis',
37
+ },
38
+ }}
32
39
  margin="dense"
33
- placeholder={localization?.filterTextFieldPlaceholder}
40
+ placeholder={localization?.filterTextFieldPlaceholder?.replace(
41
+ '{column}',
42
+ String(column.Header),
43
+ )}
34
44
  onChange={(e: ChangeEvent<HTMLInputElement>) => {
35
45
  setFilterValue(e.target.value);
36
46
  handleChange(e.target.value);
@@ -40,21 +50,37 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
40
50
  variant="standard"
41
51
  InputProps={{
42
52
  startAdornment: (
43
- <InputAdornment position="start">
44
- <FilterIcon />
45
- </InputAdornment>
53
+ <Tooltip
54
+ arrow
55
+ title={
56
+ localization?.filterTextFieldPlaceholder?.replace(
57
+ '{column}',
58
+ String(column.Header),
59
+ ) ?? ''
60
+ }
61
+ >
62
+ <InputAdornment position="start">
63
+ <FilterIcon />
64
+ </InputAdornment>
65
+ </Tooltip>
46
66
  ),
47
67
  endAdornment: (
48
68
  <InputAdornment position="end">
49
- <IconButton
50
- aria-label={localization?.filterTextFieldClearButtonTitle}
51
- disabled={filterValue?.length === 0}
52
- onClick={handleClear}
53
- size="small"
54
- title={localization?.filterTextFieldClearButtonTitle}
69
+ <Tooltip
70
+ arrow
71
+ title={localization?.filterTextFieldClearButtonTitle ?? ''}
55
72
  >
56
- <CloseIcon fontSize="small" />
57
- </IconButton>
73
+ <span>
74
+ <IconButton
75
+ aria-label={localization?.filterTextFieldClearButtonTitle}
76
+ disabled={filterValue?.length === 0}
77
+ onClick={handleClear}
78
+ size="small"
79
+ >
80
+ <CloseIcon fontSize="small" />
81
+ </IconButton>
82
+ </span>
83
+ </Tooltip>
58
84
  </InputAdornment>
59
85
  ),
60
86
  }}
@@ -1,5 +1,6 @@
1
1
  import React, { ChangeEvent, FC, useState } from 'react';
2
2
  import {
3
+ Collapse,
3
4
  IconButton,
4
5
  InputAdornment,
5
6
  styled,
@@ -7,7 +8,7 @@ import {
7
8
  } from '@mui/material';
8
9
  import SearchIcon from '@mui/icons-material/Search';
9
10
  import CloseIcon from '@mui/icons-material/Close';
10
- import { useMaterialReactTable } from '../useMaterialReactTable';
11
+ import { useMRT } from '../useMRT';
11
12
  import { useAsyncDebounce } from 'react-table';
12
13
 
13
14
  const TextField = styled(MuiTextField)({
@@ -18,11 +19,12 @@ interface Props {}
18
19
 
19
20
  export const MRT_SearchTextField: FC<Props> = () => {
20
21
  const {
21
- tableInstance,
22
- muiSearchTextFieldProps,
22
+ showSearch,
23
23
  localization,
24
+ muiSearchTextFieldProps,
24
25
  onGlobalFilterChange,
25
- } = useMaterialReactTable();
26
+ tableInstance,
27
+ } = useMRT();
26
28
 
27
29
  const [searchValue, setSearchValue] = useState('');
28
30
 
@@ -40,35 +42,38 @@ export const MRT_SearchTextField: FC<Props> = () => {
40
42
  };
41
43
 
42
44
  return (
43
- <TextField
44
- placeholder={localization?.searchTextFieldPlaceholder}
45
- onChange={(event: ChangeEvent<HTMLInputElement>) => {
46
- setSearchValue(event.target.value);
47
- handleChange(event);
48
- }}
49
- value={searchValue ?? ''}
50
- variant="standard"
51
- InputProps={{
52
- startAdornment: (
53
- <InputAdornment position="start">
54
- <SearchIcon fontSize="small" />
55
- </InputAdornment>
56
- ),
57
- endAdornment: (
58
- <InputAdornment position="end">
59
- <IconButton
60
- aria-label={localization?.searchTextFieldClearButtonTitle}
61
- disabled={searchValue?.length === 0}
62
- onClick={handleClear}
63
- size="small"
64
- title={localization?.searchTextFieldClearButtonTitle}
65
- >
66
- <CloseIcon fontSize="small" />
67
- </IconButton>
68
- </InputAdornment>
69
- ),
70
- }}
71
- {...muiSearchTextFieldProps}
72
- />
45
+ <Collapse in={showSearch} orientation="horizontal">
46
+ <TextField
47
+ id="global-search-text-field"
48
+ placeholder={localization?.searchTextFieldPlaceholder}
49
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
50
+ setSearchValue(event.target.value);
51
+ handleChange(event);
52
+ }}
53
+ value={searchValue ?? ''}
54
+ variant="standard"
55
+ InputProps={{
56
+ startAdornment: (
57
+ <InputAdornment position="start">
58
+ <SearchIcon fontSize="small" />
59
+ </InputAdornment>
60
+ ),
61
+ endAdornment: (
62
+ <InputAdornment position="end">
63
+ <IconButton
64
+ aria-label={localization?.searchTextFieldClearButtonTitle}
65
+ disabled={searchValue?.length === 0}
66
+ onClick={handleClear}
67
+ size="small"
68
+ title={localization?.searchTextFieldClearButtonTitle}
69
+ >
70
+ <CloseIcon fontSize="small" />
71
+ </IconButton>
72
+ </InputAdornment>
73
+ ),
74
+ }}
75
+ {...muiSearchTextFieldProps}
76
+ />
77
+ </Collapse>
73
78
  );
74
79
  };
@@ -1,26 +1,22 @@
1
1
  import React from 'react';
2
- import { Checkbox, TableCell as MuiTableCell, styled } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
4
-
5
- const TableCell = styled(MuiTableCell, {
6
- shouldForwardProp: (prop) => prop !== 'densePadding',
7
- })<{ densePadding?: boolean }>(({ densePadding }) => ({
8
- padding: densePadding ? '0' : '0.6rem',
9
- transition: 'all 0.2s ease-in-out',
10
- }));
2
+ import { Checkbox } from '@mui/material';
3
+ import { useMRT } from '../useMRT';
4
+ import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
11
5
 
12
6
  export const MRT_SelectAllCheckbox = () => {
13
7
  const { tableInstance, disableSelectAll, densePadding, localization } =
14
- useMaterialReactTable();
8
+ useMRT();
15
9
 
16
10
  return (
17
- <TableCell densePadding={densePadding} variant="head">
11
+ <MRT_TableButtonCell densePadding={densePadding} variant="head">
18
12
  {!disableSelectAll ? (
19
13
  <Checkbox
20
- aria-label={localization?.selectAllCheckboxTitle}
14
+ inputProps={{
15
+ 'aria-label': localization?.selectAllCheckboxTitle ?? '',
16
+ }}
21
17
  {...tableInstance.getToggleAllPageRowsSelectedProps()}
22
18
  />
23
19
  ) : null}
24
- </TableCell>
20
+ </MRT_TableButtonCell>
25
21
  );
26
22
  };
@@ -1,22 +1,16 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
- import { Checkbox, TableCell as MuiTableCell, styled } from '@mui/material';
2
+ import { Checkbox } from '@mui/material';
3
3
  import { Row } from 'react-table';
4
- import { useMaterialReactTable } from '../useMaterialReactTable';
5
-
6
- const TableCell = styled(MuiTableCell, {
7
- shouldForwardProp: (prop) => prop !== 'densePadding',
8
- })<{ densePadding?: boolean }>(({ densePadding }) => ({
9
- padding: densePadding ? '0' : '0.6rem',
10
- transition: 'all 0.2s ease-in-out',
11
- }));
4
+ import { useMRT } from '../useMRT';
5
+ import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
12
6
 
13
7
  interface Props {
14
8
  row: Row;
15
9
  }
16
10
 
17
11
  export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
18
- const { tableInstance, onRowSelectChange, densePadding } =
19
- useMaterialReactTable();
12
+ const { tableInstance, onRowSelectChange, densePadding, localization } =
13
+ useMRT();
20
14
 
21
15
  const onSelectChange = (event: ChangeEvent) => {
22
16
  row.getToggleRowSelectedProps()?.onChange?.(event);
@@ -24,11 +18,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
24
18
  };
25
19
 
26
20
  return (
27
- <TableCell densePadding={densePadding}>
21
+ <MRT_TableButtonCell densePadding={densePadding}>
28
22
  <Checkbox
29
- {...row.getToggleRowSelectedProps()}
23
+ inputProps={{
24
+ 'aria-label': localization?.selectCheckboxTitle,
25
+ }}
30
26
  onChange={onSelectChange}
27
+ {...row.getToggleRowSelectedProps()}
31
28
  />
32
- </TableCell>
29
+ </MRT_TableButtonCell>
33
30
  );
34
31
  };
@@ -1,11 +1,12 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
4
- import { ColumnInstance } from 'react-table';
3
+ import { useMRT } from '../useMRT';
4
+ import { HeaderGroup } from 'react-table';
5
5
  import ClearAllIcon from '@mui/icons-material/ClearAll';
6
6
  import SortIcon from '@mui/icons-material/Sort';
7
7
  import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
8
8
  import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
9
+ import FilterIcon from '@mui/icons-material/FilterList';
9
10
 
10
11
  const MenuItem = styled(MuiMenuItem)({
11
12
  display: 'flex',
@@ -14,7 +15,7 @@ const MenuItem = styled(MuiMenuItem)({
14
15
 
15
16
  interface Props {
16
17
  anchorEl: HTMLElement | null;
17
- column: ColumnInstance;
18
+ column: HeaderGroup;
18
19
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
19
20
  }
20
21
 
@@ -25,10 +26,12 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
25
26
  }) => {
26
27
  const {
27
28
  disableColumnHiding,
28
- enableColumnGrouping,
29
+ disableFilters,
29
30
  disableSortBy,
31
+ enableColumnGrouping,
30
32
  localization,
31
- } = useMaterialReactTable();
33
+ setShowFilters,
34
+ } = useMRT();
32
35
 
33
36
  const handleClearSort = () => {
34
37
  column.clearSortBy();
@@ -55,6 +58,22 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
55
58
  setAnchorEl(null);
56
59
  };
57
60
 
61
+ const handleFilterByColumn = () => {
62
+ setShowFilters(true);
63
+ setTimeout(
64
+ () =>
65
+ document
66
+ .getElementById(
67
+ // @ts-ignore
68
+ column.muiTableHeadCellFilterTextFieldProps?.id ??
69
+ `filter-${column.id}-column`,
70
+ )
71
+ ?.focus(),
72
+ 200,
73
+ );
74
+ setAnchorEl(null);
75
+ };
76
+
58
77
  return (
59
78
  <Menu
60
79
  anchorEl={anchorEl}
@@ -75,7 +94,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
75
94
  disabled={column.isSorted && !column.isSortedDesc}
76
95
  onClick={handleSortAsc}
77
96
  >
78
- <SortIcon /> {localization?.columnActionMenuItemSortAsc}
97
+ <SortIcon />{' '}
98
+ {localization?.columnActionMenuItemSortAsc?.replace(
99
+ '{column}',
100
+ String(column.Header),
101
+ )}
79
102
  </MenuItem>,
80
103
  <MenuItem
81
104
  key={3}
@@ -83,25 +106,45 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
83
106
  onClick={handleSortDesc}
84
107
  >
85
108
  <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
86
- {localization?.columnActionMenuItemSortDesc}
109
+ {localization?.columnActionMenuItemSortDesc?.replace(
110
+ '{column}',
111
+ String(column.Header),
112
+ )}
113
+ </MenuItem>,
114
+ ]}
115
+ {!disableFilters &&
116
+ column.canFilter && [
117
+ <Divider key={0} />,
118
+ <MenuItem key={1} onClick={handleFilterByColumn}>
119
+ <FilterIcon />{' '}
120
+ {localization?.filterTextFieldPlaceholder?.replace(
121
+ '{column}',
122
+ String(column.Header),
123
+ )}
124
+ </MenuItem>,
125
+ ]}
126
+ {enableColumnGrouping &&
127
+ column.canGroupBy && [
128
+ <Divider key={1} />,
129
+ <MenuItem key={2} onClick={handleGroupByColumn}>
130
+ <DynamicFeedIcon />{' '}
131
+ {localization?.[
132
+ column.isGrouped
133
+ ? 'columnActionMenuItemUnGroupBy'
134
+ : 'columnActionMenuItemGroupBy'
135
+ ]?.replace('{column}', String(column.Header))}
87
136
  </MenuItem>,
88
- <Divider key={4} />,
89
137
  ]}
90
- {!disableColumnHiding && (
91
- <MenuItem onClick={handleHideColumn}>
92
- <VisibilityOffIcon /> {localization?.columnActionMenuItemHideColumn}
93
- </MenuItem>
94
- )}
95
- {enableColumnGrouping && column.canGroupBy && (
96
- <MenuItem disabled={column.isGrouped} onClick={handleGroupByColumn}>
97
- <DynamicFeedIcon /> {localization?.columnActionMenuItemGroupBy}
98
- </MenuItem>
99
- )}
100
- {enableColumnGrouping && column.canGroupBy && (
101
- <MenuItem disabled={!column.isGrouped} onClick={handleGroupByColumn}>
102
- <DynamicFeedIcon /> {localization?.columnActionMenuItemUnGroupBy}
103
- </MenuItem>
104
- )}
138
+ {!disableColumnHiding && [
139
+ <Divider key={0} />,
140
+ <MenuItem key={1} onClick={handleHideColumn}>
141
+ <VisibilityOffIcon />{' '}
142
+ {localization?.columnActionMenuItemHideColumn?.replace(
143
+ '{column}',
144
+ String(column.Header),
145
+ )}
146
+ </MenuItem>,
147
+ ]}
105
148
  </Menu>
106
149
  );
107
150
  };
@@ -1,6 +1,6 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
3
+ import { useMRT } from '../useMRT';
4
4
  import { Row } from 'react-table';
5
5
  import EditIcon from '@mui/icons-material/Edit';
6
6
 
@@ -13,25 +13,21 @@ interface Props {
13
13
  anchorEl: HTMLElement | null;
14
14
  row: Row;
15
15
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
16
+ handleEdit: () => void;
16
17
  }
17
18
 
18
19
  export const MRT_RowActionMenu: FC<Props> = ({
19
20
  anchorEl,
20
21
  row,
22
+ handleEdit,
21
23
  setAnchorEl,
22
24
  }) => {
23
25
  const {
24
26
  enableRowEditing,
25
27
  localization,
26
28
  renderRowActionMenuItems,
27
- setCurrentEditingRow,
28
29
  tableInstance,
29
- } = useMaterialReactTable();
30
-
31
- const handleEdit = () => {
32
- setCurrentEditingRow({ ...row });
33
- setAnchorEl(null);
34
- };
30
+ } = useMRT();
35
31
 
36
32
  return (
37
33
  <Menu
@@ -1,6 +1,5 @@
1
1
  import React, { FC } from 'react';
2
- import { FormControlLabel, MenuItem, Switch, Typography } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
2
+ import { FormControlLabel, MenuItem, Switch } from '@mui/material';
4
3
  import { ColumnInstance } from 'react-table';
5
4
 
6
5
  interface Props {
@@ -8,23 +7,33 @@ interface Props {
8
7
  }
9
8
 
10
9
  export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
11
- const { maxColumnDepth } = useMaterialReactTable();
10
+ const isParentHeader = (column?.columns?.length ?? 0) > 0;
12
11
 
13
- const isMaxDepth = column.depth === maxColumnDepth;
12
+ const allChildColumnsVisible =
13
+ isParentHeader &&
14
+ !!column.columns?.every((childColumn) => childColumn.isVisible);
15
+
16
+ const switchChecked = column.isVisible ?? allChildColumnsVisible;
17
+
18
+ const handleToggleColumnHidden = (column: ColumnInstance) => {
19
+ if (isParentHeader) {
20
+ column?.columns?.forEach?.((childColumn) => {
21
+ childColumn.toggleHidden(switchChecked);
22
+ });
23
+ } else {
24
+ column.toggleHidden();
25
+ }
26
+ };
14
27
 
15
28
  return (
16
29
  <>
17
- <MenuItem style={{ paddingLeft: `${column.depth + 1}rem` }}>
18
- {isMaxDepth ? (
19
- <FormControlLabel
20
- checked={column.isVisible}
21
- control={<Switch />}
22
- label={column.Header as string}
23
- onChange={() => isMaxDepth && column.toggleHidden()}
24
- />
25
- ) : (
26
- <Typography>{column.Header}</Typography>
27
- )}
30
+ <MenuItem style={{ paddingLeft: `${(column.depth + 0.5) * 2}rem` }}>
31
+ <FormControlLabel
32
+ checked={switchChecked}
33
+ control={<Switch />}
34
+ label={column.Header as string}
35
+ onChange={() => handleToggleColumnHidden(column)}
36
+ />
28
37
  </MenuItem>
29
38
  {column.columns?.map((c, i) => (
30
39
  <MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
@@ -3,13 +3,13 @@ import { Table } from '@mui/material';
3
3
  import { MRT_TableHead } from '../head/MRT_TableHead';
4
4
  import { MRT_TableBody } from '../body/MRT_TableBody';
5
5
  import { MRT_TableFooter } from '../footer/MRT_TableFooter';
6
- import { useMaterialReactTable } from '../useMaterialReactTable';
6
+ import { useMRT } from '../useMRT';
7
7
 
8
8
  interface Props {}
9
9
 
10
10
  export const MRT_Table: FC<Props> = () => {
11
11
  const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } =
12
- useMaterialReactTable();
12
+ useMRT();
13
13
 
14
14
  const tableProps = {
15
15
  ...muiTableProps,
@@ -0,0 +1,9 @@
1
+ import { styled, TableCell as MuiTableCell } from '@mui/material';
2
+
3
+ export const MRT_TableButtonCell = styled(MuiTableCell, {
4
+ shouldForwardProp: (prop) => prop !== 'densePadding',
5
+ })<{ densePadding?: boolean }>(({ densePadding }) => ({
6
+ padding: densePadding ? '1px' : '0.6rem',
7
+ textAlign: 'center',
8
+ transition: 'all 0.2s ease-in-out',
9
+ }));
@@ -1,17 +1,32 @@
1
1
  import React, { FC } from 'react';
2
2
  import {
3
- alpha,
4
3
  CircularProgress,
5
4
  LinearProgress,
6
5
  Paper,
6
+ TableContainer as MuiTableContainer,
7
+ alpha,
7
8
  styled,
8
- TableContainer,
9
9
  } from '@mui/material';
10
- import { useMaterialReactTable } from '../useMaterialReactTable';
10
+ import { useMRT } from '../useMRT';
11
11
  import { MRT_Table } from './MRT_Table';
12
12
  import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
13
13
  import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
14
14
 
15
+ const TableContainer = styled(MuiTableContainer, {
16
+ shouldForwardProp: (prop) => prop !== 'fullScreen',
17
+ })<{ fullScreen?: boolean; component?: any }>(({ fullScreen }) => ({
18
+ bottom: fullScreen ? '0' : undefined,
19
+ height: fullScreen ? '100%' : undefined,
20
+ left: fullScreen ? '0' : undefined,
21
+ margin: fullScreen ? '0' : undefined,
22
+ position: fullScreen ? 'absolute' : undefined,
23
+ right: fullScreen ? '0' : undefined,
24
+ top: fullScreen ? '0' : undefined,
25
+ transition: 'all 0.2s ease-in-out',
26
+ width: fullScreen ? '100vw' : undefined,
27
+ zIndex: 1200,
28
+ }));
29
+
15
30
  const CircularProgressWrapper = styled('div')(({ theme }) => ({
16
31
  alignItems: 'center',
17
32
  backgroundColor: alpha(theme.palette.background.paper, 0.5),
@@ -27,15 +42,26 @@ interface Props {}
27
42
 
28
43
  export const MRT_TableContainer: FC<Props> = () => {
29
44
  const {
30
- muiTableContainerProps,
31
- hideToolbarTop,
45
+ fullScreen,
32
46
  hideToolbarBottom,
33
- isLoading,
47
+ hideToolbarTop,
34
48
  isFetching,
35
- } = useMaterialReactTable();
49
+ isLoading,
50
+ muiTableContainerProps,
51
+ tableInstance,
52
+ } = useMRT();
53
+
54
+ const tableContainerProps =
55
+ muiTableContainerProps instanceof Function
56
+ ? muiTableContainerProps(tableInstance)
57
+ : muiTableContainerProps;
36
58
 
37
59
  return (
38
- <TableContainer component={Paper} {...muiTableContainerProps}>
60
+ <TableContainer
61
+ component={Paper}
62
+ fullScreen={fullScreen}
63
+ {...tableContainerProps}
64
+ >
39
65
  {!hideToolbarTop && <MRT_ToolbarTop />}
40
66
  {isFetching && <LinearProgress />}
41
67
  {isLoading && (
@@ -1,13 +1,13 @@
1
1
  import React, { CSSProperties, FC } from 'react';
2
2
  import { TableCell } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
3
+ import { useMRT } from '../useMRT';
4
4
 
5
5
  interface Props {
6
6
  width?: CSSProperties['width'];
7
7
  }
8
8
 
9
9
  export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
10
- const { muiTableBodyCellProps } = useMaterialReactTable();
10
+ const { muiTableBodyCellProps } = useMRT();
11
11
 
12
12
  const mTableBodyCellrops =
13
13
  muiTableBodyCellProps instanceof Function
@@ -1,11 +1,11 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { TablePagination } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
3
+ import { useMRT } from '../useMRT';
4
4
 
5
5
  interface Props {}
6
6
 
7
7
  export const MRT_TablePagination: FC<Props> = () => {
8
- const { tableInstance, muiTablePaginationProps } = useMaterialReactTable();
8
+ const { tableInstance, muiTablePaginationProps } = useMRT();
9
9
 
10
10
  const tablePaginationProps =
11
11
  muiTablePaginationProps instanceof Function
@@ -31,6 +31,7 @@ export const MRT_TablePagination: FC<Props> = () => {
31
31
  showLastButton={
32
32
  tableInstance.rows.length / tableInstance.state.pageSize > 2
33
33
  }
34
+ style={{ padding: 0, position: 'relative', zIndex: 2 }}
34
35
  {...tablePaginationProps}
35
36
  />
36
37
  );