material-react-table 0.6.5 → 0.6.6
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 +2 -0
- package/dist/buttons/MRT_CopyButton.d.ts +7 -0
- package/dist/icons.d.ts +2 -0
- package/dist/localization.d.ts +2 -0
- package/dist/material-react-table.cjs.development.js +63 -2
- 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 +63 -2
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/MaterialReactTable.tsx +2 -0
- package/src/body/MRT_TableBodyCell.tsx +8 -1
- package/src/buttons/MRT_CopyButton.tsx +50 -0
- package/src/icons.ts +6 -0
- package/src/localization.ts +4 -0
- package/src/menus/MRT_FilterTypeMenu.tsx +66 -62
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.6.
|
|
2
|
+
"version": "0.6.6",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material-UI implementation of react-table, inspired by material-table and the mui DataGrid, written from the ground up in TypeScript.",
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@babel/core": "^7.17.
|
|
58
|
+
"@babel/core": "^7.17.7",
|
|
59
59
|
"@emotion/react": "^11.8.2",
|
|
60
60
|
"@emotion/styled": "^11.8.1",
|
|
61
61
|
"@etchteam/storybook-addon-status": "^4.2.0",
|
|
62
62
|
"@faker-js/faker": "^6.0.0-beta.0",
|
|
63
|
-
"@mui/icons-material": "^5.5.
|
|
64
|
-
"@mui/material": "^5.5.
|
|
63
|
+
"@mui/icons-material": "^5.5.1",
|
|
64
|
+
"@mui/material": "^5.5.1",
|
|
65
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
66
66
|
"@storybook/addon-a11y": "^6.4.19",
|
|
67
67
|
"@storybook/addon-actions": "^6.4.19",
|
|
@@ -136,6 +136,7 @@ export type MRT_ColumnInterface<D extends {} = {}> = ColumnInterface<D> &
|
|
|
136
136
|
columns?: MRT_ColumnInterface<D>[];
|
|
137
137
|
disableEditing?: boolean;
|
|
138
138
|
disableFilters?: boolean;
|
|
139
|
+
disableCellCopyButton?: boolean;
|
|
139
140
|
filter?: MRT_FilterType | string | FilterType<D>;
|
|
140
141
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
141
142
|
filterTypes?: (MRT_FILTER_TYPE | string)[];
|
|
@@ -232,6 +233,7 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
232
233
|
disableFullScreenToggle?: boolean;
|
|
233
234
|
disableSelectAll?: boolean;
|
|
234
235
|
disableSubRowTree?: boolean;
|
|
236
|
+
enableCellCopyButtons?: boolean;
|
|
235
237
|
enableColumnGrouping?: boolean;
|
|
236
238
|
enableColumnResizing?: boolean;
|
|
237
239
|
enableRowActions?: boolean;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { FC, MouseEvent } from 'react';
|
|
2
|
-
import { Skeleton, TableCell, TableCellProps } from '@mui/material';
|
|
2
|
+
import { Box, Skeleton, TableCell, TableCellProps } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
4
|
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
5
5
|
import type { MRT_Cell } from '..';
|
|
6
|
+
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
|
6
7
|
|
|
7
8
|
export const commonTableBodyCellStyles = (densePadding: boolean) => ({
|
|
8
9
|
p: densePadding ? '0.5rem' : '1rem',
|
|
@@ -22,6 +23,7 @@ interface Props {
|
|
|
22
23
|
|
|
23
24
|
export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
|
|
24
25
|
const {
|
|
26
|
+
enableCellCopyButtons,
|
|
25
27
|
isLoading,
|
|
26
28
|
muiTableBodyCellProps,
|
|
27
29
|
muiTableBodyCellSkeletonProps,
|
|
@@ -81,6 +83,11 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
|
|
|
81
83
|
<span>
|
|
82
84
|
{cell.render('Cell')} ({cell.row.subRows.length})
|
|
83
85
|
</span>
|
|
86
|
+
) : enableCellCopyButtons && !cell.column.disableCellCopyButton ? (
|
|
87
|
+
<Box sx={{ whiteSpace: 'nowrap' }}>
|
|
88
|
+
{cell.render('Cell')}
|
|
89
|
+
{<MRT_CopyButton cell={cell} />}
|
|
90
|
+
</Box>
|
|
84
91
|
) : (
|
|
85
92
|
cell.render('Cell')
|
|
86
93
|
)}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { FC, useState } from 'react';
|
|
2
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import { useMRT } from '../useMRT';
|
|
4
|
+
import { MRT_Cell } from '..';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
cell: MRT_Cell;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MRT_CopyButton: FC<Props> = ({ cell }) => {
|
|
11
|
+
const {
|
|
12
|
+
icons: { CheckBoxIcon, ContentCopyIcon },
|
|
13
|
+
localization,
|
|
14
|
+
} = useMRT();
|
|
15
|
+
|
|
16
|
+
const [copied, setCopied] = useState(false);
|
|
17
|
+
|
|
18
|
+
const handleCopy = (text: string) => {
|
|
19
|
+
navigator.clipboard.writeText(text);
|
|
20
|
+
setCopied(true);
|
|
21
|
+
setTimeout(() => setCopied(false), 2000);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Tooltip
|
|
26
|
+
arrow
|
|
27
|
+
title={copied ? localization.copiedToClipboard : localization.clickToCopy}
|
|
28
|
+
>
|
|
29
|
+
<IconButton
|
|
30
|
+
aria-label={localization.clickToCopy}
|
|
31
|
+
onClick={() => handleCopy(cell.value)}
|
|
32
|
+
size="small"
|
|
33
|
+
sx={{
|
|
34
|
+
opacity: 0.05,
|
|
35
|
+
m: '0 0.5rem',
|
|
36
|
+
transition: 'all 0.2s ease-in-out',
|
|
37
|
+
'&:hover': {
|
|
38
|
+
opacity: 1,
|
|
39
|
+
},
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
{copied ? (
|
|
43
|
+
<CheckBoxIcon color="success" fontSize="small" />
|
|
44
|
+
) : (
|
|
45
|
+
<ContentCopyIcon fontSize="small" />
|
|
46
|
+
)}
|
|
47
|
+
</IconButton>
|
|
48
|
+
</Tooltip>
|
|
49
|
+
);
|
|
50
|
+
};
|
package/src/icons.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
|
|
2
2
|
import CancelIcon from '@mui/icons-material/Cancel';
|
|
3
|
+
import CheckBoxIcon from '@mui/icons-material/CheckBox';
|
|
3
4
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
4
5
|
import CloseIcon from '@mui/icons-material/Close';
|
|
6
|
+
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
|
5
7
|
import DensityMediumIcon from '@mui/icons-material/DensityMedium';
|
|
6
8
|
import DensitySmallIcon from '@mui/icons-material/DensitySmall';
|
|
7
9
|
import DoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
|
@@ -27,8 +29,10 @@ import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
|
27
29
|
export interface MRT_Icons {
|
|
28
30
|
ArrowRightIcon: any;
|
|
29
31
|
CancelIcon: any;
|
|
32
|
+
CheckBoxIcon: any;
|
|
30
33
|
ClearAllIcon: any;
|
|
31
34
|
CloseIcon: any;
|
|
35
|
+
ContentCopyIcon: any;
|
|
32
36
|
DensityMediumIcon: any;
|
|
33
37
|
DensitySmallIcon: any;
|
|
34
38
|
DoubleArrowDownIcon: any;
|
|
@@ -55,8 +59,10 @@ export interface MRT_Icons {
|
|
|
55
59
|
export const MRT_Default_Icons: MRT_Icons = {
|
|
56
60
|
ArrowRightIcon,
|
|
57
61
|
CancelIcon,
|
|
62
|
+
CheckBoxIcon,
|
|
58
63
|
ClearAllIcon,
|
|
59
64
|
CloseIcon,
|
|
65
|
+
ContentCopyIcon,
|
|
60
66
|
DensityMediumIcon,
|
|
61
67
|
DensitySmallIcon,
|
|
62
68
|
DoubleArrowDownIcon,
|
package/src/localization.ts
CHANGED
|
@@ -5,7 +5,9 @@ export interface MRT_Localization {
|
|
|
5
5
|
clearFilter: string;
|
|
6
6
|
clearSearch: string;
|
|
7
7
|
clearSort: string;
|
|
8
|
+
clickToCopy: string;
|
|
8
9
|
columnActions: string;
|
|
10
|
+
copiedToClipboard: string;
|
|
9
11
|
edit: string;
|
|
10
12
|
expand: string;
|
|
11
13
|
expandAll: string;
|
|
@@ -52,7 +54,9 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
52
54
|
clearFilter: 'Clear filter',
|
|
53
55
|
clearSearch: 'Clear search',
|
|
54
56
|
clearSort: 'Clear sort',
|
|
57
|
+
clickToCopy: 'Click to copy',
|
|
55
58
|
columnActions: 'Column Actions',
|
|
59
|
+
copiedToClipboard: 'Copied to clipboard',
|
|
56
60
|
edit: 'Edit',
|
|
57
61
|
expand: 'Expand',
|
|
58
62
|
expandAll: 'Expand all',
|
|
@@ -43,68 +43,72 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
43
43
|
divider: boolean;
|
|
44
44
|
fn: Function;
|
|
45
45
|
}[] = useMemo(
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
46
|
+
() =>
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
type: MRT_FILTER_TYPE.FUZZY,
|
|
50
|
+
label: localization.filterFuzzy,
|
|
51
|
+
divider: false,
|
|
52
|
+
fn: fuzzy,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: MRT_FILTER_TYPE.CONTAINS,
|
|
56
|
+
label: localization.filterContains,
|
|
57
|
+
divider: true,
|
|
58
|
+
fn: contains,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: MRT_FILTER_TYPE.STARTS_WITH,
|
|
62
|
+
label: localization.filterStartsWith,
|
|
63
|
+
divider: false,
|
|
64
|
+
fn: startsWith,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: MRT_FILTER_TYPE.ENDS_WITH,
|
|
68
|
+
label: localization.filterEndsWith,
|
|
69
|
+
divider: true,
|
|
70
|
+
fn: endsWith,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: MRT_FILTER_TYPE.EQUALS,
|
|
74
|
+
label: localization.filterEquals,
|
|
75
|
+
divider: false,
|
|
76
|
+
fn: equals,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: MRT_FILTER_TYPE.NOT_EQUALS,
|
|
80
|
+
label: localization.filterNotEquals,
|
|
81
|
+
divider: true,
|
|
82
|
+
fn: notEquals,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: MRT_FILTER_TYPE.GREATER_THAN,
|
|
86
|
+
label: localization.filterGreaterThan,
|
|
87
|
+
divider: false,
|
|
88
|
+
fn: greaterThan,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: MRT_FILTER_TYPE.LESS_THAN,
|
|
92
|
+
label: localization.filterLessThan,
|
|
93
|
+
divider: true,
|
|
94
|
+
fn: lessThan,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: MRT_FILTER_TYPE.EMPTY,
|
|
98
|
+
label: localization.filterEmpty,
|
|
99
|
+
divider: false,
|
|
100
|
+
fn: empty,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: MRT_FILTER_TYPE.NOT_EMPTY,
|
|
104
|
+
label: localization.filterNotEmpty,
|
|
105
|
+
divider: false,
|
|
106
|
+
fn: notEmpty,
|
|
107
|
+
},
|
|
108
|
+
].filter(
|
|
109
|
+
(filterType) =>
|
|
110
|
+
!column.filterTypes || column.filterTypes.includes(filterType.type),
|
|
111
|
+
),
|
|
108
112
|
[],
|
|
109
113
|
);
|
|
110
114
|
|