material-react-table 0.1.0 → 0.2.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 (78) hide show
  1. package/dist/MaterialReactTable.d.ts +51 -20
  2. package/dist/{MRT_TableBody.d.ts → body/MRT_TableBody.d.ts} +0 -0
  3. package/dist/{MRT_TableBodyCell.d.ts → body/MRT_TableBodyCell.d.ts} +1 -1
  4. package/dist/{MRT_TableBodyRow.d.ts → body/MRT_TableBodyRow.d.ts} +1 -1
  5. package/dist/{MRT_TableDetailPanel.d.ts → body/MRT_TableDetailPanel.d.ts} +1 -1
  6. package/dist/buttons/MRT_ExpandAllButton.d.ts +5 -0
  7. package/dist/{MRT_TableExpandButton.d.ts → buttons/MRT_ExpandButton.d.ts} +2 -2
  8. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +5 -0
  9. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +7 -0
  10. package/dist/{MRT_TableFooter.d.ts → footer/MRT_TableFooter.d.ts} +0 -0
  11. package/dist/{MRT_TableFooterCell.d.ts → footer/MRT_TableFooterCell.d.ts} +0 -0
  12. package/dist/{MRT_TableFooterRow.d.ts → footer/MRT_TableFooterRow.d.ts} +1 -1
  13. package/dist/{MRT_TablePagination.d.ts → footer/MRT_TablePagination.d.ts} +0 -0
  14. package/dist/{MRT_TableHead.d.ts → head/MRT_TableHead.d.ts} +0 -0
  15. package/dist/{MRT_TableHeadCell.d.ts → head/MRT_TableHeadCell.d.ts} +1 -0
  16. package/dist/{MRT_TableHeadRow.d.ts → head/MRT_TableHeadRow.d.ts} +1 -1
  17. package/dist/inputs/MRT_FilterTextField.d.ts +7 -0
  18. package/dist/inputs/MRT_SearchTextField.d.ts +5 -0
  19. package/dist/inputs/MRT_SelectAllCheckbox.d.ts +2 -0
  20. package/dist/inputs/MRT_SelectCheckbox.d.ts +7 -0
  21. package/dist/material-react-table.cjs.development.js +755 -82
  22. package/dist/material-react-table.cjs.development.js.map +1 -1
  23. package/dist/material-react-table.cjs.production.min.js +1 -1
  24. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  25. package/dist/material-react-table.esm.js +759 -86
  26. package/dist/material-react-table.esm.js.map +1 -1
  27. package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -0
  28. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +7 -0
  29. package/dist/{MRT_Table.d.ts → table/MRT_Table.d.ts} +0 -0
  30. package/dist/{MRT_TableContainer.d.ts → table/MRT_TableContainer.d.ts} +0 -0
  31. package/dist/table/MRT_TableSpacerCell.d.ts +6 -0
  32. package/dist/toolbar/MRT_Toolbar.d.ts +5 -0
  33. package/dist/useMaterialReactTable.d.ts +7 -10
  34. package/dist/utils/localization.d.ts +15 -0
  35. package/dist/utils/overrideWarnings.d.ts +1 -0
  36. package/dist/utils/useMRTCalcs.d.ts +11 -0
  37. package/package.json +13 -11
  38. package/src/MaterialReactTable.tsx +117 -31
  39. package/src/body/MRT_TableBody.tsx +57 -0
  40. package/src/{MRT_TableBodyCell.tsx → body/MRT_TableBodyCell.tsx} +11 -1
  41. package/src/body/MRT_TableBodyRow.tsx +56 -0
  42. package/src/{MRT_TableDetailPanel.tsx → body/MRT_TableDetailPanel.tsx} +15 -4
  43. package/src/buttons/MRT_ExpandAllButton.tsx +40 -0
  44. package/src/buttons/MRT_ExpandButton.tsx +39 -0
  45. package/src/buttons/MRT_ShowHideColumnsButton.tsx +43 -0
  46. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +49 -0
  47. package/src/footer/MRT_TableFooter.tsx +36 -0
  48. package/src/{MRT_TableFooterCell.tsx → footer/MRT_TableFooterCell.tsx} +8 -0
  49. package/src/footer/MRT_TableFooterRow.tsx +44 -0
  50. package/src/{MRT_TablePagination.tsx → footer/MRT_TablePagination.tsx} +7 -2
  51. package/src/head/MRT_TableHead.tsx +38 -0
  52. package/src/head/MRT_TableHeadCell.tsx +94 -0
  53. package/src/head/MRT_TableHeadRow.tsx +63 -0
  54. package/src/inputs/MRT_FilterTextField.tsx +59 -0
  55. package/src/inputs/MRT_SearchTextField.tsx +65 -0
  56. package/src/inputs/MRT_SelectAllCheckbox.tsx +15 -0
  57. package/src/inputs/MRT_SelectCheckbox.tsx +26 -0
  58. package/src/menus/MRT_ColumnActionMenu.tsx +82 -0
  59. package/src/menus/MRT_ShowHideColumnsMenu.tsx +34 -0
  60. package/src/table/MRT_Table.tsx +21 -0
  61. package/src/{MRT_TableContainer.tsx → table/MRT_TableContainer.tsx} +4 -2
  62. package/src/table/MRT_TableSpacerCell.tsx +10 -0
  63. package/src/toolbar/MRT_Toolbar.tsx +39 -0
  64. package/src/useMaterialReactTable.tsx +45 -23
  65. package/src/utils/localization.ts +29 -0
  66. package/src/utils/overrideWarnings.ts +41 -0
  67. package/src/utils/useMRTCalcs.tsx +42 -0
  68. package/dist/defaults.d.ts +0 -2
  69. package/src/MRT_Table.tsx +0 -20
  70. package/src/MRT_TableBody.tsx +0 -19
  71. package/src/MRT_TableBodyRow.tsx +0 -27
  72. package/src/MRT_TableExpandButton.tsx +0 -25
  73. package/src/MRT_TableFooter.tsx +0 -31
  74. package/src/MRT_TableFooterRow.tsx +0 -22
  75. package/src/MRT_TableHead.tsx +0 -25
  76. package/src/MRT_TableHeadCell.tsx +0 -27
  77. package/src/MRT_TableHeadRow.tsx +0 -22
  78. package/src/defaults.ts +0 -11
@@ -0,0 +1,59 @@
1
+ import React, { ChangeEvent, FC, useState } from 'react';
2
+ import { IconButton, InputAdornment, TextField } from '@mui/material';
3
+ import CloseIcon from '@mui/icons-material/Close';
4
+ import FilterIcon from '@mui/icons-material/FilterList';
5
+ import { HeaderGroup, useAsyncDebounce } from 'react-table';
6
+ import { useMaterialReactTable } from '../useMaterialReactTable';
7
+
8
+ interface Props {
9
+ column: HeaderGroup;
10
+ }
11
+
12
+ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
13
+ const { localization } = useMaterialReactTable();
14
+
15
+ const [filterValue, setFilterValue] = useState('');
16
+
17
+ const handleChange = useAsyncDebounce((value) => {
18
+ column.setFilter(value ?? undefined);
19
+ }, 150);
20
+
21
+ const handleClear = () => {
22
+ setFilterValue('');
23
+ column.setFilter(undefined);
24
+ };
25
+
26
+ return (
27
+ <TextField
28
+ margin="dense"
29
+ placeholder={localization?.filterTextFieldPlaceholder}
30
+ onChange={(e: ChangeEvent<HTMLInputElement>) => {
31
+ setFilterValue(e.target.value);
32
+ handleChange(e.target.value);
33
+ }}
34
+ onClick={(e) => e.stopPropagation()}
35
+ value={filterValue ?? ''}
36
+ variant="standard"
37
+ InputProps={{
38
+ startAdornment: (
39
+ <InputAdornment position="start">
40
+ <FilterIcon />
41
+ </InputAdornment>
42
+ ),
43
+ endAdornment: (
44
+ <InputAdornment position="end">
45
+ <IconButton
46
+ aria-label={localization?.filterTextFieldClearButtonTitle}
47
+ disabled={filterValue?.length === 0}
48
+ onClick={handleClear}
49
+ size="small"
50
+ title={localization?.filterTextFieldClearButtonTitle}
51
+ >
52
+ <CloseIcon fontSize="small" />
53
+ </IconButton>
54
+ </InputAdornment>
55
+ ),
56
+ }}
57
+ />
58
+ );
59
+ };
@@ -0,0 +1,65 @@
1
+ import React, { ChangeEvent, FC, useState } from 'react';
2
+ import {
3
+ IconButton,
4
+ InputAdornment,
5
+ styled,
6
+ TextField as MuiTextField,
7
+ } from '@mui/material';
8
+ import SearchIcon from '@mui/icons-material/Search';
9
+ import CloseIcon from '@mui/icons-material/Close';
10
+ import { useMaterialReactTable } from '../useMaterialReactTable';
11
+ import { useAsyncDebounce } from 'react-table';
12
+
13
+ const TextField = styled(MuiTextField)({
14
+ justifySelf: 'end',
15
+ });
16
+
17
+ interface Props {}
18
+
19
+ export const MRT_SearchTextField: FC<Props> = () => {
20
+ const { tableInstance, tableSearchTextfieldProps, localization } = useMaterialReactTable();
21
+
22
+ const [searchValue, setSearchValue] = useState('');
23
+
24
+ const handleChange = useAsyncDebounce((value) => {
25
+ tableInstance.setGlobalFilter(value ?? undefined);
26
+ }, 200);
27
+
28
+ const handleClear = () => {
29
+ setSearchValue('');
30
+ tableInstance.setGlobalFilter(undefined);
31
+ };
32
+
33
+ return (
34
+ <TextField
35
+ placeholder={localization?.searchTextFieldPlaceholder}
36
+ onChange={(e: ChangeEvent<HTMLInputElement>) => {
37
+ setSearchValue(e.target.value);
38
+ handleChange(e.target.value);
39
+ }}
40
+ value={searchValue ?? ''}
41
+ variant="standard"
42
+ InputProps={{
43
+ startAdornment: (
44
+ <InputAdornment position="start">
45
+ <SearchIcon fontSize="small" />
46
+ </InputAdornment>
47
+ ),
48
+ endAdornment: (
49
+ <InputAdornment position="end">
50
+ <IconButton
51
+ aria-label={localization?.searchTextFieldClearButtonTitle}
52
+ disabled={searchValue?.length === 0}
53
+ onClick={handleClear}
54
+ size="small"
55
+ title={localization?.searchTextFieldClearButtonTitle}
56
+ >
57
+ <CloseIcon fontSize="small" />
58
+ </IconButton>
59
+ </InputAdornment>
60
+ ),
61
+ }}
62
+ {...tableSearchTextfieldProps}
63
+ />
64
+ );
65
+ };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { Checkbox, TableCell } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+
5
+ export const MRT_SelectAllCheckbox = () => {
6
+ const { tableInstance, enableSelectAll } = useMaterialReactTable();
7
+
8
+ return (
9
+ <TableCell style={{ width: '2rem', padding: '0.5rem' }} variant="head">
10
+ {enableSelectAll ? (
11
+ <Checkbox aria-label='' {...tableInstance.getToggleAllPageRowsSelectedProps()} />
12
+ ) : null}
13
+ </TableCell>
14
+ );
15
+ };
@@ -0,0 +1,26 @@
1
+ import React, { ChangeEvent, FC } from 'react';
2
+ import { Checkbox, TableCell } from '@mui/material';
3
+ import { Row } from 'react-table';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ interface Props {
7
+ row: Row;
8
+ }
9
+
10
+ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
11
+ const { tableInstance, onRowSelectChange } = useMaterialReactTable();
12
+
13
+ const onSelectChange = (event: ChangeEvent) => {
14
+ row.getToggleRowSelectedProps()?.onChange?.(event);
15
+ onRowSelectChange?.(event, row.state, tableInstance.selectedFlatRows);
16
+ };
17
+
18
+ return (
19
+ <TableCell style={{ width: '2rem', padding: '0.5rem' }}>
20
+ <Checkbox
21
+ {...row.getToggleRowSelectedProps()}
22
+ onChange={onSelectChange}
23
+ />
24
+ </TableCell>
25
+ );
26
+ };
@@ -0,0 +1,82 @@
1
+ import React, { FC } from 'react';
2
+ import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import { ColumnInstance } from 'react-table';
5
+ import ClearAllIcon from '@mui/icons-material/ClearAll';
6
+ import SortIcon from '@mui/icons-material/Sort';
7
+ import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
8
+
9
+ const MenuItem = styled(MuiMenuItem)({
10
+ display: 'flex',
11
+ gap: '0.75rem',
12
+ });
13
+
14
+ interface Props {
15
+ anchorEl: HTMLElement | null;
16
+ column: ColumnInstance;
17
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
18
+ }
19
+
20
+ export const MRT_ColumnActionMenu: FC<Props> = ({
21
+ anchorEl,
22
+ column,
23
+ setAnchorEl,
24
+ }) => {
25
+ const { enableColumnHiding, enableSorting, localization } =
26
+ useMaterialReactTable();
27
+
28
+ const handleClearSort = () => {
29
+ column.clearSortBy();
30
+ setAnchorEl(null);
31
+ };
32
+
33
+ const handleSortAsc = () => {
34
+ column.toggleSortBy(false);
35
+ setAnchorEl(null);
36
+ };
37
+
38
+ const handleSortDesc = () => {
39
+ column.toggleSortBy(true);
40
+ setAnchorEl(null);
41
+ };
42
+
43
+ const handleHideColumn = () => {
44
+ column.toggleHidden();
45
+ setAnchorEl(null);
46
+ };
47
+
48
+ return (
49
+ <Menu
50
+ anchorEl={anchorEl}
51
+ open={!!anchorEl}
52
+ onClose={() => setAnchorEl(null)}
53
+ >
54
+ {enableSorting && (
55
+ <>
56
+ <MenuItem disabled={!column.isSorted} onClick={handleClearSort}>
57
+ <ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
58
+ </MenuItem>
59
+ <MenuItem
60
+ disabled={column.isSorted && !column.isSortedDesc}
61
+ onClick={handleSortAsc}
62
+ >
63
+ <SortIcon /> {localization?.columnActionMenuItemSortAsc}
64
+ </MenuItem>
65
+ <MenuItem
66
+ disabled={column.isSorted && column.isSortedDesc}
67
+ onClick={handleSortDesc}
68
+ >
69
+ <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
70
+ {localization?.columnActionMenuItemSortDesc}
71
+ </MenuItem>
72
+ <Divider />
73
+ </>
74
+ )}
75
+ {enableColumnHiding && (
76
+ <MenuItem onClick={handleHideColumn}>
77
+ <VisibilityOffIcon /> {localization?.columnActionMenuItemHideColumn}
78
+ </MenuItem>
79
+ )}
80
+ </Menu>
81
+ );
82
+ };
@@ -0,0 +1,34 @@
1
+ import React, { FC } from 'react';
2
+ import { FormControlLabel, MenuItem, Switch, Typography } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import { ColumnInstance } from 'react-table';
5
+
6
+ interface Props {
7
+ column: ColumnInstance;
8
+ }
9
+
10
+ export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
11
+ const { maxColumnDepth } = useMaterialReactTable();
12
+
13
+ const isMaxDepth = column.depth === maxColumnDepth;
14
+
15
+ return (
16
+ <>
17
+ <MenuItem style={{ paddingLeft: `${column.depth + 1}rem` }}>
18
+ {isMaxDepth ? (
19
+ <FormControlLabel
20
+ onChange={() => isMaxDepth && column.toggleHidden()}
21
+ label={column.Header as string}
22
+ checked={column.isVisible}
23
+ control={<Switch />}
24
+ />
25
+ ) : (
26
+ <Typography>{column.Header}</Typography>
27
+ )}
28
+ </MenuItem>
29
+ {column.columns?.map((c, i) => (
30
+ <MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
31
+ ))}
32
+ </>
33
+ );
34
+ };
@@ -0,0 +1,21 @@
1
+ import React, { FC } from 'react';
2
+ import { Table } from '@mui/material';
3
+ import { MRT_TableHead } from '../head/MRT_TableHead';
4
+ import { MRT_TableBody } from '../body/MRT_TableBody';
5
+ import { MRT_TableFooter } from '../footer/MRT_TableFooter';
6
+ import { useMaterialReactTable } from '../useMaterialReactTable';
7
+
8
+ interface Props {}
9
+
10
+ export const MRT_Table: FC<Props> = () => {
11
+ const { tableInstance, tableProps, showHead, showFooter } =
12
+ useMaterialReactTable();
13
+
14
+ return (
15
+ <Table {...tableProps} {...tableInstance.getTableProps()}>
16
+ {showHead && <MRT_TableHead />}
17
+ <MRT_TableBody />
18
+ {showFooter && <MRT_TableFooter />}
19
+ </Table>
20
+ );
21
+ };
@@ -1,15 +1,17 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Paper, TableContainer } from '@mui/material';
3
- import { useMaterialReactTable } from './useMaterialReactTable';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
4
  import { MRT_Table } from './MRT_Table';
5
+ import { MRT_Toolbar } from '../toolbar/MRT_Toolbar';
5
6
 
6
7
  interface Props {}
7
8
 
8
9
  export const MRT_TableContainer: FC<Props> = () => {
9
- const { tableContainerProps } = useMaterialReactTable();
10
+ const { tableContainerProps, showToolbar } = useMaterialReactTable();
10
11
 
11
12
  return (
12
13
  <TableContainer component={Paper} {...tableContainerProps}>
14
+ {showToolbar && <MRT_Toolbar />}
13
15
  <MRT_Table />
14
16
  </TableContainer>
15
17
  );
@@ -0,0 +1,10 @@
1
+ import React, { CSSProperties, FC } from 'react';
2
+ import { TableCell } from '@mui/material';
3
+
4
+ interface Props {
5
+ width?: CSSProperties['width'];
6
+ }
7
+
8
+ export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
9
+ return <TableCell style={{ width }} />;
10
+ };
@@ -0,0 +1,39 @@
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
+
6
+ const Toolbar = styled(MuiToolbar)({
7
+ padding: '0.5rem',
8
+ display: 'flex',
9
+ justifyContent: 'space-between',
10
+ });
11
+
12
+ interface Props {}
13
+
14
+ export const MRT_Toolbar: FC<Props> = () => {
15
+ const {
16
+ OverrideTableToolbarComponent,
17
+ enableSearch,
18
+ tableInstance,
19
+ tableTitleProps,
20
+ tableToolbarProps,
21
+ title,
22
+ } = useMaterialReactTable();
23
+
24
+ if (OverrideTableToolbarComponent) {
25
+ return <>{OverrideTableToolbarComponent(tableInstance)}</>;
26
+ }
27
+
28
+ //if no features in the toolbar are enabled, don't render anything
29
+ if (!enableSearch && !title && !tableToolbarProps) {
30
+ return null;
31
+ }
32
+
33
+ return (
34
+ <Toolbar variant="dense" {...tableToolbarProps}>
35
+ {title ? <Typography {...tableTitleProps}>{title}</Typography> : <span />}
36
+ {enableSearch && <MRT_SearchTextField />}
37
+ </Toolbar>
38
+ );
39
+ };
@@ -1,50 +1,69 @@
1
- import React, { createContext, FC, useContext } from 'react';
1
+ import React, {
2
+ Context,
3
+ createContext,
4
+ PropsWithChildren,
5
+ useContext,
6
+ } from 'react';
2
7
  import {
3
8
  TableInstance,
4
9
  useExpanded,
10
+ useFilters,
11
+ useFlexLayout,
12
+ useGlobalFilter,
5
13
  usePagination,
14
+ useResizeColumns,
15
+ useRowSelect,
6
16
  useSortBy,
7
17
  useTable,
8
18
  } from 'react-table';
9
- import {
10
- MaterialReactTableOptionalProps,
11
- MaterialReactTableOptions,
12
- MaterialReactTableProps,
13
- } from '.';
14
- import { defaultOptions } from './defaults';
19
+ import { MaterialReactTableProps } from '.';
20
+ import { UseMRTCalcs, useMRTCalcs } from './utils/useMRTCalcs';
21
+ import { showOverrideWarnings } from './utils/overrideWarnings';
15
22
 
16
- interface IUseMaterialReactTable extends MaterialReactTableOptionalProps {
17
- tableInstance: TableInstance<object>;
18
- options: MaterialReactTableOptions;
23
+ interface UseMaterialReactTable<D extends {}>
24
+ extends MaterialReactTableProps<D>,
25
+ UseMRTCalcs {
26
+ tableInstance: TableInstance<D>;
19
27
  }
20
28
 
21
- const MaterialReactTableContext = createContext<IUseMaterialReactTable>(
22
- {} as IUseMaterialReactTable,
23
- );
24
-
25
- interface ProviderProps extends MaterialReactTableProps {
26
- children: React.ReactNode;
27
- }
29
+ const MaterialReactTableContext = (<D extends {}>() =>
30
+ createContext<UseMaterialReactTable<D>>(
31
+ {} as UseMaterialReactTable<D>,
32
+ ) as Context<UseMaterialReactTable<D>>)();
28
33
 
29
- export const MaterialReactTableProvider: FC<ProviderProps> = ({
34
+ export const MaterialReactTableProvider = <D extends {}>({
30
35
  children,
31
36
  columns,
32
37
  data,
33
- options,
38
+ surpressOverrideWarnings,
34
39
  ...rest
35
- }) => {
40
+ }: PropsWithChildren<MaterialReactTableProps<D>>) => {
36
41
  const tableInstance = useTable(
37
42
  { columns, data },
43
+ useFlexLayout,
44
+ useResizeColumns,
45
+ useFilters,
46
+ useGlobalFilter,
38
47
  useSortBy,
39
48
  useExpanded,
40
49
  usePagination,
50
+ useRowSelect,
41
51
  );
42
52
 
53
+ const mrtCalcs = useMRTCalcs({ tableInstance });
54
+
55
+ if (process.env.NODE_ENV !== 'production' && !surpressOverrideWarnings) {
56
+ showOverrideWarnings(rest);
57
+ }
58
+
43
59
  return (
44
60
  <MaterialReactTableContext.Provider
61
+ //@ts-ignore
45
62
  value={{
46
- options: { ...defaultOptions, ...options },
63
+ columns,
64
+ data,
47
65
  tableInstance,
66
+ ...mrtCalcs,
48
67
  ...rest,
49
68
  }}
50
69
  >
@@ -53,5 +72,8 @@ export const MaterialReactTableProvider: FC<ProviderProps> = ({
53
72
  );
54
73
  };
55
74
 
56
- export const useMaterialReactTable = (): IUseMaterialReactTable =>
57
- useContext(MaterialReactTableContext);
75
+ export const useMaterialReactTable = <
76
+ D extends {},
77
+ >(): UseMaterialReactTable<D> =>
78
+ //@ts-ignore
79
+ useContext<UseMaterialReactTable<D>>(MaterialReactTableContext);
@@ -0,0 +1,29 @@
1
+ export interface MRT_Localization {
2
+ columnActionMenuButtonTitle?: string;
3
+ columnActionMenuItemHideColumn?: string;
4
+ columnActionMenuItemSortAsc?: string;
5
+ columnActionMenuItemClearSort?: string;
6
+ columnActionMenuItemSortDesc?: string;
7
+ expandAllButtonTitle?: string;
8
+ expandButtonTitle?: string;
9
+ filterTextFieldClearButtonTitle?: string;
10
+ filterTextFieldPlaceholder?: string;
11
+ searchTextFieldClearButtonTitle?: string;
12
+ searchTextFieldPlaceholder?: string;
13
+ showHideColumnsButtonTitle?: string;
14
+ }
15
+
16
+ export const defaultLocalization: MRT_Localization = {
17
+ columnActionMenuButtonTitle: 'Column Actions',
18
+ columnActionMenuItemHideColumn: 'Hide column',
19
+ columnActionMenuItemSortAsc: 'Sort ascending',
20
+ columnActionMenuItemClearSort: 'Clear sorting',
21
+ columnActionMenuItemSortDesc: 'Sort descending',
22
+ expandAllButtonTitle: 'Expand all',
23
+ expandButtonTitle: 'Expand',
24
+ filterTextFieldClearButtonTitle: 'Clear filter',
25
+ filterTextFieldPlaceholder: 'Filter',
26
+ searchTextFieldClearButtonTitle: 'Clear search',
27
+ searchTextFieldPlaceholder: 'Search',
28
+ showHideColumnsButtonTitle: 'Show/Hide columns'
29
+ };
@@ -0,0 +1,41 @@
1
+ export const showOverrideWarnings = (props: any) => {
2
+ if (props.OverrideTableBodyCellComponent) {
3
+ showWarning('TableCell', 'props');
4
+ }
5
+ if (props.OverrideTableBodyComponent) {
6
+ showWarning('TableBody', 'tableBodyProps');
7
+ }
8
+ if (props.OverrideTableBodyRowComponent) {
9
+ showWarning('TableRow', 'props');
10
+ }
11
+ if (props.OverrideTableDetailPanelComponent) {
12
+ showWarning('Detail Panel', 'tableDetailPanelProps');
13
+ }
14
+ if (props.OverrideTableFooterComponent) {
15
+ showWarning('TableFooter', 'tableFooterProps');
16
+ }
17
+ if (props.OverrideTableFooterCellComponent) {
18
+ showWarning('TableCell', 'props');
19
+ }
20
+ if (props.OverrideTableFooterRowComponent) {
21
+ showWarning('TableRow', 'props');
22
+ }
23
+ if (props.OverrideTableHeadComponent) {
24
+ showWarning('TableHead', 'tableHeadProps');
25
+ }
26
+ if (props.OverrideTableHeadRowComponent) {
27
+ showWarning('TableRow', 'props');
28
+ }
29
+ if (props.OverrideTablePaginationComponent) {
30
+ showWarning('', 'props');
31
+ }
32
+ if (props.OverrideTableToolbarComponent) {
33
+ showWarning('TableBodyCell', 'props');
34
+ }
35
+ };
36
+
37
+ const showWarning = (componentName: string, propsName: string) => {
38
+ console.warn(
39
+ `Caution.\nYou are overriding the built-in Mui ${componentName} Component in material-react-table.\n\nYou should only use this as a last resort!\n\nConsider customizing the Mui ${componentName} Component instead with ${propsName}.`,
40
+ );
41
+ };
@@ -0,0 +1,42 @@
1
+ import { useMemo } from 'react';
2
+ import { TableInstance } from 'react-table';
3
+
4
+ export interface UseMRTCalcs {
5
+ anyRowsCanExpand: boolean;
6
+ anyRowsExpanded: boolean;
7
+ maxColumnDepth: number;
8
+ }
9
+
10
+ interface Props<D extends {}> {
11
+ tableInstance: TableInstance<D>;
12
+ }
13
+
14
+ export const useMRTCalcs = <D extends {}>({
15
+ tableInstance,
16
+ }: Props<D>): UseMRTCalcs => {
17
+ const anyRowsCanExpand = useMemo(
18
+ () => tableInstance.rows.some((row) => row.canExpand),
19
+ [tableInstance.rows],
20
+ );
21
+
22
+ const anyRowsExpanded = useMemo(
23
+ () => tableInstance.rows.some((row) => row.isExpanded),
24
+ [tableInstance.rows],
25
+ );
26
+
27
+ const maxColumnDepth = useMemo(() => {
28
+ let maxDepth = 1;
29
+ tableInstance.columns.forEach((column) => {
30
+ if (column.columns?.length) {
31
+ maxDepth = Math.max(maxDepth, column.columns.length);
32
+ }
33
+ });
34
+ return maxDepth - 1;
35
+ }, [tableInstance.columns]);
36
+
37
+ return {
38
+ anyRowsCanExpand,
39
+ anyRowsExpanded,
40
+ maxColumnDepth,
41
+ };
42
+ };
@@ -1,2 +0,0 @@
1
- import { MaterialReactTableOptions } from '.';
2
- export declare const defaultOptions: MaterialReactTableOptions;
package/src/MRT_Table.tsx DELETED
@@ -1,20 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { Table } from '@mui/material';
3
- import { MRT_TableHead } from './MRT_TableHead';
4
- import { MRT_TableBody } from './MRT_TableBody';
5
- import { MRT_TableFooter } from './MRT_TableFooter';
6
- import { useMaterialReactTable } from './useMaterialReactTable';
7
-
8
- interface Props {}
9
-
10
- export const MRT_Table: FC<Props> = () => {
11
- const { tableInstance, tableProps, options } = useMaterialReactTable();
12
-
13
- return (
14
- <Table stickyHeader {...tableProps} {...tableInstance.getTableProps()}>
15
- {options.showHead && <MRT_TableHead />}
16
- <MRT_TableBody />
17
- {options.showFooter && <MRT_TableFooter />}
18
- </Table>
19
- );
20
- };
@@ -1,19 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableBody } from '@mui/material';
3
- import { MRT_TableBodyRow } from './MRT_TableBodyRow';
4
- import { useMaterialReactTable } from './useMaterialReactTable';
5
-
6
- interface Props {}
7
-
8
- export const MRT_TableBody: FC<Props> = () => {
9
- const { tableInstance } = useMaterialReactTable();
10
-
11
- return (
12
- <TableBody {...tableInstance.getTableBodyProps()}>
13
- {tableInstance.page.map((row, index) => {
14
- tableInstance.prepareRow(row);
15
- return <MRT_TableBodyRow key={`${index}-${row.id}`} row={row} />;
16
- })}
17
- </TableBody>
18
- );
19
- };
@@ -1,27 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableRow } from '@mui/material';
3
- import { Row } from 'react-table';
4
- import { MRT_TableBodyCell } from './MRT_TableBodyCell';
5
- import { useMaterialReactTable } from './useMaterialReactTable';
6
- import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
7
- import { MRT_TableExpandButton } from './MRT_TableExpandButton';
8
-
9
- interface Props {
10
- row: Row<object>;
11
- }
12
-
13
- export const MRT_TableBodyRow: FC<Props> = ({ row }) => {
14
- const { renderDetailPanel } = useMaterialReactTable();
15
-
16
- return (
17
- <>
18
- <TableRow {...row.getRowProps()}>
19
- {renderDetailPanel && <MRT_TableExpandButton row={row} />}
20
- {row.cells.map((cell, index) => (
21
- <MRT_TableBodyCell key={`${index}-${cell.value}`} cell={cell} />
22
- ))}
23
- </TableRow>
24
- {renderDetailPanel && <MRT_TableDetailPanel row={row} />}
25
- </>
26
- );
27
- };