-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathGridActionsCellItem.tsx
More file actions
77 lines (67 loc) · 2.23 KB
/
GridActionsCellItem.tsx
File metadata and controls
77 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
73
74
75
76
77
'use client';
import * as React from 'react';
import { forwardRef } from '@mui/x-internals/forwardRef';
import type { GridSlotProps, GridBaseIconProps } from '../../models/gridSlotsComponentsProps';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
interface GridActionsCellItemCommonProps {
icon?: React.JSXElementConstructor<GridBaseIconProps> | React.ReactNode;
/** from https://mui.com/material-ui/api/button-base/#ButtonBase-prop-component */
component?: React.ElementType;
}
export type GridActionsCellItemProps = GridActionsCellItemCommonProps &
(
| ({ showInMenu?: false; icon: React.ReactElement<any>; label: string } & Omit<
GridSlotProps['baseIconButton'],
'component'
>)
| ({
showInMenu: true;
/**
* If false, the menu will not close when this item is clicked.
* @default true
*/
closeMenuOnClick?: boolean;
closeMenu?: () => void;
label: React.ReactNode;
} & Omit<GridSlotProps['baseMenuItem'], 'component'>)
);
const GridActionsCellItem = forwardRef<HTMLElement, GridActionsCellItemProps>((props, ref) => {
const rootProps = useGridRootProps();
if (!props.showInMenu) {
const { label, icon, showInMenu, onClick, ...other } = props;
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
onClick?.(event);
};
return (
<rootProps.slots.baseIconButton
size="small"
role="menuitem"
aria-label={label}
{...other}
onClick={handleClick}
{...rootProps.slotProps?.baseIconButton}
ref={ref as React.RefObject<HTMLButtonElement>}
>
{React.cloneElement(icon!, { fontSize: 'small' })}
</rootProps.slots.baseIconButton>
);
}
const { label, icon, showInMenu, onClick, closeMenuOnClick = true, closeMenu, ...other } = props;
const handleClick = (event: React.MouseEvent<HTMLLIElement>) => {
onClick?.(event);
if (closeMenuOnClick) {
closeMenu?.();
}
};
return (
<rootProps.slots.baseMenuItem
ref={ref}
{...(other as any)}
onClick={handleClick}
iconStart={icon}
>
{label}
</rootProps.slots.baseMenuItem>
);
});
export { GridActionsCellItem };