material-react-table 2.9.2 → 2.11.0
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/index.d.ts +222 -152
- package/dist/index.esm.js +906 -769
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +910 -768
- package/dist/index.js.map +1 -1
- package/locales/ar/index.esm.js +2 -0
- package/locales/ar/index.js +2 -0
- package/locales/az/index.esm.js +2 -0
- package/locales/az/index.js +2 -0
- package/locales/bg/index.esm.js +2 -0
- package/locales/bg/index.js +2 -0
- package/locales/cs/index.esm.js +2 -0
- package/locales/cs/index.js +2 -0
- package/locales/da/index.esm.js +2 -0
- package/locales/da/index.js +2 -0
- package/locales/de/index.esm.js +2 -0
- package/locales/de/index.js +2 -0
- package/locales/en/index.esm.js +2 -0
- package/locales/en/index.js +2 -0
- package/locales/es/index.esm.js +2 -0
- package/locales/es/index.js +2 -0
- package/locales/et/index.esm.js +2 -0
- package/locales/et/index.js +2 -0
- package/locales/fa/index.esm.js +2 -0
- package/locales/fa/index.js +2 -0
- package/locales/fi/index.esm.js +2 -0
- package/locales/fi/index.js +2 -0
- package/locales/fr/index.esm.js +2 -0
- package/locales/fr/index.js +2 -0
- package/locales/he/index.esm.js +2 -0
- package/locales/he/index.js +2 -0
- package/locales/hu/index.esm.js +2 -0
- package/locales/hu/index.js +2 -0
- package/locales/hy/index.esm.js +2 -0
- package/locales/hy/index.js +2 -0
- package/locales/id/index.esm.js +2 -0
- package/locales/id/index.js +2 -0
- package/locales/it/index.esm.js +2 -0
- package/locales/it/index.js +2 -0
- package/locales/ja/index.esm.js +2 -0
- package/locales/ja/index.js +2 -0
- package/locales/ko/index.esm.js +2 -0
- package/locales/ko/index.js +2 -0
- package/locales/nl/index.esm.js +2 -0
- package/locales/nl/index.js +2 -0
- package/locales/no/index.esm.js +2 -0
- package/locales/no/index.js +2 -0
- package/locales/np/index.esm.js +2 -0
- package/locales/np/index.js +2 -0
- package/locales/pl/index.esm.js +2 -0
- package/locales/pl/index.js +2 -0
- package/locales/pt/index.esm.js +2 -0
- package/locales/pt/index.js +2 -0
- package/locales/pt-BR/index.esm.js +2 -0
- package/locales/pt-BR/index.js +2 -0
- package/locales/ro/index.esm.js +2 -0
- package/locales/ro/index.js +2 -0
- package/locales/ru/index.esm.js +2 -0
- package/locales/ru/index.js +2 -0
- package/locales/sk/index.esm.js +2 -0
- package/locales/sk/index.js +2 -0
- package/locales/sr-Cyrl-RS/index.esm.js +2 -0
- package/locales/sr-Cyrl-RS/index.js +2 -0
- package/locales/sr-Latn-RS/index.esm.js +2 -0
- package/locales/sr-Latn-RS/index.js +2 -0
- package/locales/sv/index.esm.js +2 -0
- package/locales/sv/index.js +2 -0
- package/locales/tr/index.esm.js +2 -0
- package/locales/tr/index.js +2 -0
- package/locales/uk/index.esm.js +2 -0
- package/locales/uk/index.js +2 -0
- package/locales/vi/index.esm.js +2 -0
- package/locales/vi/index.js +2 -0
- package/locales/zh-Hans/index.esm.js +2 -0
- package/locales/zh-Hans/index.js +2 -0
- package/locales/zh-Hant/index.esm.js +2 -0
- package/locales/zh-Hant/index.js +2 -0
- package/package.json +20 -20
- package/src/components/MaterialReactTable.tsx +3 -3
- package/src/components/body/MRT_TableBody.tsx +3 -2
- package/src/components/body/MRT_TableBodyCell.tsx +45 -34
- package/src/components/body/MRT_TableBodyCellValue.tsx +5 -2
- package/src/components/body/MRT_TableBodyRow.tsx +13 -12
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -3
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +3 -2
- package/src/components/body/MRT_TableDetailPanel.tsx +3 -2
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +3 -2
- package/src/components/buttons/MRT_CopyButton.tsx +4 -2
- package/src/components/buttons/MRT_EditActionButtons.tsx +3 -2
- package/src/components/buttons/MRT_ExpandAllButton.tsx +3 -2
- package/src/components/buttons/MRT_ExpandButton.tsx +3 -2
- package/src/components/buttons/MRT_GrabHandleButton.tsx +9 -15
- package/src/components/buttons/MRT_RowPinButton.tsx +3 -2
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +3 -2
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +3 -2
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -2
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +3 -2
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -2
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +3 -2
- package/src/components/footer/MRT_TableFooter.tsx +3 -2
- package/src/components/footer/MRT_TableFooterCell.tsx +3 -2
- package/src/components/footer/MRT_TableFooterRow.tsx +5 -3
- package/src/components/head/MRT_TableHead.tsx +3 -2
- package/src/components/head/MRT_TableHeadCell.tsx +9 -5
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +4 -2
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -2
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +4 -2
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +4 -3
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +3 -2
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +3 -2
- package/src/components/head/MRT_TableHeadRow.tsx +4 -2
- package/src/components/inputs/MRT_EditCellTextField.tsx +3 -2
- package/src/components/inputs/MRT_FilterCheckbox.tsx +3 -2
- package/src/components/inputs/MRT_FilterRangeFields.tsx +3 -2
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +3 -2
- package/src/components/inputs/MRT_FilterTextField.tsx +15 -6
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +3 -2
- package/src/components/inputs/MRT_SelectCheckbox.tsx +26 -33
- package/src/components/menus/MRT_ActionMenuItem.tsx +61 -0
- package/src/components/menus/MRT_CellActionMenu.tsx +109 -0
- package/src/components/menus/MRT_ColumnActionMenu.tsx +92 -172
- package/src/components/menus/MRT_FilterOptionMenu.tsx +9 -16
- package/src/components/menus/MRT_RowActionMenu.tsx +10 -17
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +11 -3
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +7 -5
- package/src/components/modals/MRT_EditRowModal.tsx +3 -2
- package/src/components/table/MRT_Table.tsx +2 -2
- package/src/components/table/MRT_TableContainer.tsx +7 -2
- package/src/components/table/MRT_TableLoadingOverlay.tsx +11 -8
- package/src/components/table/MRT_TablePaper.tsx +3 -2
- package/src/components/toolbar/MRT_BottomToolbar.tsx +3 -2
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +3 -2
- package/src/components/toolbar/MRT_TablePagination.tsx +2 -2
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +30 -13
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +3 -2
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +3 -2
- package/src/components/toolbar/MRT_TopToolbar.tsx +2 -2
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +1 -8
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +1 -8
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +1 -8
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +1 -8
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +1 -8
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +1 -8
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -8
- package/src/hooks/useMRT_Effects.ts +14 -4
- package/src/hooks/useMRT_Rows.ts +11 -79
- package/src/hooks/useMRT_TableInstance.ts +114 -59
- package/src/hooks/useMRT_TableOptions.ts +2 -0
- package/src/icons.ts +2 -0
- package/src/index.ts +2 -0
- package/src/locales/ar.ts +2 -0
- package/src/locales/az.ts +2 -0
- package/src/locales/bg.ts +2 -0
- package/src/locales/cs.ts +2 -0
- package/src/locales/da.ts +2 -0
- package/src/locales/de.ts +2 -0
- package/src/locales/en.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/et.ts +2 -0
- package/src/locales/fa.ts +2 -0
- package/src/locales/fi.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/he.ts +2 -0
- package/src/locales/hu.ts +2 -0
- package/src/locales/hy.ts +2 -0
- package/src/locales/id.ts +2 -0
- package/src/locales/it.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/nl.ts +2 -0
- package/src/locales/no.ts +2 -0
- package/src/locales/np.ts +2 -0
- package/src/locales/pl.ts +2 -0
- package/src/locales/pt-BR.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/ro.ts +2 -0
- package/src/locales/ru.ts +2 -0
- package/src/locales/sk.ts +2 -0
- package/src/locales/sr-Cyrl-RS.ts +2 -0
- package/src/locales/sr-Latn-RS.ts +2 -0
- package/src/locales/sv.ts +2 -0
- package/src/locales/tr.ts +2 -0
- package/src/locales/uk.ts +2 -0
- package/src/locales/vi.ts +2 -0
- package/src/locales/zh-Hans.ts +2 -0
- package/src/locales/zh-Hant.ts +2 -0
- package/src/types.ts +51 -13
- package/src/utils/cell.utils.ts +50 -0
- package/src/utils/column.utils.ts +4 -6
- package/src/utils/displayColumn.utils.ts +39 -21
- package/src/utils/row.utils.ts +179 -21
- package/locales/am/index.d.ts +0 -3
- package/locales/am/index.esm.d.ts +0 -3
- package/locales/am/index.esm.js +0 -93
- package/locales/am/index.js +0 -97
- package/locales/am/package.json +0 -6
- package/src/hooks/display-columns/getMRT_DisplayColumns.tsx +0 -26
- package/src/locales/am.ts +0 -94
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
} from '../../types';
|
|
15
15
|
import { getValueAndLabel, parseFromValuesOrFunc } from '../../utils/utils';
|
|
16
16
|
|
|
17
|
-
interface
|
|
17
|
+
export interface MRT_EditCellTextFieldProps<TData extends MRT_RowData>
|
|
18
|
+
extends TextFieldProps<'standard'> {
|
|
18
19
|
cell: MRT_Cell<TData>;
|
|
19
20
|
table: MRT_TableInstance<TData>;
|
|
20
21
|
}
|
|
@@ -23,7 +24,7 @@ export const MRT_EditCellTextField = <TData extends MRT_RowData>({
|
|
|
23
24
|
cell,
|
|
24
25
|
table,
|
|
25
26
|
...rest
|
|
26
|
-
}:
|
|
27
|
+
}: MRT_EditCellTextFieldProps<TData>) => {
|
|
27
28
|
const {
|
|
28
29
|
getState,
|
|
29
30
|
options: { createDisplayMode, editDisplayMode, muiEditTextFieldProps },
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
import { getCommonTooltipProps } from '../../utils/style.utils';
|
|
10
10
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
11
11
|
|
|
12
|
-
interface
|
|
12
|
+
export interface MRT_FilterCheckboxProps<TData extends MRT_RowData>
|
|
13
|
+
extends CheckboxProps {
|
|
13
14
|
column: MRT_Column<TData>;
|
|
14
15
|
table: MRT_TableInstance<TData>;
|
|
15
16
|
}
|
|
@@ -18,7 +19,7 @@ export const MRT_FilterCheckbox = <TData extends MRT_RowData>({
|
|
|
18
19
|
column,
|
|
19
20
|
table,
|
|
20
21
|
...rest
|
|
21
|
-
}:
|
|
22
|
+
}: MRT_FilterCheckboxProps<TData>) => {
|
|
22
23
|
const {
|
|
23
24
|
getState,
|
|
24
25
|
options: { localization, muiFilterCheckboxProps },
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
} from '../../types';
|
|
8
8
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
9
9
|
|
|
10
|
-
interface
|
|
10
|
+
export interface MRT_FilterRangeFieldsProps<TData extends MRT_RowData>
|
|
11
|
+
extends BoxProps {
|
|
11
12
|
header: MRT_Header<TData>;
|
|
12
13
|
table: MRT_TableInstance<TData>;
|
|
13
14
|
}
|
|
@@ -16,7 +17,7 @@ export const MRT_FilterRangeFields = <TData extends MRT_RowData>({
|
|
|
16
17
|
header,
|
|
17
18
|
table,
|
|
18
19
|
...rest
|
|
19
|
-
}:
|
|
20
|
+
}: MRT_FilterRangeFieldsProps<TData>) => {
|
|
20
21
|
return (
|
|
21
22
|
<Box
|
|
22
23
|
{...rest}
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
} from '../../types';
|
|
10
10
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
11
11
|
|
|
12
|
-
interface
|
|
12
|
+
export interface MRT_FilterRangeSliderProps<TData extends MRT_RowData>
|
|
13
|
+
extends SliderProps {
|
|
13
14
|
header: MRT_Header<TData>;
|
|
14
15
|
table: MRT_TableInstance<TData>;
|
|
15
16
|
}
|
|
@@ -18,7 +19,7 @@ export const MRT_FilterRangeSlider = <TData extends MRT_RowData>({
|
|
|
18
19
|
header,
|
|
19
20
|
table,
|
|
20
21
|
...rest
|
|
21
|
-
}:
|
|
22
|
+
}: MRT_FilterRangeSliderProps<TData>) => {
|
|
22
23
|
const {
|
|
23
24
|
options: { enableColumnFilterModes, localization, muiFilterSliderProps },
|
|
24
25
|
refs: { filterInputRefs },
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
type TimePickerProps,
|
|
31
31
|
} from '@mui/x-date-pickers/TimePicker';
|
|
32
32
|
import {
|
|
33
|
+
type DropdownOption,
|
|
33
34
|
type MRT_Header,
|
|
34
35
|
type MRT_RowData,
|
|
35
36
|
type MRT_TableInstance,
|
|
@@ -37,7 +38,8 @@ import {
|
|
|
37
38
|
import { getValueAndLabel, parseFromValuesOrFunc } from '../../utils/utils';
|
|
38
39
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
39
40
|
|
|
40
|
-
interface
|
|
41
|
+
export interface MRT_FilterTextFieldProps<TData extends MRT_RowData>
|
|
42
|
+
extends TextFieldProps<'standard'> {
|
|
41
43
|
header: MRT_Header<TData>;
|
|
42
44
|
rangeFilterIndex?: number;
|
|
43
45
|
table: MRT_TableInstance<TData>;
|
|
@@ -48,7 +50,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
|
48
50
|
rangeFilterIndex,
|
|
49
51
|
table,
|
|
50
52
|
...rest
|
|
51
|
-
}:
|
|
53
|
+
}: MRT_FilterTextFieldProps<TData>) => {
|
|
52
54
|
const {
|
|
53
55
|
options: {
|
|
54
56
|
columnFilterModeOptions,
|
|
@@ -159,6 +161,10 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
|
159
161
|
] || ''
|
|
160
162
|
: (column.getFilterValue() as string) ?? '',
|
|
161
163
|
);
|
|
164
|
+
const [autocompleteValue, setAutocompleteValue] =
|
|
165
|
+
useState<DropdownOption | null>(
|
|
166
|
+
isAutocompleteFilter ? (filterValue as DropdownOption | null) : null,
|
|
167
|
+
);
|
|
162
168
|
|
|
163
169
|
const handleChangeDebounced = useCallback(
|
|
164
170
|
debounce(
|
|
@@ -194,6 +200,11 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
|
194
200
|
textFieldProps?.onChange?.(event);
|
|
195
201
|
};
|
|
196
202
|
|
|
203
|
+
const handleAutocompleteChange = (newValue: DropdownOption) => {
|
|
204
|
+
setAutocompleteValue(newValue);
|
|
205
|
+
handleChange(getValueAndLabel(newValue).value);
|
|
206
|
+
};
|
|
207
|
+
|
|
197
208
|
const handleClear = () => {
|
|
198
209
|
if (isMultiSelectFilter) {
|
|
199
210
|
setFilterValue([]);
|
|
@@ -437,9 +448,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
|
437
448
|
<Autocomplete
|
|
438
449
|
freeSolo
|
|
439
450
|
getOptionLabel={(option) => getValueAndLabel(option).label}
|
|
440
|
-
onChange={(_e, newValue) =>
|
|
441
|
-
handleChange(getValueAndLabel(newValue).value)
|
|
442
|
-
}
|
|
451
|
+
onChange={(_e, newValue) => handleAutocompleteChange(newValue)}
|
|
443
452
|
options={
|
|
444
453
|
dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
|
|
445
454
|
}
|
|
@@ -461,7 +470,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
|
461
470
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
462
471
|
/>
|
|
463
472
|
)}
|
|
464
|
-
value={
|
|
473
|
+
value={autocompleteValue}
|
|
465
474
|
/>
|
|
466
475
|
) : (
|
|
467
476
|
<TextField
|
|
@@ -16,14 +16,15 @@ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
|
16
16
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
17
17
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
18
18
|
|
|
19
|
-
interface
|
|
19
|
+
export interface MRT_GlobalFilterTextFieldProps<TData extends MRT_RowData>
|
|
20
|
+
extends TextFieldProps<'standard'> {
|
|
20
21
|
table: MRT_TableInstance<TData>;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export const MRT_GlobalFilterTextField = <TData extends MRT_RowData>({
|
|
24
25
|
table,
|
|
25
26
|
...rest
|
|
26
|
-
}:
|
|
27
|
+
}: MRT_GlobalFilterTextFieldProps<TData>) => {
|
|
27
28
|
const {
|
|
28
29
|
getState,
|
|
29
30
|
options: {
|
|
@@ -8,11 +8,15 @@ import {
|
|
|
8
8
|
type MRT_RowData,
|
|
9
9
|
type MRT_TableInstance,
|
|
10
10
|
} from '../../types';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
getIsRowSelected,
|
|
13
|
+
getMRT_RowSelectionHandler,
|
|
14
|
+
} from '../../utils/row.utils';
|
|
12
15
|
import { getCommonTooltipProps } from '../../utils/style.utils';
|
|
13
16
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
14
17
|
|
|
15
|
-
interface
|
|
18
|
+
export interface MRT_SelectCheckboxProps<TData extends MRT_RowData>
|
|
19
|
+
extends CheckboxProps {
|
|
16
20
|
row?: MRT_Row<TData>;
|
|
17
21
|
staticRowIndex?: number;
|
|
18
22
|
table: MRT_TableInstance<TData>;
|
|
@@ -23,7 +27,7 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
|
|
|
23
27
|
staticRowIndex,
|
|
24
28
|
table,
|
|
25
29
|
...rest
|
|
26
|
-
}:
|
|
30
|
+
}: MRT_SelectCheckboxProps<TData>) => {
|
|
27
31
|
const {
|
|
28
32
|
getState,
|
|
29
33
|
options: {
|
|
@@ -35,22 +39,12 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
|
|
|
35
39
|
rowPinningDisplayMode,
|
|
36
40
|
selectAllMode,
|
|
37
41
|
},
|
|
42
|
+
refs: { lastSelectedRowId },
|
|
38
43
|
} = table;
|
|
39
44
|
const { density, isLoading } = getState();
|
|
40
45
|
|
|
41
46
|
const selectAll = !row;
|
|
42
47
|
|
|
43
|
-
const checkboxProps = {
|
|
44
|
-
...(!row
|
|
45
|
-
? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
|
|
46
|
-
: parseFromValuesOrFunc(muiSelectCheckboxProps, {
|
|
47
|
-
row,
|
|
48
|
-
staticRowIndex,
|
|
49
|
-
table,
|
|
50
|
-
})),
|
|
51
|
-
...rest,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
48
|
const isStickySelection =
|
|
55
49
|
enableRowPinning && rowPinningDisplayMode?.includes('select');
|
|
56
50
|
|
|
@@ -60,26 +54,22 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
|
|
|
60
54
|
: table.getIsAllRowsSelected()
|
|
61
55
|
: undefined;
|
|
62
56
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
) => {
|
|
67
|
-
if (row.getIsAllSubRowsSelected() && row.getCanSelectSubRows()) {
|
|
68
|
-
row.subRows?.forEach((r) => r.toggleSelected(false));
|
|
69
|
-
}
|
|
70
|
-
row.getToggleSelectedHandler()(event);
|
|
57
|
+
const isChecked = selectAll
|
|
58
|
+
? allRowsSelected
|
|
59
|
+
: getIsRowSelected({ row, table });
|
|
71
60
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
61
|
+
const checkboxProps = {
|
|
62
|
+
...(selectAll
|
|
63
|
+
? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
|
|
64
|
+
: parseFromValuesOrFunc(muiSelectCheckboxProps, {
|
|
65
|
+
row,
|
|
66
|
+
table,
|
|
67
|
+
})),
|
|
68
|
+
...rest,
|
|
81
69
|
};
|
|
82
70
|
|
|
71
|
+
const onSelectionChange = getMRT_RowSelectionHandler();
|
|
72
|
+
|
|
83
73
|
const onSelectAllChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
84
74
|
selectAllMode === 'all'
|
|
85
75
|
? table.getToggleAllRowsSelectedHandler()(event)
|
|
@@ -87,13 +77,14 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
|
|
|
87
77
|
if (isStickySelection) {
|
|
88
78
|
table.setRowPinning({ bottom: [], top: [] });
|
|
89
79
|
}
|
|
80
|
+
lastSelectedRowId.current = null;
|
|
90
81
|
};
|
|
91
82
|
|
|
92
83
|
const commonProps = {
|
|
93
84
|
'aria-label': selectAll
|
|
94
85
|
? localization.toggleSelectAll
|
|
95
86
|
: localization.toggleSelectRow,
|
|
96
|
-
checked:
|
|
87
|
+
checked: isChecked,
|
|
97
88
|
disabled:
|
|
98
89
|
isLoading || (row && !row.getCanSelect()) || row?.id === 'mrt-row-create',
|
|
99
90
|
inputProps: {
|
|
@@ -103,7 +94,9 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
|
|
|
103
94
|
},
|
|
104
95
|
onChange: (event) => {
|
|
105
96
|
event.stopPropagation();
|
|
106
|
-
row
|
|
97
|
+
row
|
|
98
|
+
? onSelectionChange({ event, row, staticRowIndex, table })
|
|
99
|
+
: onSelectAllChange(event);
|
|
107
100
|
},
|
|
108
101
|
size: (density === 'compact' ? 'small' : 'medium') as 'medium' | 'small',
|
|
109
102
|
...checkboxProps,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import IconButton from '@mui/material/IconButton';
|
|
4
|
+
import ListItemIcon from '@mui/material/ListItemIcon';
|
|
5
|
+
import MenuItem, { type MenuItemProps } from '@mui/material/MenuItem';
|
|
6
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
7
|
+
|
|
8
|
+
export interface MRT_ActionMenuItemProps<TData extends MRT_RowData>
|
|
9
|
+
extends MenuItemProps {
|
|
10
|
+
icon: ReactNode;
|
|
11
|
+
label: string;
|
|
12
|
+
onOpenSubMenu?: MenuItemProps['onClick'] | MenuItemProps['onMouseEnter'];
|
|
13
|
+
table: MRT_TableInstance<TData>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const MRT_ActionMenuItem = <TData extends MRT_RowData>({
|
|
17
|
+
icon,
|
|
18
|
+
label,
|
|
19
|
+
onOpenSubMenu,
|
|
20
|
+
table,
|
|
21
|
+
...rest
|
|
22
|
+
}: MRT_ActionMenuItemProps<TData>) => {
|
|
23
|
+
const {
|
|
24
|
+
options: {
|
|
25
|
+
icons: { ArrowRightIcon },
|
|
26
|
+
},
|
|
27
|
+
} = table;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<MenuItem
|
|
31
|
+
sx={{
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
justifyContent: 'space-between',
|
|
34
|
+
minWidth: '120px',
|
|
35
|
+
my: 0,
|
|
36
|
+
py: '6px',
|
|
37
|
+
}}
|
|
38
|
+
{...rest}
|
|
39
|
+
>
|
|
40
|
+
<Box
|
|
41
|
+
sx={{
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
display: 'flex',
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<ListItemIcon>{icon}</ListItemIcon>
|
|
47
|
+
{label}
|
|
48
|
+
</Box>
|
|
49
|
+
{onOpenSubMenu && (
|
|
50
|
+
<IconButton
|
|
51
|
+
onClick={onOpenSubMenu as any}
|
|
52
|
+
onMouseEnter={onOpenSubMenu as any}
|
|
53
|
+
size="small"
|
|
54
|
+
sx={{ p: 0 }}
|
|
55
|
+
>
|
|
56
|
+
<ArrowRightIcon />
|
|
57
|
+
</IconButton>
|
|
58
|
+
)}
|
|
59
|
+
</MenuItem>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import Menu, { type MenuProps } from '@mui/material/Menu';
|
|
2
|
+
import { useTheme } from '@mui/material/styles';
|
|
3
|
+
import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
|
|
4
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
5
|
+
import { openEditingCell } from '../../utils/cell.utils';
|
|
6
|
+
import { getMRTTheme } from '../../utils/style.utils';
|
|
7
|
+
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
8
|
+
|
|
9
|
+
export interface MRT_CellActionMenuProps<TData extends MRT_RowData>
|
|
10
|
+
extends Partial<MenuProps> {
|
|
11
|
+
table: MRT_TableInstance<TData>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const MRT_CellActionMenu = <TData extends MRT_RowData>({
|
|
15
|
+
table,
|
|
16
|
+
...rest
|
|
17
|
+
}: MRT_CellActionMenuProps<TData>) => {
|
|
18
|
+
const {
|
|
19
|
+
getState,
|
|
20
|
+
options: {
|
|
21
|
+
editDisplayMode,
|
|
22
|
+
enableClickToCopy,
|
|
23
|
+
enableEditing,
|
|
24
|
+
icons: { ContentCopy, EditIcon },
|
|
25
|
+
localization,
|
|
26
|
+
renderCellActionMenuItems,
|
|
27
|
+
},
|
|
28
|
+
refs: { actionCellRef },
|
|
29
|
+
} = table;
|
|
30
|
+
const { actionCell, density } = getState();
|
|
31
|
+
const cell = actionCell!;
|
|
32
|
+
const { row } = cell;
|
|
33
|
+
const { column } = cell;
|
|
34
|
+
const { columnDef } = column;
|
|
35
|
+
|
|
36
|
+
const theme = useTheme();
|
|
37
|
+
const { menuBackgroundColor } = getMRTTheme(table, theme);
|
|
38
|
+
|
|
39
|
+
const handleClose = (event?: any) => {
|
|
40
|
+
event?.stopPropagation();
|
|
41
|
+
table.setActionCell(null);
|
|
42
|
+
actionCellRef.current = null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const internalMenuItems = [
|
|
46
|
+
(parseFromValuesOrFunc(enableClickToCopy, cell) === 'context-menu' ||
|
|
47
|
+
parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) ===
|
|
48
|
+
'context-menu') && (
|
|
49
|
+
<MRT_ActionMenuItem
|
|
50
|
+
icon={<ContentCopy />}
|
|
51
|
+
key={'mrt-copy'}
|
|
52
|
+
label={localization.copy}
|
|
53
|
+
onClick={(event) => {
|
|
54
|
+
event.stopPropagation();
|
|
55
|
+
navigator.clipboard.writeText(cell.getValue() as string);
|
|
56
|
+
handleClose();
|
|
57
|
+
}}
|
|
58
|
+
table={table}
|
|
59
|
+
/>
|
|
60
|
+
),
|
|
61
|
+
parseFromValuesOrFunc(enableEditing, row) && editDisplayMode === 'cell' && (
|
|
62
|
+
<MRT_ActionMenuItem
|
|
63
|
+
icon={<EditIcon />}
|
|
64
|
+
key={'mrt-edit'}
|
|
65
|
+
label={localization.edit}
|
|
66
|
+
onClick={() => {
|
|
67
|
+
openEditingCell({ cell, table });
|
|
68
|
+
handleClose();
|
|
69
|
+
}}
|
|
70
|
+
table={table}
|
|
71
|
+
/>
|
|
72
|
+
),
|
|
73
|
+
].filter(Boolean);
|
|
74
|
+
|
|
75
|
+
const renderActionProps = {
|
|
76
|
+
cell,
|
|
77
|
+
closeMenu: handleClose,
|
|
78
|
+
column,
|
|
79
|
+
internalMenuItems,
|
|
80
|
+
row,
|
|
81
|
+
table,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const menuItems =
|
|
85
|
+
columnDef.renderCellActionMenuItems?.(renderActionProps) ??
|
|
86
|
+
renderCellActionMenuItems?.(renderActionProps);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
(!!menuItems?.length || !!internalMenuItems?.length) && (
|
|
90
|
+
<Menu
|
|
91
|
+
MenuListProps={{
|
|
92
|
+
dense: density === 'compact',
|
|
93
|
+
sx: {
|
|
94
|
+
backgroundColor: menuBackgroundColor,
|
|
95
|
+
},
|
|
96
|
+
}}
|
|
97
|
+
anchorEl={actionCellRef.current}
|
|
98
|
+
disableScrollLock
|
|
99
|
+
onClick={(event) => event.stopPropagation()}
|
|
100
|
+
onClose={handleClose}
|
|
101
|
+
open={!!cell}
|
|
102
|
+
transformOrigin={{ horizontal: -100, vertical: 8 }}
|
|
103
|
+
{...rest}
|
|
104
|
+
>
|
|
105
|
+
{menuItems ?? internalMenuItems}
|
|
106
|
+
</Menu>
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
};
|