-
-
Notifications
You must be signed in to change notification settings - Fork 554
/
button-user-avatar.tsx
57 lines (52 loc) · 1.5 KB
/
button-user-avatar.tsx
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
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { LogoutRounded, SettingsRounded } from "@mui/icons-material";
import {
Avatar,
Dropdown,
IconButton,
IconButtonProps,
ListItemContent,
ListItemDecorator,
Menu,
MenuButton,
MenuItem,
} from "@mui/joy";
import { getAuth, signOut } from "firebase/auth";
import { useCurrentUser } from "../core/auth";
export function UserAvatarButton(props: UserAvatarButtonProps): JSX.Element {
const { sx, ...other } = props;
const user = useCurrentUser()!;
return (
<Dropdown>
<MenuButton
slots={{ root: IconButton }}
slotProps={{
root: {
sx: { borderRadius: "50%", p: "2px", ...sx },
...other,
},
}}
>
<Avatar sx={{ width: 36, height: 36 }} src={user.photoURL ?? undefined}>
{user.displayName}
</Avatar>
</MenuButton>
<Menu size="sm">
<MenuItem>
<ListItemDecorator sx={{ ml: 0.5 }}>
<SettingsRounded />
</ListItemDecorator>
<ListItemContent sx={{ mr: 2 }}>Settings</ListItemContent>
</MenuItem>
<MenuItem onClick={() => signOut(getAuth())}>
<ListItemDecorator sx={{ ml: 0.5 }}>
<LogoutRounded />
</ListItemDecorator>
<ListItemContent sx={{ mr: 2 }}>Logout</ListItemContent>
</MenuItem>
</Menu>
</Dropdown>
);
}
export type UserAvatarButtonProps = Omit<IconButtonProps, "children">;