material-react-table 0.1.0-beta.1 → 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 (96) hide show
  1. package/dist/MaterialReactTable.d.ts +60 -26
  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/{MRT_TableExpandButton.d.ts → buttons/MRT_EditActionButtons.d.ts} +2 -2
  7. package/dist/buttons/MRT_ExpandAllButton.d.ts +5 -0
  8. package/dist/buttons/MRT_ExpandButton.d.ts +7 -0
  9. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +5 -0
  10. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +7 -0
  11. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
  12. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
  13. package/dist/{MRT_TableFooter.d.ts → footer/MRT_TableFooter.d.ts} +0 -0
  14. package/dist/{MRT_TableFooterCell.d.ts → footer/MRT_TableFooterCell.d.ts} +0 -0
  15. package/dist/{MRT_TableFooterRow.d.ts → footer/MRT_TableFooterRow.d.ts} +1 -1
  16. package/dist/{MRT_TableHead.d.ts → head/MRT_TableHead.d.ts} +0 -0
  17. package/dist/head/MRT_TableHeadCell.d.ts +8 -0
  18. package/dist/{MRT_TableHeadRow.d.ts → head/MRT_TableHeadRow.d.ts} +1 -1
  19. package/dist/index.d.ts +2 -0
  20. package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
  21. package/dist/{MRT_TableHeadCell.d.ts → inputs/MRT_FilterTextField.d.ts} +1 -1
  22. package/dist/inputs/MRT_SearchTextField.d.ts +5 -0
  23. package/dist/inputs/MRT_SelectAllCheckbox.d.ts +2 -0
  24. package/dist/inputs/MRT_SelectCheckbox.d.ts +7 -0
  25. package/dist/material-react-table.cjs.development.js +1933 -170
  26. package/dist/material-react-table.cjs.development.js.map +1 -1
  27. package/dist/material-react-table.cjs.production.min.js +1 -1
  28. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  29. package/dist/material-react-table.esm.js +1939 -176
  30. package/dist/material-react-table.esm.js.map +1 -1
  31. package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -0
  32. package/dist/menus/MRT_RowActionMenu.d.ts +9 -0
  33. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +7 -0
  34. package/dist/{MRT_Table.d.ts → table/MRT_Table.d.ts} +0 -0
  35. package/dist/{MRT_TableContainer.d.ts → table/MRT_TableContainer.d.ts} +0 -0
  36. package/dist/table/MRT_TableSpacerCell.d.ts +6 -0
  37. package/dist/{MRT_TablePagination.d.ts → toolbar/MRT_TablePagination.d.ts} +0 -0
  38. package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
  39. package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
  40. package/dist/toolbar/MRT_ToolbarTop.d.ts +5 -0
  41. package/dist/useMaterialReactTable.d.ts +13 -11
  42. package/dist/utils/localization.d.ts +25 -0
  43. package/dist/utils/useMRTCalcs.d.ts +11 -0
  44. package/package.json +21 -17
  45. package/src/MaterialReactTable.tsx +145 -37
  46. package/src/body/MRT_TableBody.tsx +56 -0
  47. package/src/body/MRT_TableBodyCell.tsx +48 -0
  48. package/src/body/MRT_TableBodyRow.tsx +74 -0
  49. package/src/body/MRT_TableDetailPanel.tsx +62 -0
  50. package/src/buttons/MRT_EditActionButtons.tsx +51 -0
  51. package/src/buttons/MRT_ExpandAllButton.tsx +45 -0
  52. package/src/buttons/MRT_ExpandButton.tsx +48 -0
  53. package/src/buttons/MRT_ShowHideColumnsButton.tsx +43 -0
  54. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +51 -0
  55. package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
  56. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
  57. package/src/footer/MRT_TableFooter.tsx +21 -0
  58. package/src/footer/MRT_TableFooterCell.tsx +44 -0
  59. package/src/footer/MRT_TableFooterRow.tsx +62 -0
  60. package/src/{MRT_TableHead.tsx → head/MRT_TableHead.tsx} +7 -6
  61. package/src/head/MRT_TableHeadCell.tsx +120 -0
  62. package/src/head/MRT_TableHeadRow.tsx +89 -0
  63. package/src/index.tsx +2 -0
  64. package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
  65. package/src/inputs/MRT_FilterTextField.tsx +64 -0
  66. package/src/inputs/MRT_SearchTextField.tsx +74 -0
  67. package/src/inputs/MRT_SelectAllCheckbox.tsx +26 -0
  68. package/src/inputs/MRT_SelectCheckbox.tsx +33 -0
  69. package/src/menus/MRT_ColumnActionMenu.tsx +107 -0
  70. package/src/menus/MRT_RowActionMenu.tsx +52 -0
  71. package/src/menus/MRT_ShowHideColumnsMenu.tsx +34 -0
  72. package/src/table/MRT_Table.tsx +30 -0
  73. package/src/table/MRT_TableContainer.tsx +22 -0
  74. package/src/table/MRT_TableSpacerCell.tsx +26 -0
  75. package/src/toolbar/MRT_TablePagination.tsx +37 -0
  76. package/src/toolbar/MRT_ToolbarBottom.tsx +58 -0
  77. package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
  78. package/src/toolbar/MRT_ToolbarTop.tsx +81 -0
  79. package/src/useMaterialReactTable.tsx +71 -32
  80. package/src/utils/localization.ts +49 -0
  81. package/src/utils/useMRTCalcs.tsx +42 -0
  82. package/dist/defaults.d.ts +0 -2
  83. package/src/MRT_Table.tsx +0 -20
  84. package/src/MRT_TableBody.tsx +0 -19
  85. package/src/MRT_TableBodyCell.tsx +0 -15
  86. package/src/MRT_TableBodyRow.tsx +0 -27
  87. package/src/MRT_TableContainer.tsx +0 -16
  88. package/src/MRT_TableDetailPanel.tsx +0 -27
  89. package/src/MRT_TableExpandButton.tsx +0 -25
  90. package/src/MRT_TableFooter.tsx +0 -31
  91. package/src/MRT_TableFooterCell.tsx +0 -25
  92. package/src/MRT_TableFooterRow.tsx +0 -22
  93. package/src/MRT_TableHeadCell.tsx +0 -27
  94. package/src/MRT_TableHeadRow.tsx +0 -22
  95. package/src/MRT_TablePagination.tsx +0 -34
  96. package/src/defaults.ts +0 -11
@@ -1,57 +1,96 @@
1
- import React, { createContext, FC, useContext } from 'react';
1
+ import React, {
2
+ Context,
3
+ createContext,
4
+ PropsWithChildren,
5
+ useContext,
6
+ useState,
7
+ } from 'react';
2
8
  import {
9
+ PluginHook,
3
10
  TableInstance,
4
11
  useExpanded,
12
+ useFilters,
13
+ useFlexLayout,
14
+ useGlobalFilter,
15
+ useGroupBy,
5
16
  usePagination,
17
+ useResizeColumns,
18
+ useRowSelect,
6
19
  useSortBy,
7
20
  useTable,
8
21
  } from 'react-table';
9
- import {
10
- MaterialReactTableOptionalProps,
11
- MaterialReactTableOptions,
12
- MaterialReactTableProps,
13
- } from '.';
14
- import { defaultOptions } from './defaults';
15
-
16
- interface IUseMaterialReactTable extends MaterialReactTableOptionalProps {
17
- tableInstance: TableInstance<object>;
18
- options: MaterialReactTableOptions;
19
- }
20
-
21
- const MaterialReactTableContext = createContext<IUseMaterialReactTable>(
22
- {} as IUseMaterialReactTable,
23
- );
22
+ import { MaterialReactTableProps } from './MaterialReactTable';
23
+ import { UseMRTCalcs, useMRTCalcs } from './utils/useMRTCalcs';
24
24
 
25
- interface ProviderProps extends MaterialReactTableProps {
26
- children: React.ReactNode;
25
+ export interface UseMaterialReactTable<D extends {}>
26
+ extends MaterialReactTableProps<D>,
27
+ UseMRTCalcs {
28
+ currentEditingRowId: string | null;
29
+ densePadding: boolean;
30
+ setCurrentEditingRowId: (currentRowEditingId: string | null) => void;
31
+ setDensePadding: (densePadding: boolean) => void;
32
+ setShowFilters: (showFilters: boolean) => void;
33
+ showFilters: boolean;
34
+ tableInstance: TableInstance<D>;
27
35
  }
28
36
 
29
- export const MaterialReactTableProvider: FC<ProviderProps> = ({
30
- children,
31
- columns,
32
- data,
33
- options,
34
- ...rest
35
- }) => {
36
- const tableInstance = useTable(
37
- { columns, data },
37
+ const MaterialReactTableContext = (<D extends {}>() =>
38
+ createContext<UseMaterialReactTable<D>>(
39
+ {} as UseMaterialReactTable<D>,
40
+ ) as Context<UseMaterialReactTable<D>>)();
41
+
42
+ export const MaterialReactTableProvider = <D extends {}>(
43
+ props: PropsWithChildren<MaterialReactTableProps<D>>,
44
+ ) => {
45
+ const hooks: PluginHook<D>[] = [
46
+ useResizeColumns,
47
+ useFilters,
48
+ useGlobalFilter,
49
+ useGroupBy,
38
50
  useSortBy,
39
51
  useExpanded,
40
52
  usePagination,
53
+ useRowSelect,
54
+ ];
55
+
56
+ if (props.enableColumnResizing) hooks.unshift(useFlexLayout);
57
+
58
+ const tableInstance = useTable<D>(props, ...hooks);
59
+
60
+ const mrtCalcs = useMRTCalcs({ tableInstance });
61
+
62
+ const [showFilters, setShowFilters] = useState<boolean>(
63
+ props.defaultShowFilters ?? false,
64
+ );
65
+ const [densePadding, setDensePadding] = useState<boolean>(
66
+ props.defaultDensePadding ?? false,
67
+ );
68
+ const [currentEditingRowId, setCurrentEditingRowId] = useState<string | null>(
69
+ null,
41
70
  );
42
71
 
43
72
  return (
44
73
  <MaterialReactTableContext.Provider
45
74
  value={{
46
- options: { ...defaultOptions, ...options },
75
+ ...mrtCalcs,
76
+ ...props,
77
+ densePadding,
78
+ setDensePadding,
79
+ setShowFilters,
80
+ currentEditingRowId,
81
+ setCurrentEditingRowId,
82
+ showFilters,
83
+ // @ts-ignore
47
84
  tableInstance,
48
- ...rest,
49
85
  }}
50
86
  >
51
- {children}
87
+ {props.children}
52
88
  </MaterialReactTableContext.Provider>
53
89
  );
54
90
  };
55
91
 
56
- export const useMaterialReactTable = (): IUseMaterialReactTable =>
57
- useContext(MaterialReactTableContext);
92
+ export const useMaterialReactTable = <
93
+ D extends {},
94
+ >(): UseMaterialReactTable<D> =>
95
+ //@ts-ignore
96
+ useContext<UseMaterialReactTable<D>>(MaterialReactTableContext);
@@ -0,0 +1,49 @@
1
+ export interface MRT_Localization {
2
+ actionsHeadColumnTitle: string;
3
+ columnActionMenuButtonTitle: string;
4
+ columnActionMenuItemClearSort: string;
5
+ columnActionMenuItemGroupBy: string;
6
+ columnActionMenuItemHideColumn: string;
7
+ columnActionMenuItemSortAsc: string;
8
+ columnActionMenuItemSortDesc: string;
9
+ columnActionMenuItemUnGroupBy: string;
10
+ expandAllButtonTitle: string;
11
+ expandButtonTitle: string;
12
+ filterTextFieldClearButtonTitle: string;
13
+ filterTextFieldPlaceholder: string;
14
+ rowActionMenuButtonTitle: string;
15
+ rowActionsColumnTitle: string;
16
+ rowActionButtonSave: string;
17
+ rowActionButtonCancel: string;
18
+ rowActionMenuItemEdit: string;
19
+ searchTextFieldClearButtonTitle: string;
20
+ searchTextFieldPlaceholder: string;
21
+ showHideColumnsButtonTitle: string;
22
+ toggleDensePaddingSwitchTitle: string;
23
+ toggleFilterButtonTitle: string;
24
+ }
25
+
26
+ export const defaultLocalization: MRT_Localization = {
27
+ actionsHeadColumnTitle: 'Actions',
28
+ columnActionMenuButtonTitle: 'Column Actions',
29
+ columnActionMenuItemClearSort: 'Clear sorting',
30
+ columnActionMenuItemGroupBy: 'Group by column',
31
+ columnActionMenuItemHideColumn: 'Hide column',
32
+ columnActionMenuItemSortAsc: 'Sort ascending',
33
+ columnActionMenuItemSortDesc: 'Sort descending',
34
+ columnActionMenuItemUnGroupBy: 'Ungroup column',
35
+ expandAllButtonTitle: 'Expand all',
36
+ expandButtonTitle: 'Expand',
37
+ filterTextFieldClearButtonTitle: 'Clear filter',
38
+ filterTextFieldPlaceholder: 'Filter',
39
+ rowActionMenuButtonTitle: 'Row Actions',
40
+ rowActionsColumnTitle: 'Actions',
41
+ rowActionMenuItemEdit: 'Edit',
42
+ rowActionButtonSave: 'Save',
43
+ rowActionButtonCancel: 'Cancel',
44
+ searchTextFieldClearButtonTitle: 'Clear search',
45
+ searchTextFieldPlaceholder: 'Search',
46
+ showHideColumnsButtonTitle: 'Show/Hide columns',
47
+ toggleDensePaddingSwitchTitle: 'Toggle dense padding',
48
+ toggleFilterButtonTitle: 'Toggle filters',
49
+ };
@@ -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,15 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableCell } from '@mui/material';
3
- import { Cell } from 'react-table';
4
-
5
- interface Props {
6
- cell: Cell<object>;
7
- }
8
-
9
- export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
10
- return (
11
- <TableCell variant="body" {...cell.getCellProps()}>
12
- {cell.render('Cell')}
13
- </TableCell>
14
- );
15
- };
@@ -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
- };
@@ -1,16 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { Paper, TableContainer } from '@mui/material';
3
- import { useMaterialReactTable } from './useMaterialReactTable';
4
- import { MRT_Table } from './MRT_Table';
5
-
6
- interface Props {}
7
-
8
- export const MRT_TableContainer: FC<Props> = () => {
9
- const { tableContainerProps } = useMaterialReactTable();
10
-
11
- return (
12
- <TableContainer component={Paper} {...tableContainerProps}>
13
- <MRT_Table />
14
- </TableContainer>
15
- );
16
- };
@@ -1,27 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { Collapse, TableCell, TableRow } from '@mui/material';
3
- import { Row } from 'react-table';
4
- import { useMaterialReactTable } from './useMaterialReactTable';
5
-
6
- interface Props {
7
- row: Row<object>;
8
- }
9
-
10
- export const MRT_TableDetailPanel: FC<Props> = ({ row }) => {
11
- const { tableInstance, renderDetailPanel } = useMaterialReactTable();
12
-
13
- return (
14
- <TableRow {...row.getToggleRowExpandedProps()}>
15
- <TableCell
16
- colSpan={tableInstance.visibleColumns.length + 10}
17
- style={{
18
- paddingBottom: row.isExpanded ? '1rem' : 0,
19
- paddingTop: row.isExpanded ? '1rem' : 0,
20
- transition: 'padding 0.2s',
21
- }}
22
- >
23
- <Collapse in={row.isExpanded}>{renderDetailPanel?.(row)}</Collapse>
24
- </TableCell>
25
- </TableRow>
26
- );
27
- };
@@ -1,25 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { IconButton, TableCell } from '@mui/material';
3
- import { Row } from 'react-table';
4
- import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
5
- // import { useMaterialReactTable } from './useMaterialReactTable';
6
-
7
- interface Props {
8
- row: Row<object>;
9
- }
10
-
11
- export const MRT_TableExpandButton: FC<Props> = ({ row }) => {
12
- return (
13
- <TableCell style={{ width: '2rem' }} size="small" variant="head">
14
- <IconButton onClick={() => row.toggleRowExpanded()} size="small">
15
- <ArrowForwardIosIcon
16
- fontSize="small"
17
- style={{
18
- transform: row.isExpanded ? 'rotate(90deg)' : 'rotate(0)',
19
- transition: 'transform 0.2s',
20
- }}
21
- />
22
- </IconButton>
23
- </TableCell>
24
- );
25
- };
@@ -1,31 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableFooter } from '@mui/material';
3
- import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
- import { useMaterialReactTable } from './useMaterialReactTable';
5
- import { MRT_TablePagination } from './MRT_TablePagination';
6
-
7
- interface Props {}
8
-
9
- export const MRT_TableFooter: FC<Props> = () => {
10
- const { tableInstance, tableFooterProps, options } = useMaterialReactTable();
11
-
12
- const hasFooterGroups = tableInstance.columns.some(
13
- (c) => c.depth === 0 && !!c.Footer,
14
- );
15
-
16
- return (
17
- <TableFooter {...tableFooterProps}>
18
- {hasFooterGroups &&
19
- tableInstance.footerGroups.map((footerGroup, index) => (
20
- <MRT_TableFooterRow
21
- key={`${index}-${footerGroup.id}`}
22
- footerGroup={footerGroup}
23
- />
24
- ))}
25
- {options.enablePagination === true ||
26
- (['bottom', 'both'].includes(options.enablePagination.toString()) && (
27
- <MRT_TablePagination />
28
- ))}
29
- </TableFooter>
30
- );
31
- };
@@ -1,25 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { styled, TableCell as MuiTableCell } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
-
5
- const TableCell = styled(MuiTableCell)({
6
- fontWeight: 'bold',
7
- });
8
-
9
- interface Props {
10
- column: HeaderGroup;
11
- }
12
-
13
- export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
14
- const isParentHeader = (column?.columns?.length ?? 0) > 0;
15
-
16
- return (
17
- <TableCell
18
- align={isParentHeader ? 'center' : 'left'}
19
- variant="head"
20
- {...column.getFooterProps()}
21
- >
22
- {column.render('Footer')}
23
- </TableCell>
24
- );
25
- };
@@ -1,22 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableCell, TableRow } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
- import { MRT_TableFooterCell } from './MRT_TableFooterCell';
5
- import { useMaterialReactTable } from './useMaterialReactTable';
6
-
7
- interface Props {
8
- footerGroup: HeaderGroup<object>;
9
- }
10
-
11
- export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
12
- const { renderDetailPanel } = useMaterialReactTable();
13
-
14
- return (
15
- <TableRow {...footerGroup.getFooterGroupProps()}>
16
- {renderDetailPanel && <TableCell style={{ width: '2rem' }} />}
17
- {footerGroup.headers.map((column, index) => (
18
- <MRT_TableFooterCell key={`${index}-${column.id}`} column={column} />
19
- ))}
20
- </TableRow>
21
- );
22
- };
@@ -1,27 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableCell, TableSortLabel } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
-
5
- interface Props {
6
- column: HeaderGroup;
7
- }
8
-
9
- export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
10
- const isParentHeader = (column?.columns?.length ?? 0) > 0;
11
-
12
- return (
13
- <TableCell
14
- align={isParentHeader ? 'center' : 'left'}
15
- style={{ fontWeight: 'bold !important' }}
16
- variant="head"
17
- {...column.getHeaderProps(column.getSortByToggleProps())}
18
- >
19
- <TableSortLabel
20
- active={column.isSorted}
21
- direction={column.isSortedDesc && column.isSortedDesc ? 'desc' : 'asc'}
22
- >
23
- {column.render('Header')}
24
- </TableSortLabel>
25
- </TableCell>
26
- );
27
- };
@@ -1,22 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { TableCell, TableRow } from '@mui/material';
3
- import { HeaderGroup } from 'react-table';
4
- import { MRT_TableHeadCell } from './MRT_TableHeadCell';
5
- import { useMaterialReactTable } from './useMaterialReactTable';
6
-
7
- interface Props {
8
- headerGroup: HeaderGroup<object>;
9
- }
10
-
11
- export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
12
- const { renderDetailPanel } = useMaterialReactTable();
13
-
14
- return (
15
- <TableRow {...headerGroup.getHeaderGroupProps()}>
16
- {renderDetailPanel && <TableCell style={{ width: '2rem' }} />}
17
- {headerGroup.headers.map((column, index) => (
18
- <MRT_TableHeadCell key={`${index}-${column.id}`} column={column} />
19
- ))}
20
- </TableRow>
21
- );
22
- };
@@ -1,34 +0,0 @@
1
- import React, { ChangeEvent, FC } from 'react';
2
- import { TablePagination, TableRow } from '@mui/material';
3
- import { useMaterialReactTable } from './useMaterialReactTable';
4
-
5
- interface Props {}
6
-
7
- export const MRT_TablePagination: FC<Props> = () => {
8
- const { tableInstance, tablePaginationProps } = useMaterialReactTable();
9
-
10
- const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
11
- tableInstance.setPageSize(+event.target.value);
12
- tableInstance.gotoPage(0);
13
- };
14
-
15
- return (
16
- <TableRow>
17
- <TablePagination
18
- colSpan={tableInstance.visibleColumns.length + 10}
19
- count={tableInstance.rows.length}
20
- onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
21
- onRowsPerPageChange={handleChangeRowsPerPage}
22
- page={tableInstance.state.pageIndex}
23
- rowsPerPage={tableInstance.state.pageSize}
24
- showFirstButton={
25
- tableInstance.rows.length / tableInstance.state.pageSize > 2
26
- }
27
- showLastButton={
28
- tableInstance.rows.length / tableInstance.state.pageSize > 2
29
- }
30
- {...tablePaginationProps}
31
- />
32
- </TableRow>
33
- );
34
- };
package/src/defaults.ts DELETED
@@ -1,11 +0,0 @@
1
- import { MaterialReactTableOptions } from '.';
2
-
3
- export const defaultOptions: MaterialReactTableOptions = {
4
- enableFilters: false,
5
- enablePagination: 'bottom',
6
- enableSearch: true,
7
- enableSorting: true,
8
- showFooter: true,
9
- showHead: true,
10
- showToolbar: true,
11
- };