material-react-table 0.3.1 → 0.3.5

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 (72) hide show
  1. package/README.md +32 -162
  2. package/dist/MaterialReactTable.d.ts +17 -7
  3. package/dist/body/MRT_TableBodyCell.d.ts +3 -0
  4. package/dist/body/MRT_TableBodyRow.d.ts +16 -1
  5. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +4 -0
  6. package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
  7. package/dist/head/MRT_TableHeadCell.d.ts +4 -1
  8. package/dist/head/MRT_TableHeadCellActions.d.ts +5 -0
  9. package/dist/inputs/MRT_EditCellTextField.d.ts +7 -0
  10. package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
  11. package/dist/material-react-table.cjs.development.js +799 -441
  12. package/dist/material-react-table.cjs.development.js.map +1 -1
  13. package/dist/material-react-table.cjs.production.min.js +1 -1
  14. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  15. package/dist/material-react-table.esm.js +800 -442
  16. package/dist/material-react-table.esm.js.map +1 -1
  17. package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
  18. package/dist/menus/MRT_RowActionMenu.d.ts +1 -0
  19. package/dist/table/MRT_TableButtonCell.d.ts +3 -0
  20. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +5 -0
  21. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +5 -0
  22. package/dist/useMRT.d.ts +20 -0
  23. package/dist/utils/localization.d.ts +12 -3
  24. package/package.json +26 -23
  25. package/src/@types/faker.d.ts +4 -0
  26. package/src/@types/react-table-config.d.ts +156 -0
  27. package/src/MaterialReactTable.tsx +29 -9
  28. package/src/body/MRT_TableBody.tsx +3 -25
  29. package/src/body/MRT_TableBodyCell.tsx +30 -9
  30. package/src/body/MRT_TableBodyRow.tsx +22 -14
  31. package/src/body/MRT_TableDetailPanel.tsx +19 -8
  32. package/src/buttons/MRT_EditActionButtons.tsx +11 -6
  33. package/src/buttons/MRT_ExpandAllButton.tsx +19 -25
  34. package/src/buttons/MRT_ExpandButton.tsx +28 -26
  35. package/src/buttons/MRT_FullScreenToggleButton.tsx +23 -0
  36. package/src/buttons/MRT_ShowHideColumnsButton.tsx +34 -3
  37. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -5
  38. package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
  39. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +48 -26
  40. package/src/buttons/MRT_ToggleSearchButton.tsx +33 -0
  41. package/src/footer/MRT_TableFooter.tsx +4 -4
  42. package/src/footer/MRT_TableFooterCell.tsx +23 -7
  43. package/src/footer/MRT_TableFooterRow.tsx +9 -4
  44. package/src/head/MRT_TableHead.tsx +4 -4
  45. package/src/head/MRT_TableHeadCell.tsx +41 -20
  46. package/src/head/MRT_TableHeadCellActions.tsx +18 -0
  47. package/src/head/MRT_TableHeadRow.tsx +17 -11
  48. package/src/inputs/MRT_DensePaddingSwitch.tsx +5 -3
  49. package/src/inputs/MRT_EditCellTextField.tsx +64 -0
  50. package/src/inputs/MRT_FilterTextField.tsx +43 -18
  51. package/src/inputs/MRT_SearchTextField.tsx +39 -34
  52. package/src/inputs/MRT_SelectAllCheckbox.tsx +10 -14
  53. package/src/inputs/MRT_SelectCheckbox.tsx +11 -13
  54. package/src/menus/MRT_ColumnActionMenu.tsx +66 -23
  55. package/src/menus/MRT_RowActionMenu.tsx +4 -8
  56. package/src/menus/MRT_ShowHideColumnsMenu.tsx +24 -15
  57. package/src/table/MRT_Table.tsx +2 -2
  58. package/src/table/MRT_TableButtonCell.tsx +9 -0
  59. package/src/table/MRT_TableContainer.tsx +52 -5
  60. package/src/table/MRT_TableSpacerCell.tsx +5 -5
  61. package/src/toolbar/MRT_TablePagination.tsx +3 -2
  62. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +102 -0
  63. package/src/toolbar/MRT_ToolbarBottom.tsx +11 -22
  64. package/src/toolbar/{MRT_ToolbarButtons.tsx → MRT_ToolbarInternalButtons.tsx} +13 -4
  65. package/src/toolbar/MRT_ToolbarTop.tsx +16 -30
  66. package/src/useMRT.tsx +112 -0
  67. package/src/utils/localization.ts +30 -12
  68. package/dist/toolbar/MRT_ToolbarButtons.d.ts +0 -5
  69. package/dist/useMaterialReactTable.d.ts +0 -15
  70. package/dist/utils/useMRTCalcs.d.ts +0 -11
  71. package/src/useMaterialReactTable.tsx +0 -96
  72. package/src/utils/useMRTCalcs.tsx +0 -42
@@ -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
- setCurrentEditingRowId,
28
29
  tableInstance,
29
- } = useMaterialReactTable();
30
-
31
- const handleEdit = () => {
32
- setCurrentEditingRowId(row.id);
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,20 +1,67 @@
1
1
  import React, { FC } from 'react';
2
- import { LinearProgress, Paper, TableContainer } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
2
+ import {
3
+ CircularProgress,
4
+ LinearProgress,
5
+ Paper,
6
+ TableContainer as MuiTableContainer,
7
+ alpha,
8
+ styled,
9
+ } from '@mui/material';
10
+ import { useMRT } from '../useMRT';
4
11
  import { MRT_Table } from './MRT_Table';
5
12
  import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
6
13
  import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
7
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
+ }));
28
+
29
+ const CircularProgressWrapper = styled('div')(({ theme }) => ({
30
+ alignItems: 'center',
31
+ backgroundColor: alpha(theme.palette.background.paper, 0.5),
32
+ display: 'grid',
33
+ height: '100%',
34
+ justifyContent: 'center',
35
+ margin: 'auto',
36
+ position: 'absolute',
37
+ width: 'calc(100% - 2rem)',
38
+ }));
39
+
8
40
  interface Props {}
9
41
 
10
42
  export const MRT_TableContainer: FC<Props> = () => {
11
- const { muiTableContainerProps, hideToolbarTop, hideToolbarBottom, isFetching } =
12
- useMaterialReactTable();
43
+ const {
44
+ muiTableContainerProps,
45
+ hideToolbarTop,
46
+ hideToolbarBottom,
47
+ fullScreen,
48
+ isLoading,
49
+ isFetching,
50
+ } = useMRT();
13
51
 
14
52
  return (
15
- <TableContainer component={Paper} {...muiTableContainerProps}>
53
+ <TableContainer
54
+ component={Paper}
55
+ fullScreen={fullScreen}
56
+ {...muiTableContainerProps}
57
+ >
16
58
  {!hideToolbarTop && <MRT_ToolbarTop />}
17
59
  {isFetching && <LinearProgress />}
60
+ {isLoading && (
61
+ <CircularProgressWrapper>
62
+ <CircularProgress aria-busy="true" aria-label="Loading data" />
63
+ </CircularProgressWrapper>
64
+ )}
18
65
  <MRT_Table />
19
66
  {!hideToolbarBottom && <MRT_ToolbarBottom />}
20
67
  </TableContainer>
@@ -1,24 +1,24 @@
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
- const mTableBodyRowProps =
12
+ const mTableBodyCellrops =
13
13
  muiTableBodyCellProps instanceof Function
14
14
  ? muiTableBodyCellProps()
15
15
  : muiTableBodyCellProps;
16
16
 
17
17
  const tableCellProps = {
18
- ...mTableBodyRowProps,
18
+ ...mTableBodyCellrops,
19
19
  style: {
20
20
  width,
21
- ...(mTableBodyRowProps?.style ?? {}),
21
+ ...(mTableBodyCellrops?.style ?? {}),
22
22
  },
23
23
  };
24
24
 
@@ -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
  );
@@ -0,0 +1,102 @@
1
+ import React, { FC, Fragment } from 'react';
2
+ import {
3
+ Alert as MuiAlert,
4
+ Chip,
5
+ Collapse,
6
+ styled,
7
+ useMediaQuery,
8
+ } from '@mui/material';
9
+ import { useMRT } from '../useMRT';
10
+
11
+ const Alert = styled(MuiAlert, {
12
+ shouldForwardProp: (prop) =>
13
+ prop !== 'displayAbsolute' && prop !== 'toolbarPosition',
14
+ })<{ displayAbsolute?: boolean; toolbarPosition?: 'top' | 'bottom' }>(
15
+ ({ displayAbsolute, toolbarPosition }) => ({
16
+ borderRadius: 0,
17
+ fontSize: '1rem',
18
+ left: 0,
19
+ marginLeft: !displayAbsolute ? '-0.5rem' : undefined,
20
+ padding: toolbarPosition === 'bottom' ? '0 1rem' : '0.5rem 1.25rem',
21
+ position: displayAbsolute ? 'absolute' : 'relative',
22
+ right: 0,
23
+ top: 0,
24
+ width: `calc(100% - ${displayAbsolute ? '2.5rem' : '1.5rem'})`,
25
+ zIndex: 2,
26
+ }),
27
+ );
28
+
29
+ interface Props {}
30
+
31
+ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
32
+ const {
33
+ muiTableToolbarAlertBannerProps,
34
+ tableInstance,
35
+ positionToolbarAlertBanner,
36
+ positionToolbarActions,
37
+ localization,
38
+ renderToolbarCustomActions,
39
+ } = useMRT();
40
+
41
+ const isMobile = useMediaQuery('(max-width:720px)');
42
+
43
+ const alertProps =
44
+ muiTableToolbarAlertBannerProps instanceof Function
45
+ ? muiTableToolbarAlertBannerProps(tableInstance)
46
+ : muiTableToolbarAlertBannerProps;
47
+
48
+ const selectMessage =
49
+ tableInstance.selectedFlatRows.length > 0
50
+ ? localization?.toolbarAlertSelectionMessage
51
+ ?.replace(
52
+ '{selectedCount}',
53
+ tableInstance.selectedFlatRows.length.toString(),
54
+ )
55
+ ?.replace('{rowCount}', tableInstance.flatRows.length.toString())
56
+ : null;
57
+
58
+ const groupedByMessage =
59
+ tableInstance.state.groupBy.length > 0 ? (
60
+ <span>
61
+ {localization?.toolbarAlertGroupedByMessage}{' '}
62
+ {tableInstance.state.groupBy.map((columnId, index) => (
63
+ <Fragment key={`${index}-${columnId}`}>
64
+ {index > 0 ? localization?.toolbarAlertGroupedThenByMessage : ''}
65
+ <Chip
66
+ color="secondary"
67
+ label={
68
+ tableInstance.allColumns.find(
69
+ (column) => column.id === columnId,
70
+ )?.Header
71
+ }
72
+ onDelete={() => tableInstance.toggleGroupBy(columnId, false)}
73
+ />
74
+ </Fragment>
75
+ ))}
76
+ </span>
77
+ ) : null;
78
+
79
+ const displayAbsolute = !(
80
+ isMobile ||
81
+ (positionToolbarAlertBanner === 'bottom' &&
82
+ positionToolbarActions === 'bottom') ||
83
+ (positionToolbarAlertBanner === 'top' && !!renderToolbarCustomActions)
84
+ );
85
+
86
+ return (
87
+ <Collapse
88
+ in={!!selectMessage || !!groupedByMessage}
89
+ timeout={displayAbsolute ? 0 : 200}
90
+ >
91
+ <Alert
92
+ displayAbsolute={displayAbsolute}
93
+ icon={false}
94
+ color="info"
95
+ {...alertProps}
96
+ >
97
+ {selectMessage}
98
+ {groupedByMessage}
99
+ </Alert>
100
+ </Collapse>
101
+ );
102
+ };
@@ -1,41 +1,29 @@
1
1
  import React, { FC } from 'react';
2
2
  import { styled, Toolbar as MuiToolbar } from '@mui/material';
3
- import { useMaterialReactTable } from '../useMaterialReactTable';
3
+ import { useMRT } from '../useMRT';
4
4
  import { MRT_TablePagination } from './MRT_TablePagination';
5
- import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
5
+ import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
6
+ import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
6
7
 
7
8
  const Toolbar = styled(MuiToolbar)({
8
- padding: 0,
9
9
  display: 'flex',
10
10
  justifyContent: 'space-between',
11
+ padding: '0 0.5rem !important',
12
+ overflowY: 'hidden',
11
13
  });
12
14
 
13
15
  interface Props {}
14
16
 
15
17
  export const MRT_ToolbarBottom: FC<Props> = () => {
16
18
  const {
17
- disableGlobalFilter,
18
- disableColumnHiding,
19
+ hideToolbarActions,
19
20
  manualPagination,
21
+ muiTableToolbarBottomProps,
20
22
  positionPagination,
21
- disableFilters,
22
- hideToolbarActions,
23
23
  positionToolbarActions,
24
- muiTableToolbarBottomProps,
25
- title,
24
+ positionToolbarAlertBanner,
26
25
  tableInstance,
27
- } = useMaterialReactTable();
28
-
29
- // if no features in the toolbar are enabled, don't render anything
30
- if (
31
- !muiTableToolbarBottomProps &&
32
- !title &&
33
- disableColumnHiding &&
34
- disableFilters &&
35
- disableGlobalFilter
36
- ) {
37
- return null;
38
- }
26
+ } = useMRT();
39
27
 
40
28
  const toolbarProps =
41
29
  muiTableToolbarBottomProps instanceof Function
@@ -45,10 +33,11 @@ export const MRT_ToolbarBottom: FC<Props> = () => {
45
33
  return (
46
34
  <Toolbar variant="dense" {...toolbarProps}>
47
35
  {!hideToolbarActions && positionToolbarActions === 'bottom' ? (
48
- <MRT_ToolbarButtons />
36
+ <MRT_ToolbarInternalButtons />
49
37
  ) : (
50
38
  <span />
51
39
  )}
40
+ {positionToolbarAlertBanner === 'bottom' && <MRT_ToolbarAlertBanner />}
52
41
  {!manualPagination &&
53
42
  ['bottom', 'both'].includes(positionPagination ?? '') && (
54
43
  <MRT_TablePagination />
@@ -2,8 +2,10 @@ import React, { FC } from 'react';
2
2
  import { styled } from '@mui/material';
3
3
  import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
4
4
  import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
5
- import { useMaterialReactTable } from '../useMaterialReactTable';
5
+ import { useMRT } from '../useMRT';
6
6
  import { MRT_DensePaddingSwitch } from '../inputs/MRT_DensePaddingSwitch';
7
+ import { MRT_ToggleSearchButton } from '../buttons/MRT_ToggleSearchButton';
8
+ import { MRT_FullScreenToggleButton } from '../buttons/MRT_FullScreenToggleButton';
7
9
 
8
10
  const ToolbarButtonsContainer = styled('div')({
9
11
  display: 'flex',
@@ -13,15 +15,22 @@ const ToolbarButtonsContainer = styled('div')({
13
15
 
14
16
  interface Props {}
15
17
 
16
- export const MRT_ToolbarButtons: FC<Props> = () => {
17
- const { disableFilters, disableColumnHiding, disableDensePaddingToggle } =
18
- useMaterialReactTable();
18
+ export const MRT_ToolbarInternalButtons: FC<Props> = () => {
19
+ const {
20
+ disableFilters,
21
+ disableColumnHiding,
22
+ disableDensePaddingToggle,
23
+ disableGlobalFilter,
24
+ disableFullScreenToggle,
25
+ } = useMRT();
19
26
 
20
27
  return (
21
28
  <ToolbarButtonsContainer>
29
+ {!disableGlobalFilter && <MRT_ToggleSearchButton />}
22
30
  {!disableFilters && <MRT_ToggleFiltersButton />}
23
31
  {!disableColumnHiding && <MRT_ShowHideColumnsButton />}
24
32
  {!disableDensePaddingToggle && <MRT_DensePaddingSwitch />}
33
+ {!disableFullScreenToggle && <MRT_FullScreenToggleButton />}
25
34
  </ToolbarButtonsContainer>
26
35
  );
27
36
  };
@@ -1,16 +1,18 @@
1
1
  import React, { FC } from 'react';
2
- import { styled, Toolbar as MuiToolbar, Typography } from '@mui/material';
2
+ import { styled, Toolbar as MuiToolbar } from '@mui/material';
3
3
  import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
4
- import { useMaterialReactTable } from '../useMaterialReactTable';
5
- import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
4
+ import { useMRT } from '../useMRT';
5
+ import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
6
6
  import { MRT_TablePagination } from './MRT_TablePagination';
7
+ import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
7
8
 
8
9
  const Toolbar = styled(MuiToolbar)({
9
10
  display: 'grid',
11
+ padding: '0 0.5rem !important',
10
12
  });
11
13
 
12
14
  const ToolbarTopRow = styled('div')({
13
- padding: '0.5rem',
15
+ padding: '1rem 0.5rem',
14
16
  display: 'flex',
15
17
  justifyContent: 'space-between',
16
18
  });
@@ -18,6 +20,8 @@ const ToolbarTopRow = styled('div')({
18
20
  const ToolbarActionsContainer = styled('div')({
19
21
  display: 'flex',
20
22
  gap: '0.5rem',
23
+ position: 'relative',
24
+ zIndex: 3,
21
25
  });
22
26
 
23
27
  interface Props {}
@@ -25,28 +29,15 @@ interface Props {}
25
29
  export const MRT_ToolbarTop: FC<Props> = () => {
26
30
  const {
27
31
  disableGlobalFilter,
28
- disableColumnHiding,
29
- muiTableTitleProps,
30
- disableFilters,
32
+ hideToolbarActions,
31
33
  manualPagination,
32
- positionPagination,
33
34
  muiTableToolbarTopProps,
34
- hideToolbarActions,
35
+ positionPagination,
35
36
  positionToolbarActions,
36
- title,
37
+ positionToolbarAlertBanner,
38
+ renderToolbarCustomActions,
37
39
  tableInstance,
38
- } = useMaterialReactTable();
39
-
40
- // if no features in the toolbar are enabled, don't render anything
41
- if (
42
- !muiTableToolbarTopProps &&
43
- !title &&
44
- disableColumnHiding &&
45
- disableFilters &&
46
- disableGlobalFilter
47
- ) {
48
- return null;
49
- }
40
+ } = useMRT();
50
41
 
51
42
  const toolbarProps =
52
43
  muiTableToolbarTopProps instanceof Function
@@ -55,18 +46,13 @@ export const MRT_ToolbarTop: FC<Props> = () => {
55
46
 
56
47
  return (
57
48
  <Toolbar variant="dense" {...toolbarProps}>
49
+ {positionToolbarAlertBanner === 'top' && <MRT_ToolbarAlertBanner />}
58
50
  <ToolbarTopRow>
59
- {title ? (
60
- <Typography variant="h5" {...muiTableTitleProps}>
61
- {title}
62
- </Typography>
63
- ) : (
64
- <span />
65
- )}
51
+ {renderToolbarCustomActions?.(tableInstance) ?? <span />}
66
52
  <ToolbarActionsContainer>
67
53
  {!disableGlobalFilter && <MRT_SearchTextField />}
68
54
  {!hideToolbarActions && positionToolbarActions === 'top' && (
69
- <MRT_ToolbarButtons />
55
+ <MRT_ToolbarInternalButtons />
70
56
  )}
71
57
  </ToolbarActionsContainer>
72
58
  </ToolbarTopRow>