material-react-table 0.4.5 → 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.
- package/README.md +3 -2
- package/dist/MaterialReactTable.d.ts +71 -25
- package/dist/body/MRT_TableBodyCell.d.ts +2 -2
- package/dist/body/MRT_TableBodyRow.d.ts +2 -2
- package/dist/body/MRT_TableDetailPanel.d.ts +2 -2
- package/dist/buttons/MRT_EditActionButtons.d.ts +2 -2
- package/dist/buttons/MRT_ExpandButton.d.ts +2 -2
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +2 -2
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -2
- package/dist/footer/MRT_TableFooterCell.d.ts +2 -2
- package/dist/footer/MRT_TableFooterRow.d.ts +2 -2
- package/dist/head/MRT_TableHeadCell.d.ts +2 -2
- package/dist/head/MRT_TableHeadRow.d.ts +2 -2
- package/dist/icons.d.ts +25 -0
- package/dist/inputs/MRT_EditCellTextField.d.ts +2 -2
- package/dist/inputs/MRT_FilterTextField.d.ts +2 -2
- package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -2
- package/dist/{utils/localization.d.ts → localization.d.ts} +1 -1
- package/dist/material-react-table.cjs.development.js +197 -155
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +198 -156
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
- package/dist/menus/MRT_RowActionMenu.d.ts +2 -2
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -2
- package/dist/useMRT.d.ts +10 -6
- package/package.json +1 -1
- package/src/@types/react-table-config.d.ts +18 -121
- package/src/MaterialReactTable.tsx +188 -25
- package/src/body/MRT_TableBody.tsx +2 -1
- package/src/body/MRT_TableBodyCell.tsx +2 -2
- package/src/body/MRT_TableBodyRow.tsx +11 -9
- package/src/body/MRT_TableDetailPanel.tsx +9 -16
- package/src/buttons/MRT_EditActionButtons.tsx +7 -8
- package/src/buttons/MRT_ExpandAllButton.tsx +17 -18
- package/src/buttons/MRT_ExpandButton.tsx +20 -21
- package/src/buttons/MRT_FullScreenToggleButton.tsx +9 -6
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +11 -7
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +8 -6
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +8 -5
- package/src/buttons/MRT_ToggleFiltersButton.tsx +8 -5
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +8 -9
- package/src/buttons/MRT_ToggleSearchButton.tsx +8 -5
- package/src/footer/MRT_TableFooter.tsx +2 -1
- package/src/footer/MRT_TableFooterCell.tsx +2 -2
- package/src/footer/MRT_TableFooterRow.tsx +3 -3
- package/src/head/MRT_TableHead.tsx +2 -1
- package/src/head/MRT_TableHeadCell.tsx +7 -7
- package/src/head/MRT_TableHeadCellActions.tsx +1 -1
- package/src/head/MRT_TableHeadRow.tsx +3 -3
- package/src/icons.tsx +72 -0
- package/src/index.tsx +2 -0
- package/src/inputs/MRT_EditCellTextField.tsx +2 -2
- package/src/inputs/MRT_FilterTextField.tsx +15 -15
- package/src/inputs/MRT_SearchTextField.tsx +4 -5
- package/src/inputs/MRT_SelectCheckbox.tsx +7 -7
- package/src/{utils/localization.ts → localization.ts} +1 -1
- package/src/menus/MRT_ColumnActionMenu.tsx +16 -14
- package/src/menus/MRT_RowActionMenu.tsx +4 -4
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +3 -2
- package/src/table/MRT_TableContainer.tsx +19 -1
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
- package/src/useMRT.tsx +24 -17
package/src/icons.tsx
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import CancelIcon from '@mui/icons-material/Cancel';
|
|
2
|
+
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
3
|
+
import CloseIcon from '@mui/icons-material/Close';
|
|
4
|
+
import DensityMediumIcon from '@mui/icons-material/DensityMedium';
|
|
5
|
+
import DensitySmallIcon from '@mui/icons-material/DensitySmall';
|
|
6
|
+
import DoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
|
7
|
+
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
8
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
9
|
+
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
|
10
|
+
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
11
|
+
import FilterListIcon from '@mui/icons-material/FilterList';
|
|
12
|
+
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
|
13
|
+
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
|
14
|
+
import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
|
15
|
+
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
16
|
+
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
17
|
+
import SaveIcon from '@mui/icons-material/Save';
|
|
18
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
19
|
+
import SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
20
|
+
import SortIcon from '@mui/icons-material/Sort';
|
|
21
|
+
import ViewColumnIcon from '@mui/icons-material/ViewColumn';
|
|
22
|
+
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
23
|
+
|
|
24
|
+
export interface MRT_Icons {
|
|
25
|
+
CancelIcon: any;
|
|
26
|
+
ClearAllIcon: any;
|
|
27
|
+
CloseIcon: any;
|
|
28
|
+
DensityMediumIcon: any;
|
|
29
|
+
DensitySmallIcon: any;
|
|
30
|
+
DoubleArrowDownIcon: any;
|
|
31
|
+
DynamicFeedIcon: any;
|
|
32
|
+
EditIcon: any;
|
|
33
|
+
ExpandLessIcon: any;
|
|
34
|
+
ExpandMoreIcon: any;
|
|
35
|
+
FilterListIcon: any;
|
|
36
|
+
FilterListOffIcon: any;
|
|
37
|
+
FullscreenExitIcon: any;
|
|
38
|
+
FullscreenIcon: any;
|
|
39
|
+
MoreHorizIcon: any;
|
|
40
|
+
MoreVertIcon: any;
|
|
41
|
+
SaveIcon: any;
|
|
42
|
+
SearchIcon: any;
|
|
43
|
+
SearchOffIcon: any;
|
|
44
|
+
SortIcon: any;
|
|
45
|
+
ViewColumnIcon: any;
|
|
46
|
+
VisibilityOffIcon: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const MRT_Default_Icons: MRT_Icons = {
|
|
50
|
+
CancelIcon,
|
|
51
|
+
ClearAllIcon,
|
|
52
|
+
CloseIcon,
|
|
53
|
+
DensityMediumIcon,
|
|
54
|
+
DensitySmallIcon,
|
|
55
|
+
DoubleArrowDownIcon,
|
|
56
|
+
DynamicFeedIcon,
|
|
57
|
+
EditIcon,
|
|
58
|
+
ExpandLessIcon,
|
|
59
|
+
ExpandMoreIcon,
|
|
60
|
+
FilterListIcon,
|
|
61
|
+
FilterListOffIcon,
|
|
62
|
+
FullscreenExitIcon,
|
|
63
|
+
FullscreenIcon,
|
|
64
|
+
MoreHorizIcon,
|
|
65
|
+
MoreVertIcon,
|
|
66
|
+
SaveIcon,
|
|
67
|
+
SearchIcon,
|
|
68
|
+
SearchOffIcon,
|
|
69
|
+
SortIcon,
|
|
70
|
+
ViewColumnIcon,
|
|
71
|
+
VisibilityOffIcon,
|
|
72
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -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:
|
|
7
|
+
cell: MRT_Cell;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
2
|
import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
|
|
3
|
-
import
|
|
4
|
-
import FilterIcon from '@mui/icons-material/FilterList';
|
|
5
|
-
import { HeaderGroup, useAsyncDebounce } from 'react-table';
|
|
3
|
+
import { useAsyncDebounce } from 'react-table';
|
|
6
4
|
import { useMRT } from '../useMRT';
|
|
5
|
+
import { MRT_HeaderGroup } from '..';
|
|
7
6
|
|
|
8
7
|
interface Props {
|
|
9
|
-
column:
|
|
8
|
+
column: MRT_HeaderGroup;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
13
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
icons: { FilterListIcon, CloseIcon },
|
|
14
|
+
localization,
|
|
15
|
+
} = useMRT();
|
|
14
16
|
|
|
15
17
|
const [filterValue, setFilterValue] = useState('');
|
|
16
18
|
|
|
@@ -37,7 +39,7 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
37
39
|
},
|
|
38
40
|
}}
|
|
39
41
|
margin="dense"
|
|
40
|
-
placeholder={localization
|
|
42
|
+
placeholder={localization.filterTextFieldPlaceholder?.replace(
|
|
41
43
|
'{column}',
|
|
42
44
|
String(column.Header),
|
|
43
45
|
)}
|
|
@@ -52,15 +54,13 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
52
54
|
startAdornment: (
|
|
53
55
|
<Tooltip
|
|
54
56
|
arrow
|
|
55
|
-
title={
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) ?? ''
|
|
60
|
-
}
|
|
57
|
+
title={localization.filterTextFieldPlaceholder?.replace(
|
|
58
|
+
'{column}',
|
|
59
|
+
String(column.Header),
|
|
60
|
+
)}
|
|
61
61
|
>
|
|
62
62
|
<InputAdornment position="start">
|
|
63
|
-
<
|
|
63
|
+
<FilterListIcon />
|
|
64
64
|
</InputAdornment>
|
|
65
65
|
</Tooltip>
|
|
66
66
|
),
|
|
@@ -68,11 +68,11 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
68
68
|
<InputAdornment position="end">
|
|
69
69
|
<Tooltip
|
|
70
70
|
arrow
|
|
71
|
-
title={localization
|
|
71
|
+
title={localization.filterTextFieldClearButtonTitle ?? ''}
|
|
72
72
|
>
|
|
73
73
|
<span>
|
|
74
74
|
<IconButton
|
|
75
|
-
aria-label={localization
|
|
75
|
+
aria-label={localization.filterTextFieldClearButtonTitle}
|
|
76
76
|
disabled={filterValue?.length === 0}
|
|
77
77
|
onClick={handleClear}
|
|
78
78
|
size="small"
|
|
@@ -6,8 +6,6 @@ import {
|
|
|
6
6
|
styled,
|
|
7
7
|
TextField as MuiTextField,
|
|
8
8
|
} from '@mui/material';
|
|
9
|
-
import SearchIcon from '@mui/icons-material/Search';
|
|
10
|
-
import CloseIcon from '@mui/icons-material/Close';
|
|
11
9
|
import { useMRT } from '../useMRT';
|
|
12
10
|
import { useAsyncDebounce } from 'react-table';
|
|
13
11
|
|
|
@@ -19,6 +17,7 @@ interface Props {}
|
|
|
19
17
|
|
|
20
18
|
export const MRT_SearchTextField: FC<Props> = () => {
|
|
21
19
|
const {
|
|
20
|
+
icons: { SearchIcon, CloseIcon },
|
|
22
21
|
showSearch,
|
|
23
22
|
localization,
|
|
24
23
|
muiSearchTextFieldProps,
|
|
@@ -45,7 +44,7 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
45
44
|
<Collapse in={showSearch} orientation="horizontal">
|
|
46
45
|
<TextField
|
|
47
46
|
id="global-search-text-field"
|
|
48
|
-
placeholder={localization
|
|
47
|
+
placeholder={localization.searchTextFieldPlaceholder}
|
|
49
48
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
50
49
|
setSearchValue(event.target.value);
|
|
51
50
|
handleChange(event);
|
|
@@ -61,11 +60,11 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
61
60
|
endAdornment: (
|
|
62
61
|
<InputAdornment position="end">
|
|
63
62
|
<IconButton
|
|
64
|
-
aria-label={localization
|
|
63
|
+
aria-label={localization.searchTextFieldClearButtonTitle}
|
|
65
64
|
disabled={searchValue?.length === 0}
|
|
66
65
|
onClick={handleClear}
|
|
67
66
|
size="small"
|
|
68
|
-
title={localization
|
|
67
|
+
title={localization.searchTextFieldClearButtonTitle}
|
|
69
68
|
>
|
|
70
69
|
<CloseIcon fontSize="small" />
|
|
71
70
|
</IconButton>
|
|
@@ -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?:
|
|
8
|
+
row?: MRT_Row;
|
|
9
9
|
selectAll?: boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -20,8 +20,8 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
|
20
20
|
|
|
21
21
|
const onSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
22
22
|
if (selectAll) {
|
|
23
|
+
tableInstance?.getToggleAllRowsSelectedProps?.()?.onChange?.(event);
|
|
23
24
|
onSelectAllChange?.(event, tableInstance.selectedFlatRows);
|
|
24
|
-
tableInstance.toggleAllRowsSelected(event.target.checked);
|
|
25
25
|
} else if (row) {
|
|
26
26
|
row?.getToggleRowSelectedProps()?.onChange?.(event);
|
|
27
27
|
onRowSelectChange?.(event, row, tableInstance.selectedFlatRows);
|
|
@@ -40,15 +40,15 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
|
40
40
|
enterNextDelay={1000}
|
|
41
41
|
title={
|
|
42
42
|
selectAll
|
|
43
|
-
? localization
|
|
44
|
-
: localization
|
|
43
|
+
? localization.selectAllCheckboxTitle
|
|
44
|
+
: localization.selectCheckboxTitle
|
|
45
45
|
}
|
|
46
46
|
>
|
|
47
47
|
<Checkbox
|
|
48
48
|
inputProps={{
|
|
49
49
|
'aria-label': selectAll
|
|
50
|
-
? localization
|
|
51
|
-
: localization
|
|
50
|
+
? localization.selectAllCheckboxTitle
|
|
51
|
+
: localization.selectCheckboxTitle,
|
|
52
52
|
}}
|
|
53
53
|
onChange={onSelectChange}
|
|
54
54
|
{...checkboxProps}
|
|
@@ -32,7 +32,7 @@ export interface MRT_Localization {
|
|
|
32
32
|
toolbarAlertGroupedThenByMessage: string;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export const
|
|
35
|
+
export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
36
36
|
actionsHeadColumnTitle: 'Actions',
|
|
37
37
|
columnActionMenuButtonTitle: 'Column Actions',
|
|
38
38
|
columnActionMenuItemClearSort: 'Clear sort',
|
|
@@ -1,12 +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 {
|
|
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
|
-
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
9
|
-
import FilterIcon from '@mui/icons-material/FilterList';
|
|
4
|
+
import { MRT_HeaderGroup } from '..';
|
|
10
5
|
|
|
11
6
|
const MenuItem = styled(MuiMenuItem)({
|
|
12
7
|
display: 'flex',
|
|
@@ -15,7 +10,7 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
15
10
|
|
|
16
11
|
interface Props {
|
|
17
12
|
anchorEl: HTMLElement | null;
|
|
18
|
-
column:
|
|
13
|
+
column: MRT_HeaderGroup;
|
|
19
14
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
20
15
|
}
|
|
21
16
|
|
|
@@ -31,6 +26,13 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
31
26
|
enableColumnGrouping,
|
|
32
27
|
localization,
|
|
33
28
|
setShowFilters,
|
|
29
|
+
icons: {
|
|
30
|
+
FilterListIcon,
|
|
31
|
+
SortIcon,
|
|
32
|
+
ClearAllIcon,
|
|
33
|
+
DynamicFeedIcon,
|
|
34
|
+
VisibilityOffIcon,
|
|
35
|
+
},
|
|
34
36
|
} = useMRT();
|
|
35
37
|
|
|
36
38
|
const handleClearSort = () => {
|
|
@@ -87,7 +89,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
87
89
|
disabled={!column.isSorted}
|
|
88
90
|
onClick={handleClearSort}
|
|
89
91
|
>
|
|
90
|
-
<ClearAllIcon /> {localization
|
|
92
|
+
<ClearAllIcon /> {localization.columnActionMenuItemClearSort}
|
|
91
93
|
</MenuItem>,
|
|
92
94
|
<MenuItem
|
|
93
95
|
key={2}
|
|
@@ -95,7 +97,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
95
97
|
onClick={handleSortAsc}
|
|
96
98
|
>
|
|
97
99
|
<SortIcon />{' '}
|
|
98
|
-
{localization
|
|
100
|
+
{localization.columnActionMenuItemSortAsc?.replace(
|
|
99
101
|
'{column}',
|
|
100
102
|
String(column.Header),
|
|
101
103
|
)}
|
|
@@ -106,7 +108,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
106
108
|
onClick={handleSortDesc}
|
|
107
109
|
>
|
|
108
110
|
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
|
|
109
|
-
{localization
|
|
111
|
+
{localization.columnActionMenuItemSortDesc?.replace(
|
|
110
112
|
'{column}',
|
|
111
113
|
String(column.Header),
|
|
112
114
|
)}
|
|
@@ -116,8 +118,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
116
118
|
column.canFilter && [
|
|
117
119
|
<Divider key={0} />,
|
|
118
120
|
<MenuItem key={1} onClick={handleFilterByColumn}>
|
|
119
|
-
<
|
|
120
|
-
{localization
|
|
121
|
+
<FilterListIcon />{' '}
|
|
122
|
+
{localization.filterTextFieldPlaceholder?.replace(
|
|
121
123
|
'{column}',
|
|
122
124
|
String(column.Header),
|
|
123
125
|
)}
|
|
@@ -128,7 +130,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
128
130
|
<Divider key={1} />,
|
|
129
131
|
<MenuItem key={2} onClick={handleGroupByColumn}>
|
|
130
132
|
<DynamicFeedIcon />{' '}
|
|
131
|
-
{localization
|
|
133
|
+
{localization[
|
|
132
134
|
column.isGrouped
|
|
133
135
|
? 'columnActionMenuItemUnGroupBy'
|
|
134
136
|
: 'columnActionMenuItemGroupBy'
|
|
@@ -139,7 +141,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
139
141
|
<Divider key={0} />,
|
|
140
142
|
<MenuItem key={1} onClick={handleHideColumn}>
|
|
141
143
|
<VisibilityOffIcon />{' '}
|
|
142
|
-
{localization
|
|
144
|
+
{localization.columnActionMenuItemHideColumn?.replace(
|
|
143
145
|
'{column}',
|
|
144
146
|
String(column.Header),
|
|
145
147
|
)}
|
|
@@ -1,8 +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 {
|
|
5
|
-
import EditIcon from '@mui/icons-material/Edit';
|
|
4
|
+
import { MRT_Row } from '..';
|
|
6
5
|
|
|
7
6
|
const MenuItem = styled(MuiMenuItem)({
|
|
8
7
|
display: 'flex',
|
|
@@ -11,7 +10,7 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
11
10
|
|
|
12
11
|
interface Props {
|
|
13
12
|
anchorEl: HTMLElement | null;
|
|
14
|
-
row:
|
|
13
|
+
row: MRT_Row;
|
|
15
14
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
16
15
|
handleEdit: () => void;
|
|
17
16
|
}
|
|
@@ -23,6 +22,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
23
22
|
setAnchorEl,
|
|
24
23
|
}) => {
|
|
25
24
|
const {
|
|
25
|
+
icons: { EditIcon },
|
|
26
26
|
enableRowEditing,
|
|
27
27
|
localization,
|
|
28
28
|
renderRowActionMenuItems,
|
|
@@ -37,7 +37,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
37
37
|
>
|
|
38
38
|
{enableRowEditing && (
|
|
39
39
|
<MenuItem onClick={handleEdit}>
|
|
40
|
-
<EditIcon /> {localization
|
|
40
|
+
<EditIcon /> {localization.rowActionMenuItemEdit}
|
|
41
41
|
</MenuItem>
|
|
42
42
|
)}
|
|
43
43
|
{renderRowActionMenuItems?.(row, tableInstance, () =>
|
|
@@ -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:
|
|
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
|
</>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { FC, useEffect, useRef } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
CircularProgress,
|
|
4
4
|
LinearProgress,
|
|
@@ -50,6 +50,24 @@ export const MRT_TableContainer: FC<Props> = () => {
|
|
|
50
50
|
muiTableContainerProps,
|
|
51
51
|
tableInstance,
|
|
52
52
|
} = useMRT();
|
|
53
|
+
const originalBodyOverflowStyle = useRef<string | undefined>();
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (typeof window !== 'undefined') {
|
|
57
|
+
originalBodyOverflowStyle.current = document?.body?.style?.overflow;
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (typeof window !== 'undefined') {
|
|
63
|
+
if (fullScreen) {
|
|
64
|
+
document.body.style.overflow = 'hidden';
|
|
65
|
+
} else {
|
|
66
|
+
document.body.style.overflow =
|
|
67
|
+
originalBodyOverflowStyle.current ?? 'auto';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, [fullScreen]);
|
|
53
71
|
|
|
54
72
|
const tableContainerProps =
|
|
55
73
|
muiTableContainerProps instanceof Function
|
|
@@ -47,7 +47,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
|
47
47
|
|
|
48
48
|
const selectMessage =
|
|
49
49
|
tableInstance.selectedFlatRows.length > 0
|
|
50
|
-
? localization
|
|
50
|
+
? localization.toolbarAlertSelectionMessage
|
|
51
51
|
?.replace(
|
|
52
52
|
'{selectedCount}',
|
|
53
53
|
tableInstance.selectedFlatRows.length.toString(),
|
|
@@ -58,10 +58,10 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
|
58
58
|
const groupedByMessage =
|
|
59
59
|
tableInstance.state.groupBy.length > 0 ? (
|
|
60
60
|
<span>
|
|
61
|
-
{localization
|
|
61
|
+
{localization.toolbarAlertGroupedByMessage}{' '}
|
|
62
62
|
{tableInstance.state.groupBy.map((columnId, index) => (
|
|
63
63
|
<Fragment key={`${index}-${columnId}`}>
|
|
64
|
-
{index > 0 ? localization
|
|
64
|
+
{index > 0 ? localization.toolbarAlertGroupedThenByMessage : ''}
|
|
65
65
|
<Chip
|
|
66
66
|
color="secondary"
|
|
67
67
|
label={
|
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,23 +19,28 @@ import {
|
|
|
21
19
|
useSortBy,
|
|
22
20
|
useTable,
|
|
23
21
|
} from 'react-table';
|
|
22
|
+
import { MRT_Row, MRT_TableInstance } from '.';
|
|
23
|
+
import { MRT_Icons } from './icons';
|
|
24
|
+
import { MRT_Localization } from './localization';
|
|
24
25
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
25
26
|
|
|
26
|
-
export
|
|
27
|
+
export type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
27
28
|
anyRowsCanExpand: boolean;
|
|
28
29
|
anyRowsExpanded: boolean;
|
|
29
|
-
currentEditingRow:
|
|
30
|
+
currentEditingRow: MRT_Row<D> | null;
|
|
30
31
|
densePadding: boolean;
|
|
31
32
|
fullScreen: boolean;
|
|
32
|
-
|
|
33
|
+
icons: MRT_Icons;
|
|
34
|
+
localization: MRT_Localization;
|
|
35
|
+
setCurrentEditingRow: (currentRowEditingId: MRT_Row<D> | null) => void;
|
|
33
36
|
setDensePadding: (densePadding: boolean) => void;
|
|
34
37
|
setFullScreen: (fullScreen: boolean) => void;
|
|
35
38
|
setShowFilters: (showFilters: boolean) => void;
|
|
36
39
|
setShowSearch: (showSearch: boolean) => void;
|
|
37
40
|
showFilters: boolean;
|
|
38
41
|
showSearch: boolean;
|
|
39
|
-
tableInstance:
|
|
40
|
-
}
|
|
42
|
+
tableInstance: MRT_TableInstance<D>;
|
|
43
|
+
};
|
|
41
44
|
|
|
42
45
|
const MaterialReactTableContext = (<D extends {}>() =>
|
|
43
46
|
createContext<UseMRT<D>>({} as UseMRT<D>) as Context<UseMRT<D>>)();
|
|
@@ -58,28 +61,32 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
58
61
|
if (props.enableColumnResizing)
|
|
59
62
|
hooks.unshift(useResizeColumns, useFlexLayout);
|
|
60
63
|
|
|
61
|
-
const tableInstance = useTable<D>(props, ...hooks)
|
|
64
|
+
const tableInstance = useTable<D>(props, ...hooks) as MRT_TableInstance<D>;
|
|
62
65
|
|
|
63
66
|
const anyRowsCanExpand = useMemo(
|
|
64
|
-
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
() => tableInstance.rows.some((row: MRT_Row) => row.canExpand),
|
|
65
69
|
[tableInstance.rows],
|
|
66
70
|
);
|
|
67
71
|
const anyRowsExpanded = useMemo(
|
|
68
|
-
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
() => tableInstance.rows.some((row: MRT_Row) => row.isExpanded),
|
|
69
74
|
[tableInstance.rows],
|
|
70
75
|
);
|
|
71
|
-
const [currentEditingRow, setCurrentEditingRow] = useState<
|
|
76
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
|
|
77
|
+
null,
|
|
78
|
+
);
|
|
72
79
|
const [densePadding, setDensePadding] = useState(
|
|
73
|
-
props.
|
|
80
|
+
props.initialState?.densePadding ?? false,
|
|
74
81
|
);
|
|
75
82
|
const [fullScreen, setFullScreen] = useState(
|
|
76
|
-
props.
|
|
83
|
+
props.initialState?.fullScreen ?? false,
|
|
77
84
|
);
|
|
78
85
|
const [showFilters, setShowFilters] = useState(
|
|
79
|
-
props.
|
|
86
|
+
props.initialState?.showFilters ?? false,
|
|
80
87
|
);
|
|
81
88
|
const [showSearch, setShowSearch] = useState(
|
|
82
|
-
props.
|
|
89
|
+
props.initialState?.showSearchTextField ?? false,
|
|
83
90
|
);
|
|
84
91
|
|
|
85
92
|
return (
|
|
@@ -108,5 +115,5 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
108
115
|
};
|
|
109
116
|
|
|
110
117
|
export const useMRT = <D extends {}>(): UseMRT<D> =>
|
|
111
|
-
|
|
118
|
+
// @ts-ignore
|
|
112
119
|
useContext<UseMRT<D>>(MaterialReactTableContext);
|