material-react-table 0.3.3 → 0.3.4
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/dist/MaterialReactTable.d.ts +8 -5
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
- package/dist/inputs/{MRT_EditCellTextfield.d.ts → MRT_EditCellTextField.d.ts} +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +250 -160
- 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 +253 -163
- 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 +1 -0
- package/dist/table/MRT_TableButtonCell.d.ts +3 -0
- package/dist/useMaterialReactTable.d.ts +2 -0
- package/dist/utils/localization.d.ts +2 -0
- package/dist/utils/useMRTCalcs.d.ts +1 -1
- package/package.json +8 -6
- package/src/@types/react-table-config.d.ts +33 -55
- package/src/MaterialReactTable.tsx +22 -54
- package/src/body/MRT_TableBody.tsx +1 -2
- package/src/body/MRT_TableBodyCell.tsx +7 -14
- package/src/body/MRT_TableBodyRow.tsx +7 -24
- package/src/body/MRT_TableDetailPanel.tsx +3 -12
- package/src/buttons/MRT_EditActionButtons.tsx +4 -10
- package/src/buttons/MRT_ExpandAllButton.tsx +7 -18
- package/src/buttons/MRT_ExpandButton.tsx +8 -15
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +2 -9
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -8
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +42 -24
- package/src/buttons/MRT_ToggleSearchButton.tsx +29 -0
- package/src/footer/MRT_TableFooter.tsx +1 -4
- package/src/footer/MRT_TableFooterCell.tsx +2 -4
- package/src/footer/MRT_TableFooterRow.tsx +4 -10
- package/src/head/MRT_TableHead.tsx +2 -7
- package/src/head/MRT_TableHeadCell.tsx +15 -15
- package/src/head/MRT_TableHeadRow.tsx +2 -4
- package/src/inputs/MRT_DensePaddingSwitch.tsx +4 -2
- package/src/inputs/{MRT_EditCellTextfield.tsx → MRT_EditCellTextField.tsx} +21 -14
- package/src/inputs/MRT_FilterTextField.tsx +39 -16
- package/src/inputs/MRT_SearchTextField.tsx +40 -43
- package/src/inputs/MRT_SelectAllCheckbox.tsx +8 -13
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -13
- package/src/menus/MRT_ColumnActionMenu.tsx +51 -35
- package/src/menus/MRT_RowActionMenu.tsx +6 -25
- package/src/table/MRT_Table.tsx +1 -2
- package/src/table/MRT_TableButtonCell.tsx +9 -0
- package/src/table/MRT_TableContainer.tsx +2 -7
- package/src/table/MRT_TableSpacerCell.tsx +1 -3
- package/src/toolbar/MRT_TablePagination.tsx +3 -6
- package/src/toolbar/MRT_ToolbarBottom.tsx +4 -6
- package/src/toolbar/MRT_ToolbarButtons.tsx +3 -1
- package/src/toolbar/MRT_ToolbarTop.tsx +8 -17
- package/src/useMaterialReactTable.tsx +14 -21
- package/src/utils/localization.ts +10 -6
- package/src/utils/useMRTCalcs.tsx +1 -3
|
@@ -26,16 +26,9 @@ export const MRT_ShowHideColumnsButton: FC<Props> = () => {
|
|
|
26
26
|
<ViewColumnIcon />
|
|
27
27
|
</IconButton>
|
|
28
28
|
</Tooltip>
|
|
29
|
-
<Menu
|
|
30
|
-
anchorEl={anchorEl}
|
|
31
|
-
open={!!anchorEl}
|
|
32
|
-
onClose={() => setAnchorEl(null)}
|
|
33
|
-
>
|
|
29
|
+
<Menu anchorEl={anchorEl} open={!!anchorEl} onClose={() => setAnchorEl(null)}>
|
|
34
30
|
{tableInstance.columns.map((column, index) => (
|
|
35
|
-
<MRT_ShowHideColumnsMenu
|
|
36
|
-
key={`${index}-${column.id}`}
|
|
37
|
-
column={column}
|
|
38
|
-
/>
|
|
31
|
+
<MRT_ShowHideColumnsMenu key={`${index}-${column.id}`} column={column} />
|
|
39
32
|
))}
|
|
40
33
|
</Menu>
|
|
41
34
|
</>
|
|
@@ -9,8 +9,8 @@ const IconButton = styled(MuiIconButton)({
|
|
|
9
9
|
opacity: 0.5,
|
|
10
10
|
transition: 'opacity 0.2s',
|
|
11
11
|
marginRight: '2px',
|
|
12
|
-
height: '
|
|
13
|
-
width: '
|
|
12
|
+
height: '1.6rem',
|
|
13
|
+
width: '1.6rem',
|
|
14
14
|
'&:hover': {
|
|
15
15
|
opacity: 1,
|
|
16
16
|
},
|
|
@@ -35,17 +35,13 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
|
35
35
|
<>
|
|
36
36
|
<IconButton
|
|
37
37
|
aria-label={localization?.columnActionMenuButtonTitle}
|
|
38
|
-
title={localization?.columnActionMenuButtonTitle}
|
|
39
38
|
onClick={handleClick}
|
|
40
39
|
size="small"
|
|
40
|
+
title={localization?.columnActionMenuButtonTitle}
|
|
41
41
|
>
|
|
42
42
|
<MoreVertIcon />
|
|
43
43
|
</IconButton>
|
|
44
|
-
<MRT_ColumnActionMenu
|
|
45
|
-
anchorEl={anchorEl}
|
|
46
|
-
column={column}
|
|
47
|
-
setAnchorEl={setAnchorEl}
|
|
48
|
-
/>
|
|
44
|
+
<MRT_ColumnActionMenu anchorEl={anchorEl} column={column} setAnchorEl={setAnchorEl} />
|
|
49
45
|
</>
|
|
50
46
|
);
|
|
51
47
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
|
-
import { IconButton as MuiIconButton, styled } from '@mui/material';
|
|
2
|
+
import { IconButton as MuiIconButton, styled, Tooltip } from '@mui/material';
|
|
3
3
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
4
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
4
5
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
6
|
import { Row } from 'react-table';
|
|
6
7
|
import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
|
|
7
8
|
import { MRT_EditActionButtons } from './MRT_EditActionButtons';
|
|
9
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
8
10
|
|
|
9
11
|
const IconButton = styled(MuiIconButton)({
|
|
10
12
|
opacity: 0.5,
|
|
@@ -23,8 +25,12 @@ interface Props {
|
|
|
23
25
|
|
|
24
26
|
export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
|
|
25
27
|
const {
|
|
26
|
-
localization,
|
|
27
28
|
currentEditingRow,
|
|
29
|
+
densePadding,
|
|
30
|
+
localization,
|
|
31
|
+
renderRowActionMenuItems,
|
|
32
|
+
enableRowEditing,
|
|
33
|
+
setCurrentEditingRow,
|
|
28
34
|
renderRowActions,
|
|
29
35
|
tableInstance,
|
|
30
36
|
} = useMaterialReactTable();
|
|
@@ -37,29 +43,41 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
|
|
|
37
43
|
setAnchorEl(event.currentTarget);
|
|
38
44
|
};
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (row.id === currentEditingRow?.id) {
|
|
45
|
-
return <MRT_EditActionButtons row={row} />;
|
|
46
|
-
}
|
|
46
|
+
const handleEdit = () => {
|
|
47
|
+
setCurrentEditingRow({ ...row });
|
|
48
|
+
setAnchorEl(null);
|
|
49
|
+
};
|
|
47
50
|
|
|
48
51
|
return (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
<MRT_TableButtonCell densePadding={densePadding}>
|
|
53
|
+
{renderRowActions ? (
|
|
54
|
+
<>{renderRowActions(row, tableInstance)}</>
|
|
55
|
+
) : row.id === currentEditingRow?.id ? (
|
|
56
|
+
<MRT_EditActionButtons row={row} />
|
|
57
|
+
) : !renderRowActionMenuItems && enableRowEditing ? (
|
|
58
|
+
<Tooltip placement="right" arrow title={localization?.rowActionMenuItemEdit ?? ''}>
|
|
59
|
+
<IconButton onClick={handleEdit}>
|
|
60
|
+
<EditIcon />
|
|
61
|
+
</IconButton>
|
|
62
|
+
</Tooltip>
|
|
63
|
+
) : renderRowActionMenuItems ? (
|
|
64
|
+
<>
|
|
65
|
+
<IconButton
|
|
66
|
+
aria-label={localization?.rowActionMenuButtonTitle}
|
|
67
|
+
title={localization?.rowActionMenuButtonTitle}
|
|
68
|
+
onClick={handleOpenRowActionMenu}
|
|
69
|
+
size="small"
|
|
70
|
+
>
|
|
71
|
+
<MoreHorizIcon />
|
|
72
|
+
</IconButton>
|
|
73
|
+
<MRT_RowActionMenu
|
|
74
|
+
anchorEl={anchorEl}
|
|
75
|
+
handleEdit={handleEdit}
|
|
76
|
+
row={row}
|
|
77
|
+
setAnchorEl={setAnchorEl}
|
|
78
|
+
/>
|
|
79
|
+
</>
|
|
80
|
+
) : null}
|
|
81
|
+
</MRT_TableButtonCell>
|
|
64
82
|
);
|
|
65
83
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
5
|
+
import SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
6
|
+
|
|
7
|
+
type Props = {};
|
|
8
|
+
|
|
9
|
+
export const MRT_ToggleSearchButton: FC<Props> = () => {
|
|
10
|
+
const { localization, setShowSearch, showSearch, muiSearchTextFieldProps } =
|
|
11
|
+
useMaterialReactTable();
|
|
12
|
+
|
|
13
|
+
const handleToggleSearch = () => {
|
|
14
|
+
setShowSearch(!showSearch);
|
|
15
|
+
setTimeout(
|
|
16
|
+
() =>
|
|
17
|
+
document.getElementById(muiSearchTextFieldProps?.id ?? `global-search-text-field`)?.focus(),
|
|
18
|
+
200,
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Tooltip arrow title={localization?.toggleSearchButtonTitle ?? ''}>
|
|
24
|
+
<IconButton size="small" onClick={handleToggleSearch}>
|
|
25
|
+
{showSearch ? <SearchOffIcon /> : <SearchIcon />}
|
|
26
|
+
</IconButton>
|
|
27
|
+
</Tooltip>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -11,10 +11,7 @@ export const MRT_TableFooter: FC<Props> = () => {
|
|
|
11
11
|
return (
|
|
12
12
|
<TableFooter {...muiTableFooterProps}>
|
|
13
13
|
{tableInstance.footerGroups.map((footerGroup) => (
|
|
14
|
-
<MRT_TableFooterRow
|
|
15
|
-
key={footerGroup.getFooterGroupProps().key}
|
|
16
|
-
footerGroup={footerGroup}
|
|
17
|
-
/>
|
|
14
|
+
<MRT_TableFooterRow key={footerGroup.getFooterGroupProps().key} footerGroup={footerGroup} />
|
|
18
15
|
))}
|
|
19
16
|
</TableFooter>
|
|
20
17
|
);
|
|
@@ -4,8 +4,7 @@ import { HeaderGroup } from 'react-table';
|
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
|
|
6
6
|
const TableCell = styled(MuiTableCell, {
|
|
7
|
-
shouldForwardProp: (prop) =>
|
|
8
|
-
prop !== 'densePadding' && prop !== 'enableColumnResizing',
|
|
7
|
+
shouldForwardProp: (prop) => prop !== 'densePadding' && prop !== 'enableColumnResizing',
|
|
9
8
|
})<{ densePadding?: boolean; enableColumnResizing?: boolean }>(
|
|
10
9
|
({ densePadding, enableColumnResizing }) => ({
|
|
11
10
|
fontWeight: 'bold',
|
|
@@ -20,8 +19,7 @@ interface Props {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
|
|
23
|
-
const { muiTableFooterCellProps, densePadding, enableColumnResizing } =
|
|
24
|
-
useMaterialReactTable();
|
|
22
|
+
const { muiTableFooterCellProps, densePadding, enableColumnResizing } = useMaterialReactTable();
|
|
25
23
|
|
|
26
24
|
const isParentHeader = (column?.columns?.length ?? 0) > 0;
|
|
27
25
|
|
|
@@ -40,23 +40,17 @@ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
|
|
|
40
40
|
|
|
41
41
|
return (
|
|
42
42
|
<TableRow {...tableRowProps}>
|
|
43
|
-
{enableRowActions && positionActionsColumn === 'first' &&
|
|
44
|
-
<MRT_TableSpacerCell />
|
|
45
|
-
)}
|
|
43
|
+
{enableRowActions && positionActionsColumn === 'first' && <MRT_TableSpacerCell />}
|
|
46
44
|
{(anyRowsCanExpand || renderDetailPanel) && (
|
|
47
45
|
<MRT_TableSpacerCell
|
|
48
|
-
width={`${
|
|
49
|
-
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
50
|
-
}rem`}
|
|
46
|
+
width={`${renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5}rem`}
|
|
51
47
|
/>
|
|
52
48
|
)}
|
|
53
49
|
{enableSelection && <MRT_TableSpacerCell width="1rem" />}
|
|
54
|
-
{footerGroup.headers.map((column
|
|
50
|
+
{footerGroup.headers.map((column) => (
|
|
55
51
|
<MRT_TableFooterCell key={column.getFooterProps().key} column={column} />
|
|
56
52
|
))}
|
|
57
|
-
{enableRowActions && positionActionsColumn === 'last' &&
|
|
58
|
-
<MRT_TableSpacerCell />
|
|
59
|
-
)}
|
|
53
|
+
{enableRowActions && positionActionsColumn === 'last' && <MRT_TableSpacerCell />}
|
|
60
54
|
</TableRow>
|
|
61
55
|
);
|
|
62
56
|
};
|
|
@@ -9,17 +9,12 @@ export const MRT_TableHead: FC<Props> = () => {
|
|
|
9
9
|
const { tableInstance, muiTableHeadProps } = useMaterialReactTable();
|
|
10
10
|
|
|
11
11
|
const tableHeadProps =
|
|
12
|
-
muiTableHeadProps instanceof Function
|
|
13
|
-
? muiTableHeadProps(tableInstance)
|
|
14
|
-
: muiTableHeadProps;
|
|
12
|
+
muiTableHeadProps instanceof Function ? muiTableHeadProps(tableInstance) : muiTableHeadProps;
|
|
15
13
|
|
|
16
14
|
return (
|
|
17
15
|
<TableHead {...tableHeadProps}>
|
|
18
16
|
{tableInstance.headerGroups.map((headerGroup) => (
|
|
19
|
-
<MRT_TableHeadRow
|
|
20
|
-
key={headerGroup.getHeaderGroupProps().key}
|
|
21
|
-
headerGroup={headerGroup}
|
|
22
|
-
/>
|
|
17
|
+
<MRT_TableHeadRow key={headerGroup.getHeaderGroupProps().key} headerGroup={headerGroup} />
|
|
23
18
|
))}
|
|
24
19
|
</TableHead>
|
|
25
20
|
);
|
|
@@ -8,35 +8,38 @@ import {
|
|
|
8
8
|
} from '@mui/material';
|
|
9
9
|
import { HeaderGroup } from 'react-table';
|
|
10
10
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
11
|
-
import {
|
|
11
|
+
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
12
12
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
13
13
|
|
|
14
14
|
export const StyledTableHeadCell = styled(MuiTableCell, {
|
|
15
|
-
shouldForwardProp: (prop) =>
|
|
16
|
-
prop !== 'densePadding' && prop !== 'enableColumnResizing',
|
|
15
|
+
shouldForwardProp: (prop) => prop !== 'densePadding' && prop !== 'enableColumnResizing',
|
|
17
16
|
})<{ densePadding?: boolean; enableColumnResizing?: boolean }>(
|
|
18
17
|
({ densePadding, enableColumnResizing }) => ({
|
|
19
18
|
fontWeight: 'bold',
|
|
20
|
-
|
|
19
|
+
height: '100%',
|
|
21
20
|
padding: densePadding ? '0.5rem' : '1rem',
|
|
22
21
|
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
22
|
+
verticalAlign: 'text-top',
|
|
23
23
|
}),
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const TableCellWrapper = styled('div')({
|
|
27
|
+
alignContent: 'space-between',
|
|
27
28
|
display: 'grid',
|
|
29
|
+
height: '100%',
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
const
|
|
32
|
+
const TableCellTopContents = styled('div')({
|
|
31
33
|
width: '100%',
|
|
32
34
|
display: 'flex',
|
|
33
35
|
justifyContent: 'space-between',
|
|
36
|
+
alignItems: 'flex-start',
|
|
34
37
|
});
|
|
35
38
|
|
|
36
39
|
const CellFlexItem = styled('span')({
|
|
40
|
+
alignItems: 'center',
|
|
37
41
|
display: 'flex',
|
|
38
42
|
flexWrap: 'nowrap',
|
|
39
|
-
alignItems: 'center',
|
|
40
43
|
});
|
|
41
44
|
|
|
42
45
|
const Divider = styled(MuiDivider)({
|
|
@@ -91,10 +94,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
91
94
|
enableColumnResizing={enableColumnResizing}
|
|
92
95
|
{...tableCellProps}
|
|
93
96
|
>
|
|
94
|
-
<
|
|
95
|
-
<
|
|
96
|
-
style={{ justifyContent: isParentHeader ? 'center' : undefined }}
|
|
97
|
-
>
|
|
97
|
+
<TableCellWrapper>
|
|
98
|
+
<TableCellTopContents style={{ justifyContent: isParentHeader ? 'center' : undefined }}>
|
|
98
99
|
<CellFlexItem {...column.getSortByToggleProps()}>
|
|
99
100
|
{column.render('Header')}
|
|
100
101
|
{!isParentHeader && column.canSort && (
|
|
@@ -108,7 +109,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
108
109
|
}
|
|
109
110
|
active={column.isSorted}
|
|
110
111
|
direction={column.isSortedDesc ? 'desc' : 'asc'}
|
|
111
|
-
style={{ margin: 0 }}
|
|
112
112
|
/>
|
|
113
113
|
)}
|
|
114
114
|
</CellFlexItem>
|
|
@@ -125,13 +125,13 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
125
125
|
/>
|
|
126
126
|
)}
|
|
127
127
|
</CellFlexItem>
|
|
128
|
-
</
|
|
128
|
+
</TableCellTopContents>
|
|
129
129
|
{!disableFilters && column.canFilter && (
|
|
130
130
|
<Collapse in={showFilters}>
|
|
131
|
-
<
|
|
131
|
+
<MRT_FilterTextField column={column} />
|
|
132
132
|
</Collapse>
|
|
133
133
|
)}
|
|
134
|
-
</
|
|
134
|
+
</TableCellWrapper>
|
|
135
135
|
</StyledTableHeadCell>
|
|
136
136
|
);
|
|
137
137
|
};
|
|
@@ -51,7 +51,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
|
51
51
|
(isParentHeader ? (
|
|
52
52
|
<MRT_TableSpacerCell />
|
|
53
53
|
) : (
|
|
54
|
-
<StyledTableHeadCell>
|
|
54
|
+
<StyledTableHeadCell style={{ textAlign: 'center' }}>
|
|
55
55
|
{localization?.actionsHeadColumnTitle}
|
|
56
56
|
</StyledTableHeadCell>
|
|
57
57
|
))}
|
|
@@ -60,9 +60,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
|
60
60
|
<MRT_ExpandAllButton />
|
|
61
61
|
) : (
|
|
62
62
|
<MRT_TableSpacerCell
|
|
63
|
-
width={`${
|
|
64
|
-
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
65
|
-
}rem`}
|
|
63
|
+
width={`${renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5}rem`}
|
|
66
64
|
/>
|
|
67
65
|
)
|
|
68
66
|
) : null}
|
|
@@ -5,12 +5,14 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
|
5
5
|
interface Props {}
|
|
6
6
|
|
|
7
7
|
export const MRT_DensePaddingSwitch: FC<Props> = () => {
|
|
8
|
-
const { densePadding, setDensePadding, localization } =
|
|
9
|
-
useMaterialReactTable();
|
|
8
|
+
const { densePadding, setDensePadding, localization } = useMaterialReactTable();
|
|
10
9
|
|
|
11
10
|
return (
|
|
12
11
|
<Tooltip arrow title={localization?.toggleDensePaddingSwitchTitle ?? ''}>
|
|
13
12
|
<Switch
|
|
13
|
+
inputProps={{
|
|
14
|
+
'aria-label': localization?.toggleDensePaddingSwitchTitle ?? '',
|
|
15
|
+
}}
|
|
14
16
|
color="default"
|
|
15
17
|
checked={densePadding}
|
|
16
18
|
size="small"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TextField } from '@mui/material';
|
|
2
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
+
import { TextField } from '@mui/material';
|
|
3
3
|
import { Cell } from 'react-table';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
|
|
@@ -7,26 +7,37 @@ interface Props {
|
|
|
7
7
|
cell: Cell;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
11
11
|
const {
|
|
12
|
-
localization,
|
|
13
12
|
currentEditingRow,
|
|
14
|
-
|
|
13
|
+
localization,
|
|
15
14
|
muiTableBodyCellEditTextFieldProps,
|
|
15
|
+
setCurrentEditingRow,
|
|
16
16
|
} = useMaterialReactTable();
|
|
17
17
|
|
|
18
18
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
19
19
|
if (currentEditingRow) {
|
|
20
|
+
cell.row.values[cell.column.id] = event.target.value;
|
|
20
21
|
setCurrentEditingRow({
|
|
21
22
|
...currentEditingRow,
|
|
22
|
-
values: { ...cell.row.values, [cell.column.id]: event.target.value },
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
cell.column.onCellEditChange?.(event, cell);
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
const mTableBodyCellEditTextFieldProps =
|
|
29
|
+
muiTableBodyCellEditTextFieldProps instanceof Function
|
|
30
|
+
? muiTableBodyCellEditTextFieldProps(cell)
|
|
31
|
+
: muiTableBodyCellEditTextFieldProps;
|
|
32
|
+
|
|
33
|
+
const mcTableBodyCellEditTextFieldProps =
|
|
34
|
+
cell.column.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
35
|
+
? cell.column.muiTableBodyCellEditTextFieldProps(cell)
|
|
36
|
+
: cell.column.muiTableBodyCellEditTextFieldProps;
|
|
37
|
+
|
|
27
38
|
const textFieldProps = {
|
|
28
|
-
...
|
|
29
|
-
...
|
|
39
|
+
...mTableBodyCellEditTextFieldProps,
|
|
40
|
+
...mcTableBodyCellEditTextFieldProps,
|
|
30
41
|
style: {
|
|
31
42
|
//@ts-ignore
|
|
32
43
|
...muiTableBodyCellEditTextFieldProps?.style,
|
|
@@ -36,20 +47,16 @@ export const MRT_EditCellTextfield: FC<Props> = ({ cell }) => {
|
|
|
36
47
|
};
|
|
37
48
|
|
|
38
49
|
if (cell.column.editable && cell.column.Edit) {
|
|
39
|
-
return (
|
|
40
|
-
<>
|
|
41
|
-
{cell.column.Edit({ ...textFieldProps, cell, onChange: handleChange })}
|
|
42
|
-
</>
|
|
43
|
-
);
|
|
50
|
+
return <>{cell.column.Edit({ ...textFieldProps, cell })}</>;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
return (
|
|
47
54
|
<TextField
|
|
48
55
|
margin="dense"
|
|
49
|
-
placeholder={localization?.filterTextFieldPlaceholder}
|
|
50
56
|
onChange={handleChange}
|
|
51
57
|
onClick={(e) => e.stopPropagation()}
|
|
52
|
-
|
|
58
|
+
placeholder={localization?.filterTextFieldPlaceholder}
|
|
59
|
+
value={cell.value}
|
|
53
60
|
variant="standard"
|
|
54
61
|
{...textFieldProps}
|
|
55
62
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
|
-
import { IconButton, InputAdornment, TextField } from '@mui/material';
|
|
2
|
+
import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
|
|
3
3
|
import CloseIcon from '@mui/icons-material/Close';
|
|
4
4
|
import FilterIcon from '@mui/icons-material/FilterList';
|
|
5
5
|
import { HeaderGroup, useAsyncDebounce } from 'react-table';
|
|
@@ -9,7 +9,7 @@ interface Props {
|
|
|
9
9
|
column: HeaderGroup;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
13
13
|
const { localization } = useMaterialReactTable();
|
|
14
14
|
|
|
15
15
|
const [filterValue, setFilterValue] = useState('');
|
|
@@ -24,13 +24,23 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
if (column.Filter) {
|
|
27
|
-
return <>{column.Filter({ column })}</>;
|
|
27
|
+
return <>{column.Filter?.({ column })}</>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return (
|
|
31
31
|
<TextField
|
|
32
|
+
fullWidth
|
|
33
|
+
id={`filter-${column.id}-column`}
|
|
34
|
+
inputProps={{
|
|
35
|
+
style: {
|
|
36
|
+
textOverflow: 'ellipsis',
|
|
37
|
+
},
|
|
38
|
+
}}
|
|
32
39
|
margin="dense"
|
|
33
|
-
placeholder={localization?.filterTextFieldPlaceholder
|
|
40
|
+
placeholder={localization?.filterTextFieldPlaceholder?.replace(
|
|
41
|
+
'{column}',
|
|
42
|
+
String(column.Header),
|
|
43
|
+
)}
|
|
34
44
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
35
45
|
setFilterValue(e.target.value);
|
|
36
46
|
handleChange(e.target.value);
|
|
@@ -40,21 +50,34 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
|
|
|
40
50
|
variant="standard"
|
|
41
51
|
InputProps={{
|
|
42
52
|
startAdornment: (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
<Tooltip
|
|
54
|
+
arrow
|
|
55
|
+
title={
|
|
56
|
+
localization?.filterTextFieldPlaceholder?.replace(
|
|
57
|
+
'{column}',
|
|
58
|
+
String(column.Header),
|
|
59
|
+
) ?? ''
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
<InputAdornment position="start">
|
|
63
|
+
<FilterIcon />
|
|
64
|
+
</InputAdornment>
|
|
65
|
+
</Tooltip>
|
|
46
66
|
),
|
|
47
67
|
endAdornment: (
|
|
48
68
|
<InputAdornment position="end">
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
<Tooltip arrow title={localization?.filterTextFieldClearButtonTitle ?? ''}>
|
|
70
|
+
<span>
|
|
71
|
+
<IconButton
|
|
72
|
+
aria-label={localization?.filterTextFieldClearButtonTitle}
|
|
73
|
+
disabled={filterValue?.length === 0}
|
|
74
|
+
onClick={handleClear}
|
|
75
|
+
size="small"
|
|
76
|
+
>
|
|
77
|
+
<CloseIcon fontSize="small" />
|
|
78
|
+
</IconButton>
|
|
79
|
+
</span>
|
|
80
|
+
</Tooltip>
|
|
58
81
|
</InputAdornment>
|
|
59
82
|
),
|
|
60
83
|
}}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Collapse,
|
|
3
4
|
IconButton,
|
|
4
5
|
InputAdornment,
|
|
5
6
|
styled,
|
|
@@ -17,22 +18,15 @@ const TextField = styled(MuiTextField)({
|
|
|
17
18
|
interface Props {}
|
|
18
19
|
|
|
19
20
|
export const MRT_SearchTextField: FC<Props> = () => {
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
muiSearchTextFieldProps,
|
|
23
|
-
localization,
|
|
24
|
-
onGlobalFilterChange,
|
|
25
|
-
} = useMaterialReactTable();
|
|
21
|
+
const { showSearch, localization, muiSearchTextFieldProps, onGlobalFilterChange, tableInstance } =
|
|
22
|
+
useMaterialReactTable();
|
|
26
23
|
|
|
27
24
|
const [searchValue, setSearchValue] = useState('');
|
|
28
25
|
|
|
29
|
-
const handleChange = useAsyncDebounce(
|
|
30
|
-
(event
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
200,
|
|
35
|
-
);
|
|
26
|
+
const handleChange = useAsyncDebounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
27
|
+
tableInstance.setGlobalFilter(event.target.value ?? undefined);
|
|
28
|
+
onGlobalFilterChange?.(event);
|
|
29
|
+
}, 200);
|
|
36
30
|
|
|
37
31
|
const handleClear = () => {
|
|
38
32
|
setSearchValue('');
|
|
@@ -40,35 +34,38 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
40
34
|
};
|
|
41
35
|
|
|
42
36
|
return (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
37
|
+
<Collapse in={showSearch} orientation="horizontal">
|
|
38
|
+
<TextField
|
|
39
|
+
id="global-search-text-field"
|
|
40
|
+
placeholder={localization?.searchTextFieldPlaceholder}
|
|
41
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
42
|
+
setSearchValue(event.target.value);
|
|
43
|
+
handleChange(event);
|
|
44
|
+
}}
|
|
45
|
+
value={searchValue ?? ''}
|
|
46
|
+
variant="standard"
|
|
47
|
+
InputProps={{
|
|
48
|
+
startAdornment: (
|
|
49
|
+
<InputAdornment position="start">
|
|
50
|
+
<SearchIcon fontSize="small" />
|
|
51
|
+
</InputAdornment>
|
|
52
|
+
),
|
|
53
|
+
endAdornment: (
|
|
54
|
+
<InputAdornment position="end">
|
|
55
|
+
<IconButton
|
|
56
|
+
aria-label={localization?.searchTextFieldClearButtonTitle}
|
|
57
|
+
disabled={searchValue?.length === 0}
|
|
58
|
+
onClick={handleClear}
|
|
59
|
+
size="small"
|
|
60
|
+
title={localization?.searchTextFieldClearButtonTitle}
|
|
61
|
+
>
|
|
62
|
+
<CloseIcon fontSize="small" />
|
|
63
|
+
</IconButton>
|
|
64
|
+
</InputAdornment>
|
|
65
|
+
),
|
|
66
|
+
}}
|
|
67
|
+
{...muiSearchTextFieldProps}
|
|
68
|
+
/>
|
|
69
|
+
</Collapse>
|
|
73
70
|
);
|
|
74
71
|
};
|