-
Notifications
You must be signed in to change notification settings - Fork 3
/
VirtoAppHeader.tsx
204 lines (197 loc) · 5.01 KB
/
VirtoAppHeader.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import {
AppBar,
Box,
Drawer,
IconButton,
Link,
Toolbar,
Typography
} from "@mui/material";
import React, { Fragment, useState } from "react";
import AppLauncher from "../AppLauncher";
import AppsIcon from "@mui/icons-material/Apps";
import Menu from "@mui/icons-material/Menu";
import ToggleColorMode from "../ToggleColorMode";
import UserMenu from "../UserMenu";
import { VirtoAppHeaderProps } from "./VirtoAppHeader.types";
import VirtoLogo from "../SvgIcons/VirtoLogo";
// appbar component
function Header({
appName,
mode,
onAppClick,
onColourModeChange,
onChangePassword,
onLogout,
onMenuClick,
username,
virtoLogoLinkUrl
}: VirtoAppHeaderProps) {
return (
<AppBar
sx={theme => ({
backgroundColor: theme.palette.primary.main
})}
>
<Toolbar style={{ justifyContent: "space-between" }}>
<Box
sx={{
alignItems: "center",
display: "flex"
}}
>
<IconButton sx={{ pl: 0 }} onClick={onAppClick} disableRipple>
<AppsIcon
sx={theme => ({
color: theme.palette.background.paper,
fontSize: "30px"
})}
/>
</IconButton>
<IconButton
disableRipple
color="inherit"
data-testid="launcher-button"
edge="start"
onClick={onMenuClick}
sx={theme => ({
pl: 2.5,
[theme.breakpoints.up("md")]: {
display: "none"
}
})}
size="large"
>
<Menu
sx={theme => ({
color: theme.palette.background.paper,
fontSize: "30px"
})}
/>
</IconButton>
<Box
sx={{
alignItems: "center",
display: "flex",
ml: 1
}}
>
<Link
href={virtoLogoLinkUrl}
underline="none"
sx={{
display: "flex"
}}
>
<VirtoLogo
data-testid="virto-logo"
sx={theme => ({
color: "white",
height: 22,
mr: 0.4,
width: 110,
...theme.applyStyles("dark", {
color: "#003063"
})
})}
/>
</Link>
<Typography
variant="h6"
sx={[
{
fontSize: "28px",
fontWeight: "700",
letterSpacing: "0.05em",
lineHeight: "34px",
textTransform: "uppercase"
},
theme => ({
color: "white",
...theme.applyStyles("dark", {
color: "#003063"
})
})
]}
>
{`.`}
<span style={{ marginLeft: "7px" }}>{appName}</span>
</Typography>
</Box>
</Box>
<Box
sx={{
alignItems: "center",
display: "flex"
}}
>
<ToggleColorMode mode={mode} onChange={onColourModeChange} />
<UserMenu
username={username}
onChangePassword={onChangePassword}
onLogout={onLogout}
/>
</Box>
</Toolbar>
</AppBar>
);
}
// app header component
function VirtoAppHeader({
appName,
baseUrl,
mode,
onChangePassword,
onLogout,
onMenuClick,
onColourModeChange,
username,
virtoLogoLinkUrl = ""
}: VirtoAppHeaderProps) {
// sidebar styling
const applancherWidth = 300;
// define state for managing app launcher
const [appOpen, setAppOpen] = useState(false);
// handle click event
const handleMenuClick =
(cb: (event: React.MouseEvent<HTMLElement>) => void) =>
(event: React.MouseEvent<HTMLElement>) => {
cb(event);
};
return (
<Fragment>
<Header
appName={appName}
mode={mode}
onAppClick={() => setAppOpen(!appOpen)}
onColourModeChange={onColourModeChange}
onChangePassword={onChangePassword}
onLogout={onLogout}
onMenuClick={handleMenuClick(onMenuClick)}
username={username}
virtoLogoLinkUrl={virtoLogoLinkUrl}
/>
<Drawer
variant="temporary"
anchor="left"
data-testid="app-launcher"
open={appOpen}
onClose={() => setAppOpen(false)}
sx={theme => ({
"& .MuiDrawer-paper": {
height: `calc(100vh - ${theme.mixins.toolbar.minHeight}px)`,
top: theme.mixins.toolbar.minHeight,
width: applancherWidth
}
})}
>
<AppLauncher
baseUrl={baseUrl}
logoLinkUrl={virtoLogoLinkUrl}
onAppButtonClick={() => setAppOpen(false)}
/>
</Drawer>
</Fragment>
);
}
export default VirtoAppHeader;