48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import * as React from 'react';
|
|
import Button from '@mui/material/Button';
|
|
import Menu from '@mui/material/Menu';
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
|
|
export default function BasicMenu({nickname}) {
|
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
const open = Boolean(anchorEl);
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
setAnchorEl(event.currentTarget);
|
|
};
|
|
const handleClose = () => {
|
|
setAnchorEl(null);
|
|
};
|
|
|
|
function logout() {
|
|
const logoutForm: HTMLFormElement = document.getElementById("logout-form") as HTMLFormElement;
|
|
logoutForm.submit();
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<Button
|
|
id="basic-button"
|
|
aria-controls={open ? 'basic-menu' : undefined}
|
|
aria-haspopup="true"
|
|
aria-expanded={open ? 'true' : undefined}
|
|
onClick={handleClick}
|
|
className={"flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out"}
|
|
>
|
|
{nickname}
|
|
</Button>
|
|
<Menu
|
|
id="basic-menu"
|
|
anchorEl={anchorEl}
|
|
open={open}
|
|
onClose={handleClose}
|
|
MenuListProps={{
|
|
'aria-labelledby': 'basic-button',
|
|
}}
|
|
>
|
|
{/*<MenuItem onClick={handleClose}>My account</MenuItem>*/}
|
|
<MenuItem onClick={logout}>Logout</MenuItem>
|
|
</Menu>
|
|
</div>
|
|
);
|
|
}
|