material-react-table 0.4.7 → 0.4.8

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 (51) hide show
  1. package/dist/MaterialReactTable.d.ts +65 -21
  2. package/dist/body/MRT_TableBodyCell.d.ts +2 -2
  3. package/dist/body/MRT_TableBodyRow.d.ts +2 -2
  4. package/dist/body/MRT_TableDetailPanel.d.ts +2 -2
  5. package/dist/buttons/MRT_EditActionButtons.d.ts +2 -2
  6. package/dist/buttons/MRT_ExpandButton.d.ts +2 -2
  7. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +2 -2
  8. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -2
  9. package/dist/footer/MRT_TableFooterCell.d.ts +2 -2
  10. package/dist/footer/MRT_TableFooterRow.d.ts +2 -2
  11. package/dist/head/MRT_TableHeadCell.d.ts +2 -2
  12. package/dist/head/MRT_TableHeadRow.d.ts +2 -2
  13. package/dist/inputs/MRT_EditCellTextField.d.ts +2 -2
  14. package/dist/inputs/MRT_FilterTextField.d.ts +2 -2
  15. package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -2
  16. package/dist/material-react-table.cjs.development.js +11 -11
  17. package/dist/material-react-table.cjs.development.js.map +1 -1
  18. package/dist/material-react-table.cjs.production.min.js +1 -1
  19. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  20. package/dist/material-react-table.esm.js +11 -11
  21. package/dist/material-react-table.esm.js.map +1 -1
  22. package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
  23. package/dist/menus/MRT_RowActionMenu.d.ts +2 -2
  24. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -2
  25. package/dist/useMRT.d.ts +4 -4
  26. package/package.json +1 -1
  27. package/src/@types/react-table-config.d.ts +18 -121
  28. package/src/MaterialReactTable.tsx +179 -20
  29. package/src/body/MRT_TableBody.tsx +2 -1
  30. package/src/body/MRT_TableBodyCell.tsx +2 -2
  31. package/src/body/MRT_TableBodyRow.tsx +3 -3
  32. package/src/body/MRT_TableDetailPanel.tsx +3 -3
  33. package/src/buttons/MRT_EditActionButtons.tsx +2 -2
  34. package/src/buttons/MRT_ExpandButton.tsx +2 -2
  35. package/src/buttons/MRT_ShowHideColumnsButton.tsx +2 -1
  36. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +2 -2
  37. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -2
  38. package/src/footer/MRT_TableFooter.tsx +2 -1
  39. package/src/footer/MRT_TableFooterCell.tsx +2 -2
  40. package/src/footer/MRT_TableFooterRow.tsx +3 -3
  41. package/src/head/MRT_TableHead.tsx +2 -1
  42. package/src/head/MRT_TableHeadCell.tsx +2 -2
  43. package/src/head/MRT_TableHeadRow.tsx +3 -3
  44. package/src/index.tsx +2 -0
  45. package/src/inputs/MRT_EditCellTextField.tsx +2 -2
  46. package/src/inputs/MRT_FilterTextField.tsx +3 -2
  47. package/src/inputs/MRT_SelectCheckbox.tsx +2 -2
  48. package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
  49. package/src/menus/MRT_RowActionMenu.tsx +2 -2
  50. package/src/menus/MRT_ShowHideColumnsMenu.tsx +3 -2
  51. package/src/useMRT.tsx +18 -15
@@ -10,6 +10,7 @@ import {
10
10
  } from '@mui/material';
11
11
  import { useMRT } from '../useMRT';
12
12
  import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
13
+ import { MRT_ColumnInstance } from '..';
13
14
 
14
15
  const MenuButtons = styled('div')({
15
16
  display: 'flex',
@@ -67,7 +68,7 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
67
68
  </Button>
68
69
  </MenuButtons>
69
70
  <Divider />
70
- {tableInstance.columns.map((column, index) => (
71
+ {tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
71
72
  <MRT_ShowHideColumnsMenu
72
73
  key={`${index}-${column.id}`}
73
74
  column={column}
@@ -2,7 +2,7 @@ import React, { FC, MouseEvent, useState } from 'react';
2
2
  import { IconButton as MuiIconButton, styled, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
5
- import { HeaderGroup } from 'react-table';
5
+ import { MRT_HeaderGroup } from '..';
6
6
 
7
7
  const IconButton = styled(MuiIconButton)({
8
8
  opacity: 0.5,
@@ -16,7 +16,7 @@ const IconButton = styled(MuiIconButton)({
16
16
  });
17
17
 
18
18
  interface Props {
19
- column: HeaderGroup;
19
+ column: MRT_HeaderGroup;
20
20
  }
21
21
 
22
22
  export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
@@ -1,10 +1,10 @@
1
1
  import React, { FC, MouseEvent, useState } from 'react';
2
2
  import { IconButton as MuiIconButton, styled, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { Row } from 'react-table';
5
4
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
6
5
  import { MRT_EditActionButtons } from './MRT_EditActionButtons';
7
6
  import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
7
+ import { MRT_Row } from '..';
8
8
 
9
9
  const IconButton = styled(MuiIconButton)({
10
10
  opacity: 0.5,
@@ -18,7 +18,7 @@ const IconButton = styled(MuiIconButton)({
18
18
  });
19
19
 
20
20
  interface Props {
21
- row: Row;
21
+ row: MRT_Row;
22
22
  }
23
23
 
24
24
  export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
@@ -2,6 +2,7 @@ import React, { FC } from 'react';
2
2
  import { TableFooter } from '@mui/material';
3
3
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
4
  import { useMRT } from '../useMRT';
5
+ import { MRT_HeaderGroup } from '..';
5
6
 
6
7
  interface Props {}
7
8
 
@@ -10,7 +11,7 @@ export const MRT_TableFooter: FC<Props> = () => {
10
11
 
11
12
  return (
12
13
  <TableFooter {...muiTableFooterProps}>
13
- {tableInstance.footerGroups.map((footerGroup) => (
14
+ {tableInstance.footerGroups.map((footerGroup: MRT_HeaderGroup) => (
14
15
  <MRT_TableFooterRow
15
16
  key={footerGroup.getFooterGroupProps().key}
16
17
  footerGroup={footerGroup}
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { styled, TableCell as MuiTableCell } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
3
  import { useMRT } from '../useMRT';
4
+ import { MRT_HeaderGroup } from '..';
5
5
 
6
6
  const TableCell = styled(MuiTableCell, {
7
7
  shouldForwardProp: (prop) =>
@@ -16,7 +16,7 @@ const TableCell = styled(MuiTableCell, {
16
16
  );
17
17
 
18
18
  interface Props {
19
- column: HeaderGroup;
19
+ column: MRT_HeaderGroup;
20
20
  }
21
21
 
22
22
  export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
@@ -1,12 +1,12 @@
1
1
  import React, { FC } from 'react';
2
2
  import { TableRow } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
3
  import { MRT_TableFooterCell } from './MRT_TableFooterCell';
5
4
  import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
6
5
  import { useMRT } from '../useMRT';
6
+ import { MRT_HeaderGroup } from '..';
7
7
 
8
8
  interface Props {
9
- footerGroup: HeaderGroup;
9
+ footerGroup: MRT_HeaderGroup;
10
10
  }
11
11
 
12
12
  export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
@@ -53,7 +53,7 @@ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
53
53
  />
54
54
  )}
55
55
  {enableSelection && <MRT_TableSpacerCell width="1rem" />}
56
- {footerGroup.headers.map((column) => (
56
+ {footerGroup.headers.map((column: MRT_HeaderGroup) => (
57
57
  <MRT_TableFooterCell
58
58
  key={column.getFooterProps().key}
59
59
  column={column}
@@ -2,6 +2,7 @@ import React, { FC } from 'react';
2
2
  import { TableHead } from '@mui/material';
3
3
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
4
4
  import { useMRT } from '../useMRT';
5
+ import { MRT_HeaderGroup } from '..';
5
6
 
6
7
  interface Props {}
7
8
 
@@ -15,7 +16,7 @@ export const MRT_TableHead: FC<Props> = () => {
15
16
 
16
17
  return (
17
18
  <TableHead {...tableHeadProps}>
18
- {tableInstance.headerGroups.map((headerGroup) => (
19
+ {tableInstance.headerGroups.map((headerGroup: MRT_HeaderGroup) => (
19
20
  <MRT_TableHeadRow
20
21
  key={headerGroup.getHeaderGroupProps().key}
21
22
  headerGroup={headerGroup}
@@ -7,10 +7,10 @@ import {
7
7
  Collapse,
8
8
  Tooltip,
9
9
  } from '@mui/material';
10
- import { HeaderGroup } from 'react-table';
11
10
  import { useMRT } from '../useMRT';
12
11
  import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
13
12
  import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
13
+ import { MRT_HeaderGroup } from '..';
14
14
 
15
15
  export const MRT_StyledTableHeadCell = styled(MuiTableCell, {
16
16
  shouldForwardProp: (prop) =>
@@ -52,7 +52,7 @@ const Divider = styled(MuiDivider)({
52
52
  });
53
53
 
54
54
  interface Props {
55
- column: HeaderGroup;
55
+ column: MRT_HeaderGroup;
56
56
  }
57
57
 
58
58
  export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
@@ -1,6 +1,5 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { TableRow } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
3
  import {
5
4
  MRT_StyledTableHeadCell,
6
5
  MRT_TableHeadCell,
@@ -10,9 +9,10 @@ import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
10
9
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
11
10
  import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
12
11
  import { MRT_TableHeadCellActions } from './MRT_TableHeadCellActions';
12
+ import { MRT_HeaderGroup } from '..';
13
13
 
14
14
  interface Props {
15
- headerGroup: HeaderGroup;
15
+ headerGroup: MRT_HeaderGroup;
16
16
  }
17
17
 
18
18
  export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
@@ -81,7 +81,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
81
81
  <MRT_TableSpacerCell width="1rem" />
82
82
  )
83
83
  ) : null}
84
- {headerGroup.headers.map((column: HeaderGroup) => (
84
+ {headerGroup.headers.map((column: MRT_HeaderGroup) => (
85
85
  <MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
86
86
  ))}
87
87
  {(enableRowActions || enableRowEditing) &&
package/src/index.tsx CHANGED
@@ -1,3 +1,5 @@
1
1
  import MaterialReactTable from './MaterialReactTable';
2
2
  export default MaterialReactTable;
3
3
  export * from './MaterialReactTable';
4
+
5
+
@@ -1,10 +1,10 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { TextField } from '@mui/material';
3
- import { Cell } from 'react-table';
4
3
  import { useMRT } from '../useMRT';
4
+ import { MRT_Cell } from '..';
5
5
 
6
6
  interface Props {
7
- cell: Cell;
7
+ cell: MRT_Cell;
8
8
  }
9
9
 
10
10
  export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
@@ -1,10 +1,11 @@
1
1
  import React, { ChangeEvent, FC, useState } from 'react';
2
2
  import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
3
- import { HeaderGroup, useAsyncDebounce } from 'react-table';
3
+ import { useAsyncDebounce } from 'react-table';
4
4
  import { useMRT } from '../useMRT';
5
+ import { MRT_HeaderGroup } from '..';
5
6
 
6
7
  interface Props {
7
- column: HeaderGroup;
8
+ column: MRT_HeaderGroup;
8
9
  }
9
10
 
10
11
  export const MRT_FilterTextField: FC<Props> = ({ column }) => {
@@ -1,11 +1,11 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { Checkbox, Tooltip } from '@mui/material';
3
- import { Row } from 'react-table';
4
3
  import { useMRT } from '../useMRT';
5
4
  import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
5
+ import { MRT_Row } from '..';
6
6
 
7
7
  interface Props {
8
- row?: Row;
8
+ row?: MRT_Row;
9
9
  selectAll?: boolean;
10
10
  }
11
11
 
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { HeaderGroup } from 'react-table';
4
+ import { MRT_HeaderGroup } from '..';
5
5
 
6
6
  const MenuItem = styled(MuiMenuItem)({
7
7
  display: 'flex',
@@ -10,7 +10,7 @@ const MenuItem = styled(MuiMenuItem)({
10
10
 
11
11
  interface Props {
12
12
  anchorEl: HTMLElement | null;
13
- column: HeaderGroup;
13
+ column: MRT_HeaderGroup;
14
14
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
15
15
  }
16
16
 
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { Row } from 'react-table';
4
+ import { MRT_Row } from '..';
5
5
 
6
6
  const MenuItem = styled(MuiMenuItem)({
7
7
  display: 'flex',
@@ -10,7 +10,7 @@ const MenuItem = styled(MuiMenuItem)({
10
10
 
11
11
  interface Props {
12
12
  anchorEl: HTMLElement | null;
13
- row: Row;
13
+ row: MRT_Row;
14
14
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
15
15
  handleEdit: () => void;
16
16
  }
@@ -1,9 +1,10 @@
1
1
  import React, { FC } from 'react';
2
2
  import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
3
  import { ColumnInstance } from 'react-table';
4
+ import { MRT_ColumnInstance } from '..';
4
5
 
5
6
  interface Props {
6
- column: ColumnInstance;
7
+ column: MRT_ColumnInstance;
7
8
  }
8
9
 
9
10
  export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
@@ -35,7 +36,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
35
36
  onChange={() => handleToggleColumnHidden(column)}
36
37
  />
37
38
  </MenuItem>
38
- {column.columns?.map((c, i) => (
39
+ {column.columns?.map((c: MRT_ColumnInstance, i) => (
39
40
  <MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
40
41
  ))}
41
42
  </>
package/src/useMRT.tsx CHANGED
@@ -1,15 +1,13 @@
1
1
  import React, {
2
2
  Context,
3
- createContext,
4
3
  PropsWithChildren,
4
+ createContext,
5
5
  useContext,
6
6
  useMemo,
7
7
  useState,
8
8
  } from 'react';
9
9
  import {
10
10
  PluginHook,
11
- Row,
12
- TableInstance,
13
11
  useExpanded,
14
12
  useFilters,
15
13
  useFlexLayout,
@@ -21,6 +19,7 @@ import {
21
19
  useSortBy,
22
20
  useTable,
23
21
  } from 'react-table';
22
+ import { MRT_Row, MRT_TableInstance } from '.';
24
23
  import { MRT_Icons } from './icons';
25
24
  import { MRT_Localization } from './localization';
26
25
  import { MaterialReactTableProps } from './MaterialReactTable';
@@ -28,19 +27,19 @@ import { MaterialReactTableProps } from './MaterialReactTable';
28
27
  export type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
29
28
  anyRowsCanExpand: boolean;
30
29
  anyRowsExpanded: boolean;
31
- currentEditingRow: Row<D> | null;
30
+ currentEditingRow: MRT_Row<D> | null;
32
31
  densePadding: boolean;
33
32
  fullScreen: boolean;
34
33
  icons: MRT_Icons;
35
34
  localization: MRT_Localization;
36
- setCurrentEditingRow: (currentRowEditingId: Row<D> | null) => void;
35
+ setCurrentEditingRow: (currentRowEditingId: MRT_Row<D> | null) => void;
37
36
  setDensePadding: (densePadding: boolean) => void;
38
37
  setFullScreen: (fullScreen: boolean) => void;
39
38
  setShowFilters: (showFilters: boolean) => void;
40
39
  setShowSearch: (showSearch: boolean) => void;
41
40
  showFilters: boolean;
42
41
  showSearch: boolean;
43
- tableInstance: TableInstance<D>;
42
+ tableInstance: MRT_TableInstance<D>;
44
43
  };
45
44
 
46
45
  const MaterialReactTableContext = (<D extends {}>() =>
@@ -62,28 +61,32 @@ export const MaterialReactTableProvider = <D extends {}>(
62
61
  if (props.enableColumnResizing)
63
62
  hooks.unshift(useResizeColumns, useFlexLayout);
64
63
 
65
- const tableInstance = useTable<D>(props, ...hooks);
64
+ const tableInstance = useTable<D>(props, ...hooks) as MRT_TableInstance<D>;
66
65
 
67
66
  const anyRowsCanExpand = useMemo(
68
- () => tableInstance.rows.some((row) => row.canExpand),
67
+ // @ts-ignore
68
+ () => tableInstance.rows.some((row: MRT_Row) => row.canExpand),
69
69
  [tableInstance.rows],
70
70
  );
71
71
  const anyRowsExpanded = useMemo(
72
- () => tableInstance.rows.some((row) => row.isExpanded),
72
+ // @ts-ignore
73
+ () => tableInstance.rows.some((row: MRT_Row) => row.isExpanded),
73
74
  [tableInstance.rows],
74
75
  );
75
- const [currentEditingRow, setCurrentEditingRow] = useState<Row | null>(null);
76
+ const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
77
+ null,
78
+ );
76
79
  const [densePadding, setDensePadding] = useState(
77
- props.defaultDensePadding ?? false,
80
+ props.initialState?.densePadding ?? false,
78
81
  );
79
82
  const [fullScreen, setFullScreen] = useState(
80
- props.defaultFullScreen ?? false,
83
+ props.initialState?.fullScreen ?? false,
81
84
  );
82
85
  const [showFilters, setShowFilters] = useState(
83
- props.defaultShowFilters ?? false,
86
+ props.initialState?.showFilters ?? false,
84
87
  );
85
88
  const [showSearch, setShowSearch] = useState(
86
- props.defaultShowSearchTextField ?? false,
89
+ props.initialState?.showSearchTextField ?? false,
87
90
  );
88
91
 
89
92
  return (
@@ -112,5 +115,5 @@ export const MaterialReactTableProvider = <D extends {}>(
112
115
  };
113
116
 
114
117
  export const useMRT = <D extends {}>(): UseMRT<D> =>
115
- //@ts-ignore
118
+ // @ts-ignore
116
119
  useContext<UseMRT<D>>(MaterialReactTableContext);