material-react-table 0.3.0 → 0.3.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 (61) hide show
  1. package/dist/MaterialReactTable.d.ts +46 -44
  2. package/dist/buttons/MRT_EditActionButtons.d.ts +7 -0
  3. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
  4. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
  5. package/dist/head/MRT_TableHeadCell.d.ts +1 -0
  6. package/dist/index.d.ts +2 -2
  7. package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
  8. package/dist/material-react-table.cjs.development.js +1459 -412
  9. package/dist/material-react-table.cjs.development.js.map +1 -1
  10. package/dist/material-react-table.cjs.production.min.js +1 -1
  11. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  12. package/dist/material-react-table.esm.js +1474 -427
  13. package/dist/material-react-table.esm.js.map +1 -1
  14. package/dist/menus/MRT_RowActionMenu.d.ts +9 -0
  15. package/dist/{footer → toolbar}/MRT_TablePagination.d.ts +0 -0
  16. package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
  17. package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
  18. package/dist/toolbar/{MRT_Toolbar.d.ts → MRT_ToolbarTop.d.ts} +1 -1
  19. package/dist/useMaterialReactTable.d.ts +7 -1
  20. package/dist/utils/localization.d.ts +22 -14
  21. package/package.json +15 -13
  22. package/src/MaterialReactTable.tsx +117 -100
  23. package/src/body/MRT_TableBody.tsx +26 -27
  24. package/src/body/MRT_TableBodyCell.tsx +17 -6
  25. package/src/body/MRT_TableBodyRow.tsx +39 -23
  26. package/src/body/MRT_TableDetailPanel.tsx +38 -14
  27. package/src/buttons/MRT_EditActionButtons.tsx +51 -0
  28. package/src/buttons/MRT_ExpandAllButton.tsx +9 -4
  29. package/src/buttons/MRT_ExpandButton.tsx +12 -6
  30. package/src/buttons/MRT_ShowHideColumnsButton.tsx +12 -12
  31. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +1 -1
  32. package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
  33. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
  34. package/src/footer/MRT_TableFooter.tsx +2 -17
  35. package/src/footer/MRT_TableFooterCell.tsx +18 -7
  36. package/src/footer/MRT_TableFooterRow.tsx +28 -14
  37. package/src/head/MRT_TableHead.tsx +6 -18
  38. package/src/head/MRT_TableHeadCell.tsx +37 -17
  39. package/src/head/MRT_TableHeadRow.tsx +42 -14
  40. package/src/index.tsx +2 -5
  41. package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
  42. package/src/inputs/MRT_FilterTextField.tsx +5 -0
  43. package/src/inputs/MRT_SearchTextField.tsx +4 -4
  44. package/src/inputs/MRT_SelectAllCheckbox.tsx +11 -3
  45. package/src/inputs/MRT_SelectCheckbox.tsx +9 -2
  46. package/src/menus/MRT_ColumnActionMenu.tsx +29 -24
  47. package/src/menus/MRT_RowActionMenu.tsx +52 -0
  48. package/src/menus/MRT_ShowHideColumnsMenu.tsx +2 -2
  49. package/src/table/MRT_Table.tsx +13 -4
  50. package/src/table/MRT_TableContainer.tsx +9 -5
  51. package/src/table/MRT_TableSpacerCell.tsx +17 -1
  52. package/src/toolbar/MRT_TablePagination.tsx +37 -0
  53. package/src/toolbar/MRT_ToolbarBottom.tsx +58 -0
  54. package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
  55. package/src/toolbar/MRT_ToolbarTop.tsx +81 -0
  56. package/src/useMaterialReactTable.tsx +36 -32
  57. package/src/utils/localization.ts +32 -16
  58. package/dist/utils/overrideWarnings.d.ts +0 -1
  59. package/src/footer/MRT_TablePagination.tsx +0 -42
  60. package/src/toolbar/MRT_Toolbar.tsx +0 -39
  61. package/src/utils/overrideWarnings.ts +0 -41
@@ -1,11 +1,10 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { TableRow } from '@mui/material';
3
3
  import { HeaderGroup } from 'react-table';
4
- import { MRT_TableHeadCell } from './MRT_TableHeadCell';
4
+ import { MRT_TableHeadCell, StyledTableHeadCell } from './MRT_TableHeadCell';
5
5
  import { useMaterialReactTable } from '../useMaterialReactTable';
6
6
  import { MRT_SelectAllCheckbox } from '../inputs/MRT_SelectAllCheckbox';
7
7
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
8
- import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
9
8
  import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
10
9
 
11
10
  interface Props {
@@ -14,28 +13,49 @@ interface Props {
14
13
 
15
14
  export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
16
15
  const {
17
- overrideTableHeadRowComponent,
18
16
  anyRowsCanExpand,
19
- enableColumnHiding,
20
- enableExpandAll,
17
+ disableExpandAll,
18
+ enableRowActions,
21
19
  enableSelection,
20
+ localization,
21
+ muiTableHeadRowProps,
22
+ positionActionsColumn,
22
23
  renderDetailPanel,
23
24
  tableInstance,
24
25
  } = useMaterialReactTable();
25
26
 
26
- if (overrideTableHeadRowComponent) {
27
- return <>{overrideTableHeadRowComponent(headerGroup, tableInstance)}</>;
28
- }
29
-
30
27
  const isParentHeader = useMemo(
31
28
  () => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
32
29
  [headerGroup.headers],
33
30
  );
34
31
 
32
+ const mTableHeadRowProps =
33
+ muiTableHeadRowProps instanceof Function
34
+ ? muiTableHeadRowProps(headerGroup)
35
+ : muiTableHeadRowProps;
36
+
37
+ const tableRowProps = {
38
+ ...mTableHeadRowProps,
39
+ ...headerGroup.getHeaderGroupProps(),
40
+ style: {
41
+ ...headerGroup.getHeaderGroupProps().style,
42
+ ...(mTableHeadRowProps?.style ?? {}),
43
+ },
44
+ };
45
+
35
46
  return (
36
- <TableRow {...headerGroup.getHeaderGroupProps()}>
47
+ <TableRow {...tableRowProps}>
48
+ {enableRowActions &&
49
+ positionActionsColumn === 'first' &&
50
+ (isParentHeader ? (
51
+ <MRT_TableSpacerCell />
52
+ ) : (
53
+ <StyledTableHeadCell>
54
+ {localization?.actionsHeadColumnTitle}
55
+ </StyledTableHeadCell>
56
+ ))}
37
57
  {anyRowsCanExpand || renderDetailPanel ? (
38
- enableExpandAll && !isParentHeader ? (
58
+ !disableExpandAll && !isParentHeader ? (
39
59
  <MRT_ExpandAllButton />
40
60
  ) : (
41
61
  <MRT_TableSpacerCell
@@ -52,10 +72,18 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
52
72
  <MRT_TableSpacerCell width="1rem" />
53
73
  )
54
74
  ) : null}
55
- {headerGroup.headers.map((column, index) => (
56
- <MRT_TableHeadCell key={`${index}-${column.id}`} column={column} />
75
+ {headerGroup.headers.map((column) => (
76
+ <MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
57
77
  ))}
58
- {enableColumnHiding && !isParentHeader && <MRT_ShowHideColumnsButton />}
78
+ {enableRowActions &&
79
+ positionActionsColumn === 'last' &&
80
+ (isParentHeader ? (
81
+ <MRT_TableSpacerCell />
82
+ ) : (
83
+ <StyledTableHeadCell>
84
+ {localization?.actionsHeadColumnTitle}
85
+ </StyledTableHeadCell>
86
+ ))}
59
87
  </TableRow>
60
88
  );
61
89
  };
package/src/index.tsx CHANGED
@@ -1,6 +1,3 @@
1
- import {
2
- MaterialReactTable,
3
- MaterialReactTableProps,
4
- } from './MaterialReactTable';
1
+ import MaterialReactTable from './MaterialReactTable';
5
2
  export default MaterialReactTable;
6
- export type { MaterialReactTableProps };
3
+ export * from './MaterialReactTable';
@@ -0,0 +1,21 @@
1
+ import React, { FC } from 'react';
2
+ import { Switch, Tooltip } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+
5
+ interface Props {}
6
+
7
+ export const MRT_DensePaddingSwitch: FC<Props> = () => {
8
+ const { densePadding, setDensePadding, localization } =
9
+ useMaterialReactTable();
10
+
11
+ return (
12
+ <Tooltip arrow title={localization?.toggleDensePaddingSwitchTitle ?? ''}>
13
+ <Switch
14
+ color="default"
15
+ checked={densePadding}
16
+ size="small"
17
+ onChange={() => setDensePadding(!densePadding)}
18
+ />
19
+ </Tooltip>
20
+ );
21
+ };
@@ -23,6 +23,11 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
23
23
  column.setFilter(undefined);
24
24
  };
25
25
 
26
+ if (column.Filter) {
27
+ //@ts-ignore
28
+ return <>{column.Filter({ column })}</>;
29
+ }
30
+
26
31
  return (
27
32
  <TextField
28
33
  margin="dense"
@@ -19,9 +19,9 @@ interface Props {}
19
19
  export const MRT_SearchTextField: FC<Props> = () => {
20
20
  const {
21
21
  tableInstance,
22
- tableSearchTextfieldProps,
22
+ muiSearchTextFieldProps,
23
23
  localization,
24
- onSearchChange,
24
+ onGlobalFilterChange,
25
25
  } = useMaterialReactTable();
26
26
 
27
27
  const [searchValue, setSearchValue] = useState('');
@@ -29,7 +29,7 @@ export const MRT_SearchTextField: FC<Props> = () => {
29
29
  const handleChange = useAsyncDebounce(
30
30
  (event: ChangeEvent<HTMLInputElement>) => {
31
31
  tableInstance.setGlobalFilter(event.target.value ?? undefined);
32
- onSearchChange?.(event);
32
+ onGlobalFilterChange?.(event);
33
33
  },
34
34
  200,
35
35
  );
@@ -68,7 +68,7 @@ export const MRT_SearchTextField: FC<Props> = () => {
68
68
  </InputAdornment>
69
69
  ),
70
70
  }}
71
- {...tableSearchTextfieldProps}
71
+ {...muiSearchTextFieldProps}
72
72
  />
73
73
  );
74
74
  };
@@ -3,11 +3,19 @@ import { Checkbox, TableCell } from '@mui/material';
3
3
  import { useMaterialReactTable } from '../useMaterialReactTable';
4
4
 
5
5
  export const MRT_SelectAllCheckbox = () => {
6
- const { tableInstance, enableSelectAll } = useMaterialReactTable();
6
+ const { tableInstance, disableSelectAll, densePadding } =
7
+ useMaterialReactTable();
7
8
 
8
9
  return (
9
- <TableCell style={{ width: '2rem', padding: '0.5rem' }} variant="head">
10
- {enableSelectAll ? (
10
+ <TableCell
11
+ style={{
12
+ width: '2rem',
13
+ padding: densePadding ? '0' : '0.6rem',
14
+ transition: 'all 0.2s ease-in-out',
15
+ }}
16
+ variant="head"
17
+ >
18
+ {!disableSelectAll ? (
11
19
  <Checkbox
12
20
  aria-label=""
13
21
  {...tableInstance.getToggleAllPageRowsSelectedProps()}
@@ -8,7 +8,8 @@ interface Props {
8
8
  }
9
9
 
10
10
  export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
11
- const { tableInstance, onRowSelectChange } = useMaterialReactTable();
11
+ const { tableInstance, onRowSelectChange, densePadding } =
12
+ useMaterialReactTable();
12
13
 
13
14
  const onSelectChange = (event: ChangeEvent) => {
14
15
  row.getToggleRowSelectedProps()?.onChange?.(event);
@@ -16,7 +17,13 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
16
17
  };
17
18
 
18
19
  return (
19
- <TableCell style={{ width: '2rem', padding: '0.5rem' }}>
20
+ <TableCell
21
+ style={{
22
+ width: '2rem',
23
+ padding: densePadding ? '0' : '0.6rem',
24
+ transition: 'all 0.2s ease-in-out',
25
+ }}
26
+ >
20
27
  <Checkbox
21
28
  {...row.getToggleRowSelectedProps()}
22
29
  onChange={onSelectChange}
@@ -24,9 +24,9 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
24
24
  setAnchorEl,
25
25
  }) => {
26
26
  const {
27
- enableColumnHiding,
27
+ disableColumnHiding,
28
28
  enableColumnGrouping,
29
- enableSorting,
29
+ disableSortBy,
30
30
  localization,
31
31
  } = useMaterialReactTable();
32
32
 
@@ -61,28 +61,33 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
61
61
  open={!!anchorEl}
62
62
  onClose={() => setAnchorEl(null)}
63
63
  >
64
- {enableSorting && [
65
- <MenuItem key={1} disabled={!column.isSorted} onClick={handleClearSort}>
66
- <ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
67
- </MenuItem>,
68
- <MenuItem
69
- key={2}
70
- disabled={column.isSorted && !column.isSortedDesc}
71
- onClick={handleSortAsc}
72
- >
73
- <SortIcon /> {localization?.columnActionMenuItemSortAsc}
74
- </MenuItem>,
75
- <MenuItem
76
- key={3}
77
- disabled={column.isSorted && column.isSortedDesc}
78
- onClick={handleSortDesc}
79
- >
80
- <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
81
- {localization?.columnActionMenuItemSortDesc}
82
- </MenuItem>,
83
- <Divider key={4} />,
84
- ]}
85
- {enableColumnHiding && (
64
+ {!disableSortBy &&
65
+ column.canSort && [
66
+ <MenuItem
67
+ key={1}
68
+ disabled={!column.isSorted}
69
+ onClick={handleClearSort}
70
+ >
71
+ <ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
72
+ </MenuItem>,
73
+ <MenuItem
74
+ key={2}
75
+ disabled={column.isSorted && !column.isSortedDesc}
76
+ onClick={handleSortAsc}
77
+ >
78
+ <SortIcon /> {localization?.columnActionMenuItemSortAsc}
79
+ </MenuItem>,
80
+ <MenuItem
81
+ key={3}
82
+ disabled={column.isSorted && column.isSortedDesc}
83
+ onClick={handleSortDesc}
84
+ >
85
+ <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
86
+ {localization?.columnActionMenuItemSortDesc}
87
+ </MenuItem>,
88
+ <Divider key={4} />,
89
+ ]}
90
+ {!disableColumnHiding && (
86
91
  <MenuItem onClick={handleHideColumn}>
87
92
  <VisibilityOffIcon /> {localization?.columnActionMenuItemHideColumn}
88
93
  </MenuItem>
@@ -0,0 +1,52 @@
1
+ import React, { FC } from 'react';
2
+ import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import { Row } from 'react-table';
5
+ import EditIcon from '@mui/icons-material/Edit';
6
+
7
+ const MenuItem = styled(MuiMenuItem)({
8
+ display: 'flex',
9
+ gap: '0.75rem',
10
+ });
11
+
12
+ interface Props {
13
+ anchorEl: HTMLElement | null;
14
+ row: Row;
15
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
16
+ }
17
+
18
+ export const MRT_RowActionMenu: FC<Props> = ({
19
+ anchorEl,
20
+ row,
21
+ setAnchorEl,
22
+ }) => {
23
+ const {
24
+ enableRowEditing,
25
+ localization,
26
+ renderRowActionMenuItems,
27
+ setCurrentEditingRowId,
28
+ tableInstance,
29
+ } = useMaterialReactTable();
30
+
31
+ const handleEdit = () => {
32
+ setCurrentEditingRowId(row.id);
33
+ setAnchorEl(null);
34
+ };
35
+
36
+ return (
37
+ <Menu
38
+ anchorEl={anchorEl}
39
+ open={!!anchorEl}
40
+ onClose={() => setAnchorEl(null)}
41
+ >
42
+ {enableRowEditing && (
43
+ <MenuItem onClick={handleEdit}>
44
+ <EditIcon /> {localization?.rowActionMenuItemEdit}
45
+ </MenuItem>
46
+ )}
47
+ {renderRowActionMenuItems?.(row, tableInstance, () =>
48
+ setAnchorEl(null),
49
+ ) ?? null}
50
+ </Menu>
51
+ );
52
+ };
@@ -17,10 +17,10 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
17
17
  <MenuItem style={{ paddingLeft: `${column.depth + 1}rem` }}>
18
18
  {isMaxDepth ? (
19
19
  <FormControlLabel
20
- onChange={() => isMaxDepth && column.toggleHidden()}
21
- label={column.Header as string}
22
20
  checked={column.isVisible}
23
21
  control={<Switch />}
22
+ label={column.Header as string}
23
+ onChange={() => isMaxDepth && column.toggleHidden()}
24
24
  />
25
25
  ) : (
26
26
  <Typography>{column.Header}</Typography>
@@ -8,14 +8,23 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
8
8
  interface Props {}
9
9
 
10
10
  export const MRT_Table: FC<Props> = () => {
11
- const { tableInstance, tableProps, showHead, showFooter } =
11
+ const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } =
12
12
  useMaterialReactTable();
13
13
 
14
+ const tableProps = {
15
+ ...muiTableProps,
16
+ ...tableInstance.getTableProps(),
17
+ style: {
18
+ ...tableInstance.getTableProps().style,
19
+ ...(muiTableProps?.style ?? {}),
20
+ },
21
+ };
22
+
14
23
  return (
15
- <Table {...tableProps} {...tableInstance.getTableProps()}>
16
- {showHead && <MRT_TableHead />}
24
+ <Table {...tableProps}>
25
+ {!hideTableHead && <MRT_TableHead />}
17
26
  <MRT_TableBody />
18
- {showFooter && <MRT_TableFooter />}
27
+ {!hideTableFooter && <MRT_TableFooter />}
19
28
  </Table>
20
29
  );
21
30
  };
@@ -1,18 +1,22 @@
1
1
  import React, { FC } from 'react';
2
- import { Paper, TableContainer } from '@mui/material';
2
+ import { LinearProgress, Paper, TableContainer } from '@mui/material';
3
3
  import { useMaterialReactTable } from '../useMaterialReactTable';
4
4
  import { MRT_Table } from './MRT_Table';
5
- import { MRT_Toolbar } from '../toolbar/MRT_Toolbar';
5
+ import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
6
+ import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
6
7
 
7
8
  interface Props {}
8
9
 
9
10
  export const MRT_TableContainer: FC<Props> = () => {
10
- const { tableContainerProps, showToolbar } = useMaterialReactTable();
11
+ const { muiTableContainerProps, hideToolbarTop, hideToolbarBottom, isFetching } =
12
+ useMaterialReactTable();
11
13
 
12
14
  return (
13
- <TableContainer component={Paper} {...tableContainerProps}>
14
- {showToolbar && <MRT_Toolbar />}
15
+ <TableContainer component={Paper} {...muiTableContainerProps}>
16
+ {!hideToolbarTop && <MRT_ToolbarTop />}
17
+ {isFetching && <LinearProgress />}
15
18
  <MRT_Table />
19
+ {!hideToolbarBottom && <MRT_ToolbarBottom />}
16
20
  </TableContainer>
17
21
  );
18
22
  };
@@ -1,10 +1,26 @@
1
1
  import React, { CSSProperties, FC } from 'react';
2
2
  import { TableCell } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
3
4
 
4
5
  interface Props {
5
6
  width?: CSSProperties['width'];
6
7
  }
7
8
 
8
9
  export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
9
- return <TableCell style={{ width }} />;
10
+ const { muiTableBodyCellProps } = useMaterialReactTable();
11
+
12
+ const mTableBodyRowProps =
13
+ muiTableBodyCellProps instanceof Function
14
+ ? muiTableBodyCellProps()
15
+ : muiTableBodyCellProps;
16
+
17
+ const tableCellProps = {
18
+ ...mTableBodyRowProps,
19
+ style: {
20
+ width,
21
+ ...(mTableBodyRowProps?.style ?? {}),
22
+ },
23
+ };
24
+
25
+ return <TableCell {...tableCellProps} />;
10
26
  };
@@ -0,0 +1,37 @@
1
+ import React, { ChangeEvent, FC } from 'react';
2
+ import { TablePagination } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+
5
+ interface Props {}
6
+
7
+ export const MRT_TablePagination: FC<Props> = () => {
8
+ const { tableInstance, muiTablePaginationProps } = useMaterialReactTable();
9
+
10
+ const tablePaginationProps =
11
+ muiTablePaginationProps instanceof Function
12
+ ? muiTablePaginationProps(tableInstance)
13
+ : muiTablePaginationProps;
14
+
15
+ const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
16
+ tableInstance.setPageSize(+event.target.value);
17
+ tableInstance.gotoPage(0);
18
+ };
19
+
20
+ return (
21
+ <TablePagination
22
+ component={'div'}
23
+ count={tableInstance.rows.length}
24
+ onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
25
+ onRowsPerPageChange={handleChangeRowsPerPage}
26
+ page={tableInstance.state.pageIndex}
27
+ rowsPerPage={tableInstance.state.pageSize}
28
+ showFirstButton={
29
+ tableInstance.rows.length / tableInstance.state.pageSize > 2
30
+ }
31
+ showLastButton={
32
+ tableInstance.rows.length / tableInstance.state.pageSize > 2
33
+ }
34
+ {...tablePaginationProps}
35
+ />
36
+ );
37
+ };
@@ -0,0 +1,58 @@
1
+ import React, { FC } from 'react';
2
+ import { styled, Toolbar as MuiToolbar } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import { MRT_TablePagination } from './MRT_TablePagination';
5
+ import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
6
+
7
+ const Toolbar = styled(MuiToolbar)({
8
+ padding: 0,
9
+ display: 'flex',
10
+ justifyContent: 'space-between',
11
+ });
12
+
13
+ interface Props {}
14
+
15
+ export const MRT_ToolbarBottom: FC<Props> = () => {
16
+ const {
17
+ disableGlobalFilter,
18
+ disableColumnHiding,
19
+ manualPagination,
20
+ positionPagination,
21
+ disableFilters,
22
+ hideToolbarActions,
23
+ positionToolbarActions,
24
+ muiTableToolbarBottomProps,
25
+ title,
26
+ 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
+ }
39
+
40
+ const toolbarProps =
41
+ muiTableToolbarBottomProps instanceof Function
42
+ ? muiTableToolbarBottomProps(tableInstance)
43
+ : muiTableToolbarBottomProps;
44
+
45
+ return (
46
+ <Toolbar variant="dense" {...toolbarProps}>
47
+ {!hideToolbarActions && positionToolbarActions === 'bottom' ? (
48
+ <MRT_ToolbarButtons />
49
+ ) : (
50
+ <span />
51
+ )}
52
+ {!manualPagination &&
53
+ ['bottom', 'both'].includes(positionPagination ?? '') && (
54
+ <MRT_TablePagination />
55
+ )}
56
+ </Toolbar>
57
+ );
58
+ };
@@ -0,0 +1,27 @@
1
+ import React, { FC } from 'react';
2
+ import { styled } from '@mui/material';
3
+ import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
4
+ import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
5
+ import { useMaterialReactTable } from '../useMaterialReactTable';
6
+ import { MRT_DensePaddingSwitch } from '../inputs/MRT_DensePaddingSwitch';
7
+
8
+ const ToolbarButtonsContainer = styled('div')({
9
+ display: 'flex',
10
+ gap: '0.5rem',
11
+ alignItems: 'center',
12
+ });
13
+
14
+ interface Props {}
15
+
16
+ export const MRT_ToolbarButtons: FC<Props> = () => {
17
+ const { disableFilters, disableColumnHiding, disableDensePaddingToggle } =
18
+ useMaterialReactTable();
19
+
20
+ return (
21
+ <ToolbarButtonsContainer>
22
+ {!disableFilters && <MRT_ToggleFiltersButton />}
23
+ {!disableColumnHiding && <MRT_ShowHideColumnsButton />}
24
+ {!disableDensePaddingToggle && <MRT_DensePaddingSwitch />}
25
+ </ToolbarButtonsContainer>
26
+ );
27
+ };
@@ -0,0 +1,81 @@
1
+ import React, { FC } from 'react';
2
+ import { styled, Toolbar as MuiToolbar, Typography } from '@mui/material';
3
+ import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+ import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
6
+ import { MRT_TablePagination } from './MRT_TablePagination';
7
+
8
+ const Toolbar = styled(MuiToolbar)({
9
+ display: 'grid',
10
+ });
11
+
12
+ const ToolbarTopRow = styled('div')({
13
+ padding: '0.5rem',
14
+ display: 'flex',
15
+ justifyContent: 'space-between',
16
+ });
17
+
18
+ const ToolbarActionsContainer = styled('div')({
19
+ display: 'flex',
20
+ gap: '0.5rem',
21
+ });
22
+
23
+ interface Props {}
24
+
25
+ export const MRT_ToolbarTop: FC<Props> = () => {
26
+ const {
27
+ disableGlobalFilter,
28
+ disableColumnHiding,
29
+ muiTableTitleProps,
30
+ disableFilters,
31
+ manualPagination,
32
+ positionPagination,
33
+ muiTableToolbarTopProps,
34
+ hideToolbarActions,
35
+ positionToolbarActions,
36
+ title,
37
+ 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
+ }
50
+
51
+ const toolbarProps =
52
+ muiTableToolbarTopProps instanceof Function
53
+ ? muiTableToolbarTopProps(tableInstance)
54
+ : muiTableToolbarTopProps;
55
+
56
+ return (
57
+ <Toolbar variant="dense" {...toolbarProps}>
58
+ <ToolbarTopRow>
59
+ {title ? (
60
+ <Typography variant="h5" {...muiTableTitleProps}>
61
+ {title}
62
+ </Typography>
63
+ ) : (
64
+ <span />
65
+ )}
66
+ <ToolbarActionsContainer>
67
+ {!disableGlobalFilter && <MRT_SearchTextField />}
68
+ {!hideToolbarActions && positionToolbarActions === 'top' && (
69
+ <MRT_ToolbarButtons />
70
+ )}
71
+ </ToolbarActionsContainer>
72
+ </ToolbarTopRow>
73
+ <div>
74
+ {!manualPagination &&
75
+ ['top', 'both'].includes(positionPagination ?? '') && (
76
+ <MRT_TablePagination />
77
+ )}
78
+ </div>
79
+ </Toolbar>
80
+ );
81
+ };