-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathActionMenu.tsx
More file actions
52 lines (45 loc) · 1.12 KB
/
ActionMenu.tsx
File metadata and controls
52 lines (45 loc) · 1.12 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
import { MoreVert } from "@mui/icons-material";
import { IconButton, Menu, MenuItem } from "@mui/material";
import { useState } from "react";
interface Item {
label: string;
onClick: () => void;
}
interface ActionMenuProps {
items: Item[]
}
export default function ActionMenu({items}: ActionMenuProps) {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = (props?: any) => {
setAnchorEl(null);
};
return (
<>
<IconButton onClick={handleClick}>
<MoreVert />
</IconButton>
<Menu
id="basic-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
>
{items.map((item) => (
<MenuItem key={item.label} onClick={() => {
item.onClick();
handleClose()
}}>
{item.label}
</MenuItem>
))}
</Menu>
</>
)
}