-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from tokomath/topbar
トップバーのユーザー名をクリックすると、サインアウトのメニューが出てくるように
- Loading branch information
Showing
2 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// トップバーに表示するための、ユーザーメニューを表示するコンポーネント | ||
// アイコンとユーザー名を表示し、クリックするとメニューが表示される | ||
|
||
import React from 'react'; | ||
import { AccountCircle, ExitToAppSharp } from "@mui/icons-material"; | ||
import { Button, Menu, MenuItem } from "@mui/material"; | ||
import { signOut } from "next-auth/react"; | ||
import { ArrowDropDownIcon } from '@mui/x-date-pickers'; | ||
|
||
interface UserMenuProps { | ||
user_name: string; | ||
} | ||
|
||
export default function UserMenu({ user_name }: UserMenuProps) { | ||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button | ||
color="inherit" | ||
size='large' | ||
startIcon={<AccountCircle />} | ||
endIcon={<ArrowDropDownIcon />} | ||
onClick={handleClick} | ||
style={{ textTransform: 'none' }} | ||
> | ||
{user_name} | ||
</Button > | ||
<Menu | ||
anchorEl={anchorEl} | ||
open={Boolean(anchorEl)} | ||
onClose={() => setAnchorEl(null)} | ||
> | ||
<MenuItem onClick={() => signOut()}><ExitToAppSharp />SignOut</MenuItem> | ||
</Menu> | ||
</> | ||
); | ||
} |