forked from rpailer/todo-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavBar.jsx
59 lines (46 loc) · 1.52 KB
/
NavBar.jsx
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
import { AppBar, IconButton, Menu, MenuItem, Toolbar, Typography } from "@mui/material";
import MenuIcon from '@mui/icons-material/Menu';
import { useState } from "react";
import { useRouter } from 'next/router'
export default function NavBar () {
const [anchorEl, setAnchorEl] = useState(null);
const router = useRouter();
const handleMenuClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = (event) => {
console.log("Handle menu " + event.target.id);
setAnchorEl(null);
switch (event.target.id) {
case "todo":
router.push("/");
return;
default:
router.push("/");
return;
}
};
return (
<div>
<AppBar position="static">
<Toolbar>
<IconButton edge="start" color="inherit" aria-label="menu" onClick={handleMenuClick}>
<MenuIcon />
</IconButton>
<Menu
id="simple-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem id="todo" onClick={handleClose}>TODOs</MenuItem>
</Menu>
<Typography variant="h6">
TODO App
</Typography>
</Toolbar>
</AppBar>
</div>
);
}