forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserMenu.tsx
More file actions
92 lines (82 loc) · 2.66 KB
/
UserMenu.tsx
File metadata and controls
92 lines (82 loc) · 2.66 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* SPDX-FileCopyrightText: 2014-present Kriasoft <hello@kriasoft.com> */
/* SPDX-License-Identifier: MIT */
import {
Link,
ListItemIcon,
ListItemText,
Menu,
MenuItem,
MenuProps,
Switch,
} from "@material-ui/core";
import { useTheme } from "@material-ui/core/styles";
import { Brightness4, Settings } from "@material-ui/icons";
import * as React from "react";
import { useNavigate, useSignOut } from "../hooks";
import { Logout } from "../icons";
type UserMenuProps = Omit<
MenuProps,
"id" | "role" | "open" | "anchorOrigin" | "transformOrigin"
> & {
onChangeTheme: () => void;
};
export function UserMenu(props: UserMenuProps): JSX.Element {
const { onChangeTheme, PaperProps, MenuListProps, ...other } = props;
const navigate = useNavigate();
const signOut = useSignOut();
const theme = useTheme();
function handleClick(event: React.MouseEvent<HTMLAnchorElement>): void {
props.onClose?.(event, "backdropClick");
navigate(event);
}
return (
<Menu
id="user-menu"
role="menu"
open={Boolean(props.anchorEl)}
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
transformOrigin={{ vertical: "top", horizontal: "right" }}
PaperProps={{ ...PaperProps, sx: { ...PaperProps?.sx, width: 320 } }}
MenuListProps={{ ...MenuListProps, dense: true }}
{...other}
>
<MenuItem component={Link} href="/settings" onClick={handleClick}>
<ListItemIcon sx={{ minWidth: 40 }} children={<Settings />} />
<ListItemText primary="Account Settings" />
</MenuItem>
<MenuItem>
<ListItemIcon sx={{ minWidth: 40 }} children={<Brightness4 />} />
<ListItemText primary="Dark Mode" />
<Switch
name="theme"
checked={theme?.palette?.mode === "dark"}
onChange={onChangeTheme}
/>
</MenuItem>
<MenuItem onClick={signOut}>
<ListItemIcon sx={{ minWidth: 40 }} children={<Logout />} />
<ListItemText primary="Log Out" />
</MenuItem>
{/* Copyright and links to legal documents */}
<MenuItem
sx={{
"&:hover": { background: "none" },
color: (x) => x.palette.grey[500],
paddingTop: (x) => x.spacing(0.5),
paddingBottom: (x) => x.spacing(0.5),
fontSize: "0.75rem",
}}
>
<span>© 2021 Company Name</span>
<span style={{ padding: "0 4px" }}>•</span>
<Link sx={{ color: "inherit" }} href="/privacy">
Privacy
</Link>
<span style={{ padding: "0 4px" }}>•</span>
<Link sx={{ color: "inherit" }} href="/terms">
Terms
</Link>
</MenuItem>
</Menu>
);
}