-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVirtoAppLayout.tsx
155 lines (147 loc) · 4.15 KB
/
VirtoAppLayout.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
import { Box, CssBaseline, Drawer, Hidden } from "@mui/material";
import React, { Fragment, useState } from "react";
import { ConfirmProvider } from "../ConfirmProvider";
import Sidebar from "../Sidebar";
import { SnackbarProvider } from "../SnackbarProvider";
import ThemeProvider from "../ThemeProvider";
import VirtoAppHeader from "../VirtoAppHeader";
import { VirtoAppLayoutProps } from "./VirtoAppLayout.types";
import useTheme from "../ThemeProvider/useTheme";
// app layout component
function Layout({
appVersion,
baseUrl,
sidebarContent,
virtoLogoLinkUrl = "",
appName,
onChangePassword,
onLogout,
username,
content
}: VirtoAppLayoutProps) {
// sidebar styling
const sidebarWidth = 240;
// define state for managing dynamic sidebar
const [mobileOpen, setMobileOpen] = useState(false);
const [appOpen, setAppOpen] = useState(false);
// use theme context hook
const [theme, setTheme] = useTheme();
return (
<Fragment>
<Box height="100vh" display="flex">
<CssBaseline />
<VirtoAppHeader
appName={appName}
onMenuClick={() => setMobileOpen(!mobileOpen)}
onAppClick={() => setAppOpen(!appOpen)}
onChangePassword={onChangePassword}
onLogout={onLogout}
onColourModeChange={newMode => setTheme(newMode)}
username={username}
mode={theme as "light" | "dark"}
baseUrl={baseUrl}
virtoLogoLinkUrl={virtoLogoLinkUrl}
/>
<Box
sx={theme => ({
[theme.breakpoints.up("md")]: {
flexShrink: 0,
width: sidebarWidth
}
})}
>
<Hidden mdUp>
<Drawer
variant="temporary"
anchor="left"
open={mobileOpen}
onClose={() => setMobileOpen(false)}
sx={{
"& .MuiDrawer-paper": {
height: `calc(100% - 64px)`,
paddingTop: "8px",
top: "64px",
width: sidebarWidth
}
}}
>
<Sidebar appVersion={appVersion}>{sidebarContent}</Sidebar>
</Drawer>
</Hidden>
<Hidden mdDown>
<Drawer
sx={{
"& .MuiDrawer-paper": {
height: `calc(100% - 64px)`,
paddingTop: "8px",
top: "64px",
width: sidebarWidth
}
}}
variant="permanent"
open
>
<Sidebar appVersion={appVersion}>{sidebarContent}</Sidebar>
</Drawer>
</Hidden>
</Box>
<Box
flexGrow={1}
display="flex"
flexDirection="column"
sx={{
background: theme => theme.palette.background.default
}}
>
<Box sx={theme => theme.mixins.toolbar} />
<Box
id="virto-app-layout-page-content"
sx={theme => ({
height: `calc(100vh - ${theme.mixins.toolbar.minHeight}px)`,
overflow: "auto",
[theme.breakpoints.down("md")]: {
width: "100vw"
},
[theme.breakpoints.up("md")]: {
width: `calc(100vw - ${sidebarWidth}px)`
}
})}
>
<SnackbarProvider>{content}</SnackbarProvider>
</Box>
</Box>
</Box>
</Fragment>
);
}
// app layout wrapper component
function VirtoAppLayout({
appVersion,
baseUrl,
sidebarContent,
virtoLogoLinkUrl = "",
appName,
onChangePassword,
onLogout,
username,
content
}: VirtoAppLayoutProps) {
return (
<ThemeProvider>
<ConfirmProvider>
<Layout
appVersion={appVersion}
baseUrl={baseUrl}
sidebarContent={sidebarContent}
virtoLogoLinkUrl={virtoLogoLinkUrl}
appName={appName}
onChangePassword={onChangePassword}
onLogout={onLogout}
username={username}
content={content}
/>
</ConfirmProvider>
</ThemeProvider>
);
}
export default VirtoAppLayout;