material-react-table 0.8.0-alpha.1 → 0.8.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.
- package/README.md +1 -1
- package/dist/MaterialReactTable.d.ts +8 -2
- package/dist/head/MRT_DraggableTableHeadCell.d.ts +8 -0
- package/dist/head/MRT_TableHeadCell.d.ts +5 -1
- package/dist/head/MRT_TableHeadCellFilterContainer.d.ts +8 -0
- package/dist/head/MRT_TableHeadCellFilterLabel.d.ts +8 -0
- package/dist/head/MRT_TableHeadCellGrabHandle.d.ts +9 -0
- package/dist/head/MRT_TableHeadCellResizeHandle.d.ts +8 -0
- package/dist/head/MRT_TableHeadCellSortLabel.d.ts +8 -0
- package/dist/icons.d.ts +1 -0
- package/dist/inputs/MRT_FilterRangeFields.d.ts +2 -2
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +514 -313
- 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 +516 -315
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -0
- package/dist/toolbar/MRT_ToolbarTop.d.ts +2 -0
- package/dist/utils.d.ts +1 -1
- package/package.json +13 -13
- package/src/MaterialReactTable.tsx +13 -0
- package/src/body/MRT_TableBodyCell.tsx +10 -7
- package/src/buttons/MRT_CopyButton.tsx +3 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +26 -18
- package/src/buttons/MRT_ExpandButton.tsx +27 -21
- package/src/footer/MRT_TableFooterCell.tsx +11 -8
- package/src/footer/MRT_TableFooterRow.tsx +3 -2
- package/src/head/MRT_DraggableTableHeadCell.tsx +52 -0
- package/src/head/MRT_TableHeadCell.tsx +75 -156
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +32 -0
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +82 -0
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +52 -0
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +52 -0
- package/src/head/MRT_TableHeadCellSortLabel.tsx +45 -0
- package/src/head/MRT_TableHeadRow.tsx +17 -8
- package/src/icons.ts +3 -0
- package/src/inputs/MRT_EditCellTextField.tsx +1 -1
- package/src/inputs/MRT_FilterRangeFields.tsx +1 -3
- package/src/inputs/MRT_FilterTextField.tsx +4 -1
- package/src/inputs/MRT_SelectCheckbox.tsx +1 -2
- package/src/localization.ts +2 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +6 -6
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +1 -1
- package/src/table/MRT_TablePaper.tsx +26 -22
- package/src/table/MRT_TableRoot.tsx +9 -9
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +11 -27
- package/src/toolbar/MRT_ToolbarBottom.tsx +23 -5
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +30 -29
- package/src/toolbar/MRT_ToolbarTop.tsx +21 -20
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
import React, { FC,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
TableSortLabel,
|
|
9
|
-
Theme,
|
|
10
|
-
Tooltip,
|
|
11
|
-
alpha,
|
|
12
|
-
lighten,
|
|
13
|
-
} from '@mui/material';
|
|
14
|
-
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
1
|
+
import React, { FC, ReactNode, Ref } from 'react';
|
|
2
|
+
import { Box, TableCell, Theme, alpha, lighten } from '@mui/material';
|
|
3
|
+
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
|
|
4
|
+
import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
|
|
5
|
+
import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
|
|
6
|
+
import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
|
|
7
|
+
import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
|
|
15
8
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
16
9
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
17
|
-
import MRT_FilterRangeFields from '../inputs/MRT_FilterRangeFields';
|
|
18
|
-
import { MRT_FILTER_OPTION } from '../enums';
|
|
19
10
|
|
|
20
11
|
interface Props {
|
|
12
|
+
dragRef?: Ref<HTMLButtonElement>;
|
|
13
|
+
dropRef?: Ref<HTMLDivElement>;
|
|
21
14
|
header: MRT_Header;
|
|
15
|
+
isDragging?: boolean;
|
|
16
|
+
previewRef?: Ref<HTMLTableCellElement>;
|
|
22
17
|
tableInstance: MRT_TableInstance;
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
export const MRT_TableHeadCell: FC<Props> = ({
|
|
20
|
+
export const MRT_TableHeadCell: FC<Props> = ({
|
|
21
|
+
dragRef,
|
|
22
|
+
dropRef,
|
|
23
|
+
header,
|
|
24
|
+
isDragging,
|
|
25
|
+
previewRef,
|
|
26
|
+
tableInstance,
|
|
27
|
+
}) => {
|
|
26
28
|
const {
|
|
27
29
|
getState,
|
|
28
30
|
options: {
|
|
29
31
|
enableColumnActions,
|
|
30
32
|
enableColumnFilters,
|
|
33
|
+
enableColumnOrdering,
|
|
31
34
|
enableColumnResizing,
|
|
32
|
-
|
|
33
|
-
localization,
|
|
35
|
+
enableGrouping,
|
|
34
36
|
muiTableHeadCellProps,
|
|
35
37
|
},
|
|
36
|
-
setShowFilters,
|
|
37
38
|
} = tableInstance;
|
|
38
39
|
|
|
39
|
-
const {
|
|
40
|
+
const { isDensePadding } = getState();
|
|
40
41
|
|
|
41
42
|
const { column } = header;
|
|
42
43
|
|
|
@@ -55,44 +56,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
55
56
|
...mcTableHeadCellProps,
|
|
56
57
|
};
|
|
57
58
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
: localization.unsorted;
|
|
63
|
-
|
|
64
|
-
const filterFn = getState()?.currentFilterFns?.[header.id];
|
|
65
|
-
|
|
66
|
-
const filterTooltip = !!column.getFilterValue()
|
|
67
|
-
? localization.filteringByColumn
|
|
68
|
-
.replace('{column}', String(column.header))
|
|
69
|
-
.replace(
|
|
70
|
-
'{filterType}',
|
|
71
|
-
filterFn instanceof Function
|
|
72
|
-
? ''
|
|
73
|
-
: // @ts-ignore
|
|
74
|
-
localization[
|
|
75
|
-
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
76
|
-
],
|
|
77
|
-
)
|
|
78
|
-
.replace(
|
|
79
|
-
'{filterValue}',
|
|
80
|
-
`"${
|
|
81
|
-
Array.isArray(column.getFilterValue())
|
|
82
|
-
? (column.getFilterValue() as [string, string]).join(
|
|
83
|
-
`" ${localization.and} "`,
|
|
84
|
-
)
|
|
85
|
-
: (column.getFilterValue() as string)
|
|
86
|
-
}"`,
|
|
87
|
-
)
|
|
88
|
-
.replace('" "', '')
|
|
89
|
-
: localization.showHideFilters;
|
|
90
|
-
|
|
91
|
-
const headerElement =
|
|
92
|
-
column?.Header?.({
|
|
93
|
-
header,
|
|
94
|
-
tableInstance,
|
|
95
|
-
}) ?? column.header;
|
|
59
|
+
const headerElement = (column.columnDef?.Header?.({
|
|
60
|
+
header,
|
|
61
|
+
tableInstance,
|
|
62
|
+
}) ?? header.renderHeader()) as ReactNode;
|
|
96
63
|
|
|
97
64
|
const getIsLastLeftPinnedColumn = () => {
|
|
98
65
|
return (
|
|
@@ -113,12 +80,13 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
113
80
|
150
|
|
114
81
|
);
|
|
115
82
|
};
|
|
116
|
-
|
|
83
|
+
console.log(column.getCanGroup());
|
|
117
84
|
return (
|
|
118
85
|
<TableCell
|
|
119
86
|
align={column.columnDefType === 'group' ? 'center' : 'left'}
|
|
120
87
|
colSpan={header.colSpan}
|
|
121
88
|
{...tableCellProps}
|
|
89
|
+
ref={column.columnDefType === 'data' ? dropRef : undefined}
|
|
122
90
|
sx={(theme: Theme) => ({
|
|
123
91
|
backgroundColor:
|
|
124
92
|
column.getIsPinned() && column.columnDefType !== 'group'
|
|
@@ -136,8 +104,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
136
104
|
column.getIsPinned() === 'left'
|
|
137
105
|
? `${column.getStart('left')}px`
|
|
138
106
|
: undefined,
|
|
139
|
-
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
140
|
-
minWidth: `max(${column.getSize()}px, ${column.minSize}px)`,
|
|
141
107
|
overflow: 'visible',
|
|
142
108
|
p: isDensePadding
|
|
143
109
|
? column.columnDefType === 'display'
|
|
@@ -161,7 +127,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
161
127
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
162
128
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
163
129
|
verticalAlign: 'text-top',
|
|
164
|
-
width: header.getSize(),
|
|
165
130
|
zIndex: column.getIsResizing()
|
|
166
131
|
? 3
|
|
167
132
|
: column.getIsPinned() && column.columnDefType !== 'group'
|
|
@@ -169,16 +134,23 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
169
134
|
: 1,
|
|
170
135
|
...(tableCellProps?.sx as any),
|
|
171
136
|
})}
|
|
137
|
+
style={{
|
|
138
|
+
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
139
|
+
minWidth: `max(${column.getSize()}px, ${column.minSize ?? 30}px)`,
|
|
140
|
+
width: header.getSize(),
|
|
141
|
+
}}
|
|
172
142
|
>
|
|
173
143
|
{header.isPlaceholder ? null : column.columnDefType === 'display' ? (
|
|
174
144
|
headerElement
|
|
175
145
|
) : (
|
|
176
146
|
<Box
|
|
147
|
+
ref={previewRef}
|
|
177
148
|
sx={{
|
|
178
149
|
alignItems: 'flex-start',
|
|
179
150
|
display: 'flex',
|
|
180
151
|
justifyContent:
|
|
181
152
|
column.columnDefType === 'group' ? 'center' : 'space-between',
|
|
153
|
+
opacity: isDragging ? 0.5 : 1,
|
|
182
154
|
width: '100%',
|
|
183
155
|
}}
|
|
184
156
|
>
|
|
@@ -192,114 +164,61 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
192
164
|
: undefined,
|
|
193
165
|
display: 'flex',
|
|
194
166
|
flexWrap: 'nowrap',
|
|
195
|
-
whiteSpace:
|
|
167
|
+
whiteSpace:
|
|
168
|
+
(column.columnDef.header?.length ?? 0) < 24
|
|
169
|
+
? 'nowrap'
|
|
170
|
+
: 'normal',
|
|
196
171
|
}}
|
|
197
172
|
>
|
|
198
173
|
{headerElement}
|
|
199
174
|
{column.columnDefType === 'data' && column.getCanSort() && (
|
|
200
|
-
<
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
direction={
|
|
205
|
-
column.getIsSorted()
|
|
206
|
-
? (column.getIsSorted() as 'asc' | 'desc')
|
|
207
|
-
: undefined
|
|
208
|
-
}
|
|
209
|
-
/>
|
|
210
|
-
</Tooltip>
|
|
175
|
+
<MRT_TableHeadCellSortLabel
|
|
176
|
+
header={header}
|
|
177
|
+
tableInstance={tableInstance}
|
|
178
|
+
/>
|
|
211
179
|
)}
|
|
212
180
|
{column.columnDefType === 'data' &&
|
|
213
181
|
enableColumnFilters &&
|
|
214
|
-
|
|
215
|
-
<
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
</IconButton>
|
|
240
|
-
</Tooltip>
|
|
182
|
+
column.getCanFilter() && (
|
|
183
|
+
<MRT_TableHeadCellFilterLabel
|
|
184
|
+
header={header}
|
|
185
|
+
tableInstance={tableInstance}
|
|
186
|
+
/>
|
|
187
|
+
)}
|
|
188
|
+
</Box>
|
|
189
|
+
<Box sx={{ whiteSpace: 'nowrap' }}>
|
|
190
|
+
{column.columnDefType === 'data' &&
|
|
191
|
+
((enableColumnOrdering &&
|
|
192
|
+
column.enableColumnOrdering !== false) ||
|
|
193
|
+
(enableGrouping && column.enableGrouping !== false)) && (
|
|
194
|
+
<MRT_TableHeadCellGrabHandle
|
|
195
|
+
header={header}
|
|
196
|
+
ref={dragRef as Ref<HTMLButtonElement>}
|
|
197
|
+
tableInstance={tableInstance}
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
{(enableColumnActions || column.enableColumnActions) &&
|
|
201
|
+
column.enableColumnActions !== false &&
|
|
202
|
+
column.columnDefType !== 'group' && (
|
|
203
|
+
<MRT_ToggleColumnActionMenuButton
|
|
204
|
+
header={header}
|
|
205
|
+
tableInstance={tableInstance}
|
|
206
|
+
/>
|
|
241
207
|
)}
|
|
242
208
|
</Box>
|
|
243
|
-
{(enableColumnActions || column.enableColumnActions) &&
|
|
244
|
-
column.enableColumnActions !== false &&
|
|
245
|
-
column.columnDefType !== 'group' && (
|
|
246
|
-
<MRT_ToggleColumnActionMenuButton
|
|
247
|
-
header={header}
|
|
248
|
-
tableInstance={tableInstance}
|
|
249
|
-
/>
|
|
250
|
-
)}
|
|
251
209
|
{column.getCanResize() && (
|
|
252
|
-
<
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
onDoubleClick={() => column.resetSize()}
|
|
256
|
-
sx={(theme: Theme) => ({
|
|
257
|
-
borderRadius: '2px',
|
|
258
|
-
borderRightWidth: '2px',
|
|
259
|
-
cursor: 'col-resize',
|
|
260
|
-
height:
|
|
261
|
-
showFilters && column.columnDefType === 'data'
|
|
262
|
-
? '4rem'
|
|
263
|
-
: '2rem',
|
|
264
|
-
opacity: 0.8,
|
|
265
|
-
position: 'absolute',
|
|
266
|
-
right: '1px',
|
|
267
|
-
touchAction: 'none',
|
|
268
|
-
transition: 'all 0.2s ease-in-out',
|
|
269
|
-
userSelect: 'none',
|
|
270
|
-
zIndex: 2000,
|
|
271
|
-
'&:active': {
|
|
272
|
-
backgroundColor: theme.palette.info.main,
|
|
273
|
-
opacity: 1,
|
|
274
|
-
},
|
|
275
|
-
})}
|
|
276
|
-
{...{
|
|
277
|
-
onMouseDown: header.getResizeHandler,
|
|
278
|
-
onTouchStart: header.getResizeHandler,
|
|
279
|
-
}}
|
|
280
|
-
style={{
|
|
281
|
-
transform: column.getIsResizing()
|
|
282
|
-
? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
|
|
283
|
-
: 'none',
|
|
284
|
-
}}
|
|
210
|
+
<MRT_TableHeadCellResizeHandle
|
|
211
|
+
header={header}
|
|
212
|
+
tableInstance={tableInstance}
|
|
285
213
|
/>
|
|
286
214
|
)}
|
|
287
215
|
</Box>
|
|
288
216
|
)}
|
|
289
217
|
{column.columnDefType === 'data' && column.getCanFilter() && (
|
|
290
|
-
<
|
|
291
|
-
{
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
tableInstance={tableInstance}
|
|
295
|
-
/>
|
|
296
|
-
) : (
|
|
297
|
-
<MRT_FilterTextField
|
|
298
|
-
header={header}
|
|
299
|
-
tableInstance={tableInstance}
|
|
300
|
-
/>
|
|
301
|
-
)}
|
|
302
|
-
</Collapse>
|
|
218
|
+
<MRT_TableHeadCellFilterContainer
|
|
219
|
+
header={header}
|
|
220
|
+
tableInstance={tableInstance}
|
|
221
|
+
/>
|
|
303
222
|
)}
|
|
304
223
|
</TableCell>
|
|
305
224
|
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Collapse } from '@mui/material';
|
|
3
|
+
import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
|
|
4
|
+
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
5
|
+
import { MRT_FILTER_OPTION } from '../enums';
|
|
6
|
+
import { MRT_Header, MRT_TableInstance } from '..';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
header: MRT_Header;
|
|
10
|
+
tableInstance: MRT_TableInstance;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
14
|
+
header,
|
|
15
|
+
tableInstance,
|
|
16
|
+
}) => {
|
|
17
|
+
const { getState } = tableInstance;
|
|
18
|
+
|
|
19
|
+
const { currentFilterFns, showFilters } = getState();
|
|
20
|
+
|
|
21
|
+
const { column } = header;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Collapse in={showFilters} mountOnEnter unmountOnExit>
|
|
25
|
+
{currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
|
|
26
|
+
<MRT_FilterRangeFields header={header} tableInstance={tableInstance} />
|
|
27
|
+
) : (
|
|
28
|
+
<MRT_FilterTextField header={header} tableInstance={tableInstance} />
|
|
29
|
+
)}
|
|
30
|
+
</Collapse>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { FC, MouseEvent } from 'react';
|
|
2
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
header: MRT_Header;
|
|
7
|
+
tableInstance: MRT_TableInstance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MRT_TableHeadCellFilterLabel: FC<Props> = ({
|
|
11
|
+
header,
|
|
12
|
+
tableInstance,
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
getState,
|
|
16
|
+
options: {
|
|
17
|
+
icons: { FilterAltIcon, FilterAltOff },
|
|
18
|
+
localization,
|
|
19
|
+
},
|
|
20
|
+
setShowFilters,
|
|
21
|
+
} = tableInstance;
|
|
22
|
+
|
|
23
|
+
const { showFilters } = getState();
|
|
24
|
+
|
|
25
|
+
const { column } = header;
|
|
26
|
+
|
|
27
|
+
const filterFn = getState()?.currentFilterFns?.[header.id];
|
|
28
|
+
|
|
29
|
+
const filterTooltip = !!column.getFilterValue()
|
|
30
|
+
? localization.filteringByColumn
|
|
31
|
+
.replace('{column}', String(column.columnDef.header))
|
|
32
|
+
.replace(
|
|
33
|
+
'{filterType}',
|
|
34
|
+
filterFn instanceof Function
|
|
35
|
+
? ''
|
|
36
|
+
: // @ts-ignore
|
|
37
|
+
localization[
|
|
38
|
+
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
39
|
+
],
|
|
40
|
+
)
|
|
41
|
+
.replace(
|
|
42
|
+
'{filterValue}',
|
|
43
|
+
`"${
|
|
44
|
+
Array.isArray(column.getFilterValue())
|
|
45
|
+
? (column.getFilterValue() as [string, string]).join(
|
|
46
|
+
`" ${localization.and} "`,
|
|
47
|
+
)
|
|
48
|
+
: (column.getFilterValue() as string)
|
|
49
|
+
}"`,
|
|
50
|
+
)
|
|
51
|
+
.replace('" "', '')
|
|
52
|
+
: localization.showHideFilters;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Tooltip arrow placement="top" title={filterTooltip}>
|
|
56
|
+
<IconButton
|
|
57
|
+
disableRipple
|
|
58
|
+
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
|
59
|
+
event.stopPropagation();
|
|
60
|
+
setShowFilters(!showFilters);
|
|
61
|
+
}}
|
|
62
|
+
size="small"
|
|
63
|
+
sx={{
|
|
64
|
+
m: 0,
|
|
65
|
+
opacity: !!column.getFilterValue() || showFilters ? 0.8 : 0,
|
|
66
|
+
p: '2px',
|
|
67
|
+
transition: 'all 0.2s ease-in-out',
|
|
68
|
+
'&:hover': {
|
|
69
|
+
backgroundColor: 'transparent',
|
|
70
|
+
opacity: 0.8,
|
|
71
|
+
},
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{showFilters && !column.getFilterValue() ? (
|
|
75
|
+
<FilterAltOff />
|
|
76
|
+
) : (
|
|
77
|
+
<FilterAltIcon />
|
|
78
|
+
)}
|
|
79
|
+
</IconButton>
|
|
80
|
+
</Tooltip>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
2
|
+
import React, { FC, forwardRef, Ref } from 'react';
|
|
3
|
+
import { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
header: MRT_Header;
|
|
7
|
+
ref: Ref<HTMLButtonElement>;
|
|
8
|
+
tableInstance: MRT_TableInstance;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const MRT_TableHeadCellGrabHandle: FC<Props> = forwardRef(
|
|
12
|
+
({ tableInstance }, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
options: {
|
|
15
|
+
icons: { DragHandleIcon },
|
|
16
|
+
localization,
|
|
17
|
+
},
|
|
18
|
+
} = tableInstance;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Tooltip
|
|
22
|
+
arrow
|
|
23
|
+
enterDelay={1000}
|
|
24
|
+
enterNextDelay={1000}
|
|
25
|
+
placement="top"
|
|
26
|
+
title={localization.grab}
|
|
27
|
+
>
|
|
28
|
+
<IconButton
|
|
29
|
+
disableRipple
|
|
30
|
+
ref={ref}
|
|
31
|
+
size="small"
|
|
32
|
+
sx={{
|
|
33
|
+
cursor: 'grab',
|
|
34
|
+
m: 0,
|
|
35
|
+
opacity: 0.5,
|
|
36
|
+
p: '2px',
|
|
37
|
+
transition: 'all 0.2s ease-in-out',
|
|
38
|
+
'&:hover': {
|
|
39
|
+
backgroundColor: 'transparent',
|
|
40
|
+
opacity: 1,
|
|
41
|
+
},
|
|
42
|
+
'&:active': {
|
|
43
|
+
cursor: 'grabbing',
|
|
44
|
+
},
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<DragHandleIcon />
|
|
48
|
+
</IconButton>
|
|
49
|
+
</Tooltip>
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Divider, Theme } from '@mui/material';
|
|
3
|
+
import { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
header: MRT_Header;
|
|
7
|
+
tableInstance: MRT_TableInstance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
|
|
11
|
+
header,
|
|
12
|
+
tableInstance,
|
|
13
|
+
}) => {
|
|
14
|
+
const { getState } = tableInstance;
|
|
15
|
+
|
|
16
|
+
const { showFilters } = getState();
|
|
17
|
+
|
|
18
|
+
const { column } = header;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Divider
|
|
22
|
+
flexItem
|
|
23
|
+
orientation="vertical"
|
|
24
|
+
onDoubleClick={() => column.resetSize()}
|
|
25
|
+
sx={(theme: Theme) => ({
|
|
26
|
+
borderRadius: '2px',
|
|
27
|
+
borderRightWidth: '2px',
|
|
28
|
+
cursor: 'col-resize',
|
|
29
|
+
height:
|
|
30
|
+
showFilters && column.columnDefType === 'data' ? '4rem' : '2rem',
|
|
31
|
+
opacity: 0.8,
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
right: '1px',
|
|
34
|
+
touchAction: 'none',
|
|
35
|
+
transition: column.getIsResizing() ? undefined : 'all 0.2s ease-in-out',
|
|
36
|
+
userSelect: 'none',
|
|
37
|
+
zIndex: 2000,
|
|
38
|
+
'&:active': {
|
|
39
|
+
backgroundColor: theme.palette.info.main,
|
|
40
|
+
opacity: 1,
|
|
41
|
+
},
|
|
42
|
+
})}
|
|
43
|
+
onMouseDown={header.getResizeHandler()}
|
|
44
|
+
onTouchStart={header.getResizeHandler()}
|
|
45
|
+
style={{
|
|
46
|
+
transform: column.getIsResizing()
|
|
47
|
+
? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
|
|
48
|
+
: 'none',
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { TableSortLabel, Tooltip } from '@mui/material';
|
|
3
|
+
import { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
header: MRT_Header;
|
|
7
|
+
tableInstance: MRT_TableInstance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MRT_TableHeadCellSortLabel: FC<Props> = ({
|
|
11
|
+
header,
|
|
12
|
+
tableInstance,
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
options: { localization },
|
|
16
|
+
} = tableInstance;
|
|
17
|
+
|
|
18
|
+
const { column } = header;
|
|
19
|
+
|
|
20
|
+
const sortTooltip = !!column.getIsSorted()
|
|
21
|
+
? column.getIsSorted() === 'desc'
|
|
22
|
+
? localization.sortedByColumnDesc.replace(
|
|
23
|
+
'{column}',
|
|
24
|
+
column.columnDef.header,
|
|
25
|
+
)
|
|
26
|
+
: localization.sortedByColumnAsc.replace(
|
|
27
|
+
'{column}',
|
|
28
|
+
column.columnDef.header,
|
|
29
|
+
)
|
|
30
|
+
: localization.unsorted;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Tooltip arrow placement="top" title={sortTooltip}>
|
|
34
|
+
<TableSortLabel
|
|
35
|
+
aria-label={sortTooltip}
|
|
36
|
+
active={!!column.getIsSorted()}
|
|
37
|
+
direction={
|
|
38
|
+
column.getIsSorted()
|
|
39
|
+
? (column.getIsSorted() as 'asc' | 'desc')
|
|
40
|
+
: undefined
|
|
41
|
+
}
|
|
42
|
+
/>
|
|
43
|
+
</Tooltip>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { alpha, lighten, TableRow } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
|
+
import { MRT_DraggableTableHeadCell } from './MRT_DraggableTableHeadCell';
|
|
4
5
|
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
@@ -10,7 +11,7 @@ interface Props {
|
|
|
10
11
|
|
|
11
12
|
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
12
13
|
const {
|
|
13
|
-
options: { muiTableHeadRowProps },
|
|
14
|
+
options: { enableColumnOrdering, enableGrouping, muiTableHeadRowProps },
|
|
14
15
|
} = tableInstance;
|
|
15
16
|
|
|
16
17
|
const tableRowProps =
|
|
@@ -27,13 +28,21 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
|
27
28
|
...(tableRowProps?.sx as any),
|
|
28
29
|
})}
|
|
29
30
|
>
|
|
30
|
-
{headerGroup.headers.map((header: MRT_Header, index) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
{headerGroup.headers.map((header: MRT_Header, index) =>
|
|
32
|
+
enableColumnOrdering || enableGrouping ? (
|
|
33
|
+
<MRT_DraggableTableHeadCell
|
|
34
|
+
header={header}
|
|
35
|
+
key={header.id || index}
|
|
36
|
+
tableInstance={tableInstance}
|
|
37
|
+
/>
|
|
38
|
+
) : (
|
|
39
|
+
<MRT_TableHeadCell
|
|
40
|
+
header={header}
|
|
41
|
+
key={header.id || index}
|
|
42
|
+
tableInstance={tableInstance}
|
|
43
|
+
/>
|
|
44
|
+
),
|
|
45
|
+
)}
|
|
37
46
|
</TableRow>
|
|
38
47
|
);
|
|
39
48
|
};
|
package/src/icons.ts
CHANGED
|
@@ -6,6 +6,7 @@ import CloseIcon from '@mui/icons-material/Close';
|
|
|
6
6
|
import DensityMediumIcon from '@mui/icons-material/DensityMedium';
|
|
7
7
|
import DensitySmallIcon from '@mui/icons-material/DensitySmall';
|
|
8
8
|
import DoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
|
9
|
+
import DragHandleIcon from '@mui/icons-material/DragHandle';
|
|
9
10
|
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
10
11
|
import EditIcon from '@mui/icons-material/Edit';
|
|
11
12
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
|
@@ -36,6 +37,7 @@ export interface MRT_Icons {
|
|
|
36
37
|
DensityMediumIcon: any;
|
|
37
38
|
DensitySmallIcon: any;
|
|
38
39
|
DoubleArrowDownIcon: any;
|
|
40
|
+
DragHandleIcon: any;
|
|
39
41
|
DynamicFeedIcon: any;
|
|
40
42
|
EditIcon: any;
|
|
41
43
|
ExpandLessIcon: any;
|
|
@@ -67,6 +69,7 @@ export const MRT_Default_Icons: MRT_Icons = {
|
|
|
67
69
|
DensityMediumIcon,
|
|
68
70
|
DensitySmallIcon,
|
|
69
71
|
DoubleArrowDownIcon,
|
|
72
|
+
DragHandleIcon,
|
|
70
73
|
DynamicFeedIcon,
|
|
71
74
|
EditIcon,
|
|
72
75
|
ExpandLessIcon,
|
|
@@ -73,7 +73,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
73
73
|
onBlur={handleBlur}
|
|
74
74
|
onChange={handleChange}
|
|
75
75
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
76
|
-
placeholder={column.header}
|
|
76
|
+
placeholder={column.columnDef.header}
|
|
77
77
|
value={value}
|
|
78
78
|
variant="standard"
|
|
79
79
|
{...textFieldProps}
|
|
@@ -8,7 +8,7 @@ interface Props {
|
|
|
8
8
|
tableInstance: MRT_TableInstance;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const MRT_FilterRangeFields: FC<Props> = ({ header, tableInstance }) => {
|
|
11
|
+
export const MRT_FilterRangeFields: FC<Props> = ({ header, tableInstance }) => {
|
|
12
12
|
const {
|
|
13
13
|
options: { localization },
|
|
14
14
|
} = tableInstance;
|
|
@@ -37,5 +37,3 @@ const MRT_FilterRangeFields: FC<Props> = ({ header, tableInstance }) => {
|
|
|
37
37
|
</Box>
|
|
38
38
|
);
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
export default MRT_FilterRangeFields;
|