material-react-table 2.0.0-alpha.0 → 2.0.0-alpha.2
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 +2 -2
- package/dist/cjs/index.js +2480 -2392
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +1 -1
- package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/cjs/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
- package/dist/cjs/types/body/index.d.ts +1 -0
- package/dist/cjs/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
- package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +9 -0
- package/dist/cjs/types/buttons/index.d.ts +2 -1
- package/dist/cjs/types/column.utils.d.ts +7 -6
- package/dist/cjs/types/filterFns.d.ts +14 -14
- package/dist/cjs/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/cjs/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/cjs/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
- package/dist/cjs/types/icons.d.ts +1 -1
- package/dist/cjs/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
- package/dist/cjs/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
- package/dist/cjs/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/cjs/types/toolbar/MRT_TopToolbar.d.ts +1 -1
- package/dist/cjs/types/types.d.ts +203 -197
- package/dist/esm/material-react-table.esm.js +2442 -2358
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +1 -1
- package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/esm/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
- package/dist/esm/types/body/index.d.ts +1 -0
- package/dist/esm/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
- package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +9 -0
- package/dist/esm/types/buttons/index.d.ts +2 -1
- package/dist/esm/types/column.utils.d.ts +7 -6
- package/dist/esm/types/filterFns.d.ts +14 -14
- package/dist/esm/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/esm/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/esm/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
- package/dist/esm/types/icons.d.ts +1 -1
- package/dist/esm/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
- package/dist/esm/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
- package/dist/esm/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/esm/types/toolbar/MRT_TopToolbar.d.ts +1 -1
- package/dist/esm/types/types.d.ts +203 -197
- package/dist/index.d.ts +293 -272
- package/locales/en.esm.js +1 -0
- package/locales/en.esm.js.map +1 -1
- package/locales/en.js +1 -0
- package/locales/en.js.map +1 -1
- package/locales/fr.esm.js +1 -1
- package/locales/fr.esm.js.map +1 -1
- package/locales/fr.js +1 -1
- package/locales/fr.js.map +1 -1
- package/package.json +10 -9
- package/src/MaterialReactTable.tsx +2 -2
- package/src/body/MRT_TableBody.tsx +180 -76
- package/src/body/MRT_TableBodyCell.tsx +45 -43
- package/src/body/MRT_TableBodyCellValue.tsx +5 -5
- package/src/body/MRT_TableBodyRow.tsx +117 -29
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +6 -5
- package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
- package/src/body/MRT_TableDetailPanel.tsx +16 -22
- package/src/body/index.ts +2 -1
- package/src/buttons/MRT_CopyButton.tsx +14 -20
- package/src/buttons/MRT_EditActionButtons.tsx +4 -4
- package/src/buttons/MRT_ExpandAllButton.tsx +7 -9
- package/src/buttons/MRT_ExpandButton.tsx +6 -7
- package/src/buttons/MRT_GrabHandleButton.tsx +12 -13
- package/src/buttons/MRT_RowPinButton.tsx +74 -0
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -1
- package/src/buttons/MRT_ToggleFullScreenButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +9 -10
- package/src/buttons/index.ts +2 -1
- package/src/column.utils.ts +33 -21
- package/src/filterFns.ts +29 -29
- package/src/footer/MRT_TableFooter.tsx +14 -8
- package/src/footer/MRT_TableFooterCell.tsx +8 -21
- package/src/footer/MRT_TableFooterRow.tsx +7 -8
- package/src/head/MRT_TableHead.tsx +12 -8
- package/src/head/MRT_TableHeadCell.tsx +18 -25
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +18 -23
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +11 -4
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +106 -61
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +8 -15
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +11 -11
- package/src/head/MRT_TableHeadCellSortLabel.tsx +8 -8
- package/src/head/MRT_TableHeadRow.tsx +7 -8
- package/src/hooks/useMRT_DisplayColumns.tsx +17 -4
- package/src/hooks/useMRT_Effects.ts +3 -3
- package/src/hooks/useMRT_TableInstance.ts +17 -10
- package/src/hooks/useMRT_TableOptions.ts +9 -5
- package/src/icons.ts +2 -2
- package/src/inputs/MRT_EditCellTextField.tsx +23 -31
- package/src/inputs/MRT_FilterCheckbox.tsx +17 -29
- package/src/inputs/MRT_FilterRangeFields.tsx +1 -1
- package/src/inputs/MRT_FilterRangeSlider.tsx +12 -29
- package/src/inputs/MRT_FilterTextField.tsx +83 -99
- package/src/inputs/MRT_GlobalFilterTextField.tsx +29 -29
- package/src/inputs/MRT_SelectCheckbox.tsx +35 -21
- package/src/locales/en.ts +1 -1
- package/src/locales/fr.ts +1 -1
- package/src/menus/MRT_ColumnActionMenu.tsx +14 -14
- package/src/menus/MRT_FilterOptionMenu.tsx +35 -35
- package/src/menus/MRT_RowActionMenu.tsx +17 -18
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -6
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +5 -5
- package/src/modals/MRT_EditRowModal.tsx +12 -20
- package/src/sortingFns.ts +1 -1
- package/src/table/MRT_Table.tsx +14 -19
- package/src/table/MRT_TableContainer.tsx +14 -20
- package/src/table/MRT_TablePaper.tsx +16 -20
- package/src/toolbar/MRT_BottomToolbar.tsx +18 -24
- package/src/toolbar/MRT_LinearProgressBar.tsx +8 -7
- package/src/toolbar/MRT_TablePagination.tsx +23 -25
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +11 -14
- package/src/toolbar/MRT_ToolbarDropZone.tsx +6 -6
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -5
- package/src/toolbar/MRT_TopToolbar.tsx +14 -20
- package/src/types.ts +269 -252
- package/src/useMaterialReactTable.ts +1 -1
@@ -3,9 +3,9 @@ import {
|
|
3
3
|
type MouseEvent,
|
4
4
|
useCallback,
|
5
5
|
useEffect,
|
6
|
+
useMemo,
|
6
7
|
useRef,
|
7
8
|
useState,
|
8
|
-
useMemo,
|
9
9
|
} from 'react';
|
10
10
|
import Box from '@mui/material/Box';
|
11
11
|
import Checkbox from '@mui/material/Checkbox';
|
@@ -14,10 +14,11 @@ import IconButton from '@mui/material/IconButton';
|
|
14
14
|
import InputAdornment from '@mui/material/InputAdornment';
|
15
15
|
import MenuItem from '@mui/material/MenuItem';
|
16
16
|
import TextField from '@mui/material/TextField';
|
17
|
+
import { type TextFieldProps } from '@mui/material/TextField';
|
17
18
|
import Tooltip from '@mui/material/Tooltip';
|
18
19
|
import { debounce } from '@mui/material/utils';
|
20
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
19
21
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
20
|
-
import { type TextFieldProps } from '@mui/material/TextField';
|
21
22
|
import { type MRT_Header, type MRT_TableInstance } from '../types';
|
22
23
|
|
23
24
|
interface Props<TData extends Record<string, any>> {
|
@@ -33,9 +34,9 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
33
34
|
}: Props<TData>) => {
|
34
35
|
const {
|
35
36
|
options: {
|
36
|
-
enableColumnFilterModes,
|
37
37
|
columnFilterModeOptions,
|
38
|
-
|
38
|
+
enableColumnFilterModes,
|
39
|
+
icons: { CloseIcon, FilterListIcon },
|
39
40
|
localization,
|
40
41
|
manualFiltering,
|
41
42
|
muiFilterTextFieldProps,
|
@@ -46,28 +47,13 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
46
47
|
const { column } = header;
|
47
48
|
const { columnDef } = column;
|
48
49
|
|
49
|
-
const
|
50
|
-
muiFilterTextFieldProps
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
: muiFilterTextFieldProps;
|
57
|
-
|
58
|
-
const mcTableHeadCellFilterTextFieldProps =
|
59
|
-
columnDef.muiFilterTextFieldProps instanceof Function
|
60
|
-
? columnDef.muiFilterTextFieldProps({
|
61
|
-
column,
|
62
|
-
table,
|
63
|
-
rangeFilterIndex,
|
64
|
-
})
|
65
|
-
: columnDef.muiFilterTextFieldProps;
|
66
|
-
|
67
|
-
const textFieldProps = {
|
68
|
-
...mTableHeadCellFilterTextFieldProps,
|
69
|
-
...mcTableHeadCellFilterTextFieldProps,
|
70
|
-
} as TextFieldProps;
|
50
|
+
const textFieldProps: TextFieldProps = {
|
51
|
+
...parseFromValuesOrFunc(muiFilterTextFieldProps, { column, table }),
|
52
|
+
...parseFromValuesOrFunc(columnDef.muiFilterTextFieldProps, {
|
53
|
+
column,
|
54
|
+
table,
|
55
|
+
}),
|
56
|
+
};
|
71
57
|
|
72
58
|
const isRangeFilter =
|
73
59
|
columnDef.filterVariant === 'range' || rangeFilterIndex !== undefined;
|
@@ -121,7 +107,7 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
121
107
|
],
|
122
108
|
);
|
123
109
|
|
124
|
-
const [anchorEl, setAnchorEl] = useState<
|
110
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
125
111
|
const [filterValue, setFilterValue] = useState<string | string[]>(() =>
|
126
112
|
isMultiSelectFilter
|
127
113
|
? (column.getFilterValue() as string[]) || []
|
@@ -142,7 +128,7 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
142
128
|
? event.target.valueAsNumber
|
143
129
|
: event.target.value;
|
144
130
|
if (isRangeFilter) {
|
145
|
-
column.setFilterValue((old: Array<
|
131
|
+
column.setFilterValue((old: Array<Date | null | number | string>) => {
|
146
132
|
const newFilterValues = old ?? ['', ''];
|
147
133
|
newFilterValues[rangeFilterIndex as number] = value;
|
148
134
|
return newFilterValues;
|
@@ -216,31 +202,6 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
216
202
|
return (
|
217
203
|
<>
|
218
204
|
<TextField
|
219
|
-
fullWidth
|
220
|
-
inputProps={{
|
221
|
-
disabled: !!filterChipLabel,
|
222
|
-
sx: {
|
223
|
-
textOverflow: 'ellipsis',
|
224
|
-
width: filterChipLabel ? 0 : undefined,
|
225
|
-
},
|
226
|
-
title: filterPlaceholder,
|
227
|
-
}}
|
228
|
-
helperText={
|
229
|
-
showChangeModeButton ? (
|
230
|
-
<label>
|
231
|
-
{localization.filterMode.replace(
|
232
|
-
'{filterType}',
|
233
|
-
// @ts-ignore
|
234
|
-
localization[
|
235
|
-
`filter${
|
236
|
-
currentFilterOption?.charAt(0)?.toUpperCase() +
|
237
|
-
currentFilterOption?.slice(1)
|
238
|
-
}`
|
239
|
-
],
|
240
|
-
)}
|
241
|
-
</label>
|
242
|
-
) : null
|
243
|
-
}
|
244
205
|
FormHelperTextProps={{
|
245
206
|
sx: {
|
246
207
|
fontSize: '0.75rem',
|
@@ -248,40 +209,7 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
248
209
|
whiteSpace: 'nowrap',
|
249
210
|
},
|
250
211
|
}}
|
251
|
-
margin="none"
|
252
|
-
placeholder={
|
253
|
-
filterChipLabel || isSelectFilter || isMultiSelectFilter
|
254
|
-
? undefined
|
255
|
-
: filterPlaceholder
|
256
|
-
}
|
257
|
-
onChange={handleChange}
|
258
|
-
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
259
|
-
select={isSelectFilter || isMultiSelectFilter}
|
260
|
-
value={filterValue ?? ''}
|
261
|
-
variant="standard"
|
262
212
|
InputProps={{
|
263
|
-
startAdornment: showChangeModeButton ? (
|
264
|
-
<InputAdornment position="start">
|
265
|
-
<Tooltip arrow title={localization.changeFilterMode}>
|
266
|
-
<span>
|
267
|
-
<IconButton
|
268
|
-
aria-label={localization.changeFilterMode}
|
269
|
-
onClick={handleFilterMenuOpen}
|
270
|
-
size="small"
|
271
|
-
sx={{ height: '1.75rem', width: '1.75rem' }}
|
272
|
-
>
|
273
|
-
<FilterListIcon />
|
274
|
-
</IconButton>
|
275
|
-
</span>
|
276
|
-
</Tooltip>
|
277
|
-
{filterChipLabel && (
|
278
|
-
<Chip
|
279
|
-
onDelete={handleClearEmptyFilterChip}
|
280
|
-
label={filterChipLabel}
|
281
|
-
/>
|
282
|
-
)}
|
283
|
-
</InputAdornment>
|
284
|
-
) : null,
|
285
213
|
endAdornment: !filterChipLabel && (
|
286
214
|
<InputAdornment position="end">
|
287
215
|
<Tooltip
|
@@ -306,6 +234,28 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
306
234
|
</Tooltip>
|
307
235
|
</InputAdornment>
|
308
236
|
),
|
237
|
+
startAdornment: showChangeModeButton ? (
|
238
|
+
<InputAdornment position="start">
|
239
|
+
<Tooltip arrow title={localization.changeFilterMode}>
|
240
|
+
<span>
|
241
|
+
<IconButton
|
242
|
+
aria-label={localization.changeFilterMode}
|
243
|
+
onClick={handleFilterMenuOpen}
|
244
|
+
size="small"
|
245
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
246
|
+
>
|
247
|
+
<FilterListIcon />
|
248
|
+
</IconButton>
|
249
|
+
</span>
|
250
|
+
</Tooltip>
|
251
|
+
{filterChipLabel && (
|
252
|
+
<Chip
|
253
|
+
label={filterChipLabel}
|
254
|
+
onDelete={handleClearEmptyFilterChip}
|
255
|
+
/>
|
256
|
+
)}
|
257
|
+
</InputAdornment>
|
258
|
+
) : null,
|
309
259
|
}}
|
310
260
|
SelectProps={{
|
311
261
|
displayEmpty: true,
|
@@ -338,6 +288,42 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
338
288
|
)
|
339
289
|
: undefined,
|
340
290
|
}}
|
291
|
+
fullWidth
|
292
|
+
helperText={
|
293
|
+
showChangeModeButton ? (
|
294
|
+
<label>
|
295
|
+
{localization.filterMode.replace(
|
296
|
+
'{filterType}',
|
297
|
+
// @ts-ignore
|
298
|
+
localization[
|
299
|
+
`filter${
|
300
|
+
currentFilterOption?.charAt(0)?.toUpperCase() +
|
301
|
+
currentFilterOption?.slice(1)
|
302
|
+
}`
|
303
|
+
],
|
304
|
+
)}
|
305
|
+
</label>
|
306
|
+
) : null
|
307
|
+
}
|
308
|
+
inputProps={{
|
309
|
+
disabled: !!filterChipLabel,
|
310
|
+
sx: {
|
311
|
+
textOverflow: 'ellipsis',
|
312
|
+
width: filterChipLabel ? 0 : undefined,
|
313
|
+
},
|
314
|
+
title: filterPlaceholder,
|
315
|
+
}}
|
316
|
+
margin="none"
|
317
|
+
onChange={handleChange}
|
318
|
+
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
319
|
+
placeholder={
|
320
|
+
filterChipLabel || isSelectFilter || isMultiSelectFilter
|
321
|
+
? undefined
|
322
|
+
: filterPlaceholder
|
323
|
+
}
|
324
|
+
select={isSelectFilter || isMultiSelectFilter}
|
325
|
+
value={filterValue ?? ''}
|
326
|
+
variant="standard"
|
341
327
|
{...textFieldProps}
|
342
328
|
inputRef={(inputRef) => {
|
343
329
|
filterInputRefs.current[`${column.id}-${rangeFilterIndex ?? 0}`] =
|
@@ -347,30 +333,28 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
347
333
|
}
|
348
334
|
}}
|
349
335
|
sx={(theme) => ({
|
350
|
-
|
336
|
+
'& .MuiSelect-icon': {
|
337
|
+
mr: '1.5rem',
|
338
|
+
},
|
351
339
|
minWidth: isRangeFilter
|
352
340
|
? '100px'
|
353
341
|
: !filterChipLabel
|
354
342
|
? '120px'
|
355
343
|
: 'auto',
|
356
|
-
width: 'calc(100% + 4px)',
|
357
344
|
mx: '-2px',
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
...(textFieldProps?.sx instanceof Function
|
362
|
-
? textFieldProps.sx(theme)
|
363
|
-
: (textFieldProps?.sx as any)),
|
345
|
+
p: 0,
|
346
|
+
width: 'calc(100% + 4px)',
|
347
|
+
...(parseFromValuesOrFunc(textFieldProps?.sx, theme) as any),
|
364
348
|
})}
|
365
349
|
>
|
366
350
|
{(isSelectFilter || isMultiSelectFilter) && (
|
367
|
-
<MenuItem divider
|
351
|
+
<MenuItem disabled divider hidden value="">
|
368
352
|
<Box sx={{ opacity: 0.5 }}>{filterPlaceholder}</Box>
|
369
353
|
</MenuItem>
|
370
354
|
)}
|
371
355
|
{textFieldProps.children ??
|
372
356
|
filterSelectOptions?.map(
|
373
|
-
(option:
|
357
|
+
(option: { text: string; value: string } | string) => {
|
374
358
|
if (!option) return '';
|
375
359
|
let value: string;
|
376
360
|
let text: string;
|
@@ -385,10 +369,10 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
385
369
|
<MenuItem
|
386
370
|
key={value}
|
387
371
|
sx={{
|
388
|
-
display: 'flex',
|
389
|
-
m: 0,
|
390
372
|
alignItems: 'center',
|
373
|
+
display: 'flex',
|
391
374
|
gap: '0.5rem',
|
375
|
+
m: 0,
|
392
376
|
}}
|
393
377
|
value={value}
|
394
378
|
>
|
@@ -412,8 +396,8 @@ export const MRT_FilterTextField = <TData extends Record<string, any>>({
|
|
412
396
|
anchorEl={anchorEl}
|
413
397
|
header={header}
|
414
398
|
setAnchorEl={setAnchorEl}
|
415
|
-
table={table}
|
416
399
|
setFilterValue={setFilterValue}
|
400
|
+
table={table}
|
417
401
|
/>
|
418
402
|
</>
|
419
403
|
);
|
@@ -12,6 +12,7 @@ import InputAdornment from '@mui/material/InputAdornment';
|
|
12
12
|
import TextField from '@mui/material/TextField';
|
13
13
|
import Tooltip from '@mui/material/Tooltip';
|
14
14
|
import { debounce } from '@mui/material/utils';
|
15
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
15
16
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
16
17
|
import { type MRT_TableInstance } from '../types';
|
17
18
|
|
@@ -24,25 +25,24 @@ export const MRT_GlobalFilterTextField = <TData extends Record<string, any>>({
|
|
24
25
|
}: Props<TData>) => {
|
25
26
|
const {
|
26
27
|
getState,
|
27
|
-
setGlobalFilter,
|
28
28
|
options: {
|
29
29
|
enableGlobalFilterModes,
|
30
|
-
icons: {
|
30
|
+
icons: { CloseIcon, SearchIcon },
|
31
31
|
localization,
|
32
32
|
manualFiltering,
|
33
33
|
muiSearchTextFieldProps,
|
34
34
|
},
|
35
35
|
refs: { searchInputRef },
|
36
|
+
setGlobalFilter,
|
36
37
|
} = table;
|
37
38
|
const { globalFilter, showGlobalFilter } = getState();
|
38
39
|
|
39
|
-
const textFieldProps =
|
40
|
-
|
41
|
-
|
42
|
-
: muiSearchTextFieldProps;
|
40
|
+
const textFieldProps = parseFromValuesOrFunc(muiSearchTextFieldProps, {
|
41
|
+
table,
|
42
|
+
});
|
43
43
|
|
44
44
|
const isMounted = useRef(false);
|
45
|
-
const [anchorEl, setAnchorEl] = useState<
|
45
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
46
46
|
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
47
47
|
|
48
48
|
const handleChangeDebounced = useCallback(
|
@@ -83,32 +83,12 @@ export const MRT_GlobalFilterTextField = <TData extends Record<string, any>>({
|
|
83
83
|
return (
|
84
84
|
<Collapse
|
85
85
|
in={showGlobalFilter}
|
86
|
+
mountOnEnter
|
86
87
|
orientation="horizontal"
|
87
88
|
unmountOnExit
|
88
|
-
mountOnEnter
|
89
89
|
>
|
90
90
|
<TextField
|
91
|
-
placeholder={localization.search}
|
92
|
-
onChange={handleChange}
|
93
|
-
value={searchValue ?? ''}
|
94
|
-
variant="standard"
|
95
91
|
InputProps={{
|
96
|
-
startAdornment: enableGlobalFilterModes ? (
|
97
|
-
<InputAdornment position="start">
|
98
|
-
<Tooltip arrow title={localization.changeSearchMode}>
|
99
|
-
<IconButton
|
100
|
-
aria-label={localization.changeSearchMode}
|
101
|
-
onClick={handleGlobalFilterMenuOpen}
|
102
|
-
size="small"
|
103
|
-
sx={{ height: '1.75rem', width: '1.75rem' }}
|
104
|
-
>
|
105
|
-
<SearchIcon />
|
106
|
-
</IconButton>
|
107
|
-
</Tooltip>
|
108
|
-
</InputAdornment>
|
109
|
-
) : (
|
110
|
-
<SearchIcon style={{ marginRight: '4px' }} />
|
111
|
-
),
|
112
92
|
endAdornment: (
|
113
93
|
<InputAdornment position="end">
|
114
94
|
<Tooltip arrow title={localization.clearSearch ?? ''}>
|
@@ -125,7 +105,27 @@ export const MRT_GlobalFilterTextField = <TData extends Record<string, any>>({
|
|
125
105
|
</Tooltip>
|
126
106
|
</InputAdornment>
|
127
107
|
),
|
108
|
+
startAdornment: enableGlobalFilterModes ? (
|
109
|
+
<InputAdornment position="start">
|
110
|
+
<Tooltip arrow title={localization.changeSearchMode}>
|
111
|
+
<IconButton
|
112
|
+
aria-label={localization.changeSearchMode}
|
113
|
+
onClick={handleGlobalFilterMenuOpen}
|
114
|
+
size="small"
|
115
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
116
|
+
>
|
117
|
+
<SearchIcon />
|
118
|
+
</IconButton>
|
119
|
+
</Tooltip>
|
120
|
+
</InputAdornment>
|
121
|
+
) : (
|
122
|
+
<SearchIcon style={{ marginRight: '4px' }} />
|
123
|
+
),
|
128
124
|
}}
|
125
|
+
onChange={handleChange}
|
126
|
+
placeholder={localization.search}
|
127
|
+
value={searchValue ?? ''}
|
128
|
+
variant="standard"
|
129
129
|
{...textFieldProps}
|
130
130
|
inputRef={(inputRef) => {
|
131
131
|
searchInputRef.current = inputRef;
|
@@ -136,9 +136,9 @@ export const MRT_GlobalFilterTextField = <TData extends Record<string, any>>({
|
|
136
136
|
/>
|
137
137
|
<MRT_FilterOptionMenu
|
138
138
|
anchorEl={anchorEl}
|
139
|
+
onSelect={handleClear}
|
139
140
|
setAnchorEl={setAnchorEl}
|
140
141
|
table={table}
|
141
|
-
onSelect={handleClear}
|
142
142
|
/>
|
143
143
|
</Collapse>
|
144
144
|
);
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { type MouseEvent } from 'react';
|
2
|
-
import Checkbox from '@mui/material/Checkbox';
|
2
|
+
import Checkbox, { type CheckboxProps } from '@mui/material/Checkbox';
|
3
|
+
import Radio, { type RadioProps } from '@mui/material/Radio';
|
3
4
|
import Tooltip from '@mui/material/Tooltip';
|
4
|
-
import Radio from '@mui/material/Radio';
|
5
5
|
import { type Theme } from '@mui/material/styles';
|
6
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
6
7
|
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
7
8
|
|
8
9
|
interface Props<TData extends Record<string, any>> {
|
@@ -19,22 +20,20 @@ export const MRT_SelectCheckbox = <TData extends Record<string, any>>({
|
|
19
20
|
const {
|
20
21
|
getState,
|
21
22
|
options: {
|
22
|
-
localization,
|
23
23
|
enableMultiRowSelection,
|
24
|
-
|
24
|
+
enableRowPinning,
|
25
|
+
localization,
|
25
26
|
muiSelectAllCheckboxProps,
|
27
|
+
muiSelectCheckboxProps,
|
28
|
+
rowPinningDisplayMode,
|
26
29
|
selectAllMode,
|
27
30
|
},
|
28
31
|
} = table;
|
29
32
|
const { density, isLoading } = getState();
|
30
33
|
|
31
34
|
const checkboxProps = !row
|
32
|
-
? muiSelectAllCheckboxProps
|
33
|
-
|
34
|
-
: muiSelectAllCheckboxProps
|
35
|
-
: muiSelectCheckboxProps instanceof Function
|
36
|
-
? muiSelectCheckboxProps({ row, table })
|
37
|
-
: muiSelectCheckboxProps;
|
35
|
+
? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
|
36
|
+
: parseFromValuesOrFunc(muiSelectCheckboxProps, { row, table });
|
38
37
|
|
39
38
|
const allRowsSelected = selectAll
|
40
39
|
? selectAllMode === 'page'
|
@@ -50,12 +49,28 @@ export const MRT_SelectCheckbox = <TData extends Record<string, any>>({
|
|
50
49
|
? localization.toggleSelectAll
|
51
50
|
: localization.toggleSelectRow,
|
52
51
|
},
|
53
|
-
onChange:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
onChange: (event) => {
|
53
|
+
event.stopPropagation();
|
54
|
+
row
|
55
|
+
? row.getToggleSelectedHandler()(event)
|
56
|
+
: selectAllMode === 'all'
|
57
|
+
? table.getToggleAllRowsSelectedHandler()(event)
|
58
|
+
: table.getToggleAllPageRowsSelectedHandler()(event);
|
59
|
+
if (enableRowPinning && rowPinningDisplayMode?.includes('select')) {
|
60
|
+
if (row) {
|
61
|
+
row.pin(
|
62
|
+
!row.getIsPinned() && event.target.checked
|
63
|
+
? rowPinningDisplayMode?.includes('bottom')
|
64
|
+
? 'bottom'
|
65
|
+
: 'top'
|
66
|
+
: false,
|
67
|
+
);
|
68
|
+
} else {
|
69
|
+
table.setRowPinning({ bottom: [], top: [] });
|
70
|
+
}
|
71
|
+
}
|
72
|
+
},
|
73
|
+
size: (density === 'compact' ? 'small' : 'medium') as 'medium' | 'small',
|
59
74
|
...checkboxProps,
|
60
75
|
onClick: (e: MouseEvent<HTMLButtonElement>) => {
|
61
76
|
e.stopPropagation();
|
@@ -63,14 +78,13 @@ export const MRT_SelectCheckbox = <TData extends Record<string, any>>({
|
|
63
78
|
},
|
64
79
|
sx: (theme: Theme) => ({
|
65
80
|
height: density === 'compact' ? '1.75rem' : '2.5rem',
|
66
|
-
width: density === 'compact' ? '1.75rem' : '2.5rem',
|
67
81
|
m: density !== 'compact' ? '-0.4rem' : undefined,
|
68
|
-
|
69
|
-
|
70
|
-
|
82
|
+
width: density === 'compact' ? '1.75rem' : '2.5rem',
|
83
|
+
zIndex: 0,
|
84
|
+
...parseFromValuesOrFunc(checkboxProps?.sx, theme),
|
71
85
|
}),
|
72
86
|
title: undefined,
|
73
|
-
};
|
87
|
+
} as CheckboxProps | RadioProps;
|
74
88
|
|
75
89
|
return (
|
76
90
|
<Tooltip
|
package/src/locales/en.ts
CHANGED
@@ -14,7 +14,6 @@ export const MRT_Localization_EN: MRT_Localization = {
|
|
14
14
|
collapseAll: 'Collapse all',
|
15
15
|
columnActions: 'Column Actions',
|
16
16
|
copiedToClipboard: 'Copied to clipboard',
|
17
|
-
|
18
17
|
dropToGroupBy: 'Drop to group by {column}',
|
19
18
|
edit: 'Edit',
|
20
19
|
expand: 'Expand',
|
@@ -60,6 +59,7 @@ export const MRT_Localization_EN: MRT_Localization = {
|
|
60
59
|
noResultsFound: 'No results found',
|
61
60
|
of: 'of',
|
62
61
|
or: 'or',
|
62
|
+
pin: 'Pin',
|
63
63
|
pinToLeft: 'Pin to left',
|
64
64
|
pinToRight: 'Pin to right',
|
65
65
|
resetColumnSize: 'Reset column size',
|
package/src/locales/fr.ts
CHANGED
@@ -70,7 +70,7 @@ export const MRT_Localization_FR: MRT_Localization = {
|
|
70
70
|
save: 'Sauvegarder',
|
71
71
|
search: 'Rechercher',
|
72
72
|
selectedCountOfRowCountRowsSelected:
|
73
|
-
'{selectedCount}
|
73
|
+
'{selectedCount} sur {rowCount} ligne(s)',
|
74
74
|
select: 'Sélectionner',
|
75
75
|
showAll: 'Afficher tous',
|
76
76
|
showAllColumns: 'Afficher toutes les colonnes',
|
@@ -9,15 +9,15 @@ import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
|
|
9
9
|
import { type MRT_Header, type MRT_TableInstance } from '../types';
|
10
10
|
|
11
11
|
export const commonMenuItemStyles = {
|
12
|
-
py: '6px',
|
13
|
-
my: 0,
|
14
|
-
justifyContent: 'space-between',
|
15
12
|
alignItems: 'center',
|
13
|
+
justifyContent: 'space-between',
|
14
|
+
my: 0,
|
15
|
+
py: '6px',
|
16
16
|
};
|
17
17
|
|
18
18
|
export const commonListItemStyles = {
|
19
|
-
display: 'flex',
|
20
19
|
alignItems: 'center',
|
20
|
+
display: 'flex',
|
21
21
|
};
|
22
22
|
|
23
23
|
interface Props<TData extends Record<string, any>> {
|
@@ -35,36 +35,36 @@ export const MRT_ColumnActionMenu = <TData extends Record<string, any>>({
|
|
35
35
|
}: Props<TData>) => {
|
36
36
|
const {
|
37
37
|
getState,
|
38
|
-
toggleAllColumnsVisible,
|
39
|
-
setColumnOrder,
|
40
38
|
options: {
|
41
39
|
columnFilterModeOptions,
|
42
40
|
enableColumnFilterModes,
|
43
41
|
enableColumnFilters,
|
42
|
+
enableColumnPinning,
|
44
43
|
enableColumnResizing,
|
45
44
|
enableGrouping,
|
46
45
|
enableHiding,
|
47
|
-
enableColumnPinning,
|
48
46
|
enableSorting,
|
49
47
|
enableSortingRemoval,
|
50
48
|
icons: {
|
51
49
|
ArrowRightIcon,
|
52
50
|
ClearAllIcon,
|
53
|
-
ViewColumnIcon,
|
54
51
|
DynamicFeedIcon,
|
55
52
|
FilterListIcon,
|
56
53
|
FilterListOffIcon,
|
57
54
|
PushPinIcon,
|
58
|
-
SortIcon,
|
59
55
|
RestartAltIcon,
|
56
|
+
SortIcon,
|
57
|
+
ViewColumnIcon,
|
60
58
|
VisibilityOffIcon,
|
61
59
|
},
|
62
60
|
localization,
|
63
61
|
renderColumnActionsMenuItems,
|
64
62
|
},
|
65
63
|
refs: { filterInputRefs },
|
64
|
+
setColumnOrder,
|
66
65
|
setColumnSizingInfo,
|
67
66
|
setShowColumnFilters,
|
67
|
+
toggleAllColumnsVisible,
|
68
68
|
} = table;
|
69
69
|
const { column } = header;
|
70
70
|
const { columnDef } = column;
|
@@ -73,7 +73,7 @@ export const MRT_ColumnActionMenu = <TData extends Record<string, any>>({
|
|
73
73
|
const columnFilterValue = column.getFilterValue();
|
74
74
|
|
75
75
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
76
|
-
useState<
|
76
|
+
useState<HTMLElement | null>(null);
|
77
77
|
|
78
78
|
const handleClearSort = () => {
|
79
79
|
column.clearSorting();
|
@@ -180,9 +180,9 @@ export const MRT_ColumnActionMenu = <TData extends Record<string, any>>({
|
|
180
180
|
</Box>
|
181
181
|
</MenuItem>,
|
182
182
|
<MenuItem
|
183
|
+
disabled={column.getIsSorted() === 'desc'}
|
183
184
|
divider={enableColumnFilters || enableGrouping || enableHiding}
|
184
185
|
key={2}
|
185
|
-
disabled={column.getIsSorted() === 'desc'}
|
186
186
|
onClick={handleSortDesc}
|
187
187
|
sx={commonMenuItemStyles}
|
188
188
|
>
|
@@ -383,12 +383,12 @@ export const MRT_ColumnActionMenu = <TData extends Record<string, any>>({
|
|
383
383
|
|
384
384
|
return (
|
385
385
|
<Menu
|
386
|
-
anchorEl={anchorEl}
|
387
|
-
open={!!anchorEl}
|
388
|
-
onClose={() => setAnchorEl(null)}
|
389
386
|
MenuListProps={{
|
390
387
|
dense: density === 'compact',
|
391
388
|
}}
|
389
|
+
anchorEl={anchorEl}
|
390
|
+
onClose={() => setAnchorEl(null)}
|
391
|
+
open={!!anchorEl}
|
392
392
|
>
|
393
393
|
{columnDef.renderColumnActionsMenuItems?.({
|
394
394
|
closeMenu: () => setAnchorEl(null),
|