-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathindex.js
More file actions
193 lines (172 loc) · 6.11 KB
/
index.js
File metadata and controls
193 lines (172 loc) · 6.11 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
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
/**
=========================================================
* Soft UI Dashboard React - v4.0.1
=========================================================
* Product Page: https://www.creative-tim.com/product/soft-ui-dashboard-react
* Copyright 2023 Creative Tim (https://www.creative-tim.com)
Coded by www.creative-tim.com
=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
import { useState, useEffect } from "react";
// react-router components
import { Link } from "react-router-dom";
// prop-types is a library for typechecking of props.
import PropTypes from "prop-types";
// @mui material components
import Container from "@mui/material/Container";
import Icon from "@mui/material/Icon";
// Soft UI Dashboard React components
import SoftBox from "components/SoftBox";
import SoftTypography from "components/SoftTypography";
import SoftButton from "components/SoftButton";
// Soft UI Dashboard React examples
import DefaultNavbarLink from "examples/Navbars/DefaultNavbar/DefaultNavbarLink";
import DefaultNavbarMobile from "examples/Navbars/DefaultNavbar/DefaultNavbarMobile";
// Soft UI Dashboard React base styles
import breakpoints from "assets/theme/base/breakpoints";
function DefaultNavbar({ transparent, light, action }) {
const [mobileNavbar, setMobileNavbar] = useState(false);
const [mobileView, setMobileView] = useState(false);
const openMobileNavbar = ({ currentTarget }) => setMobileNavbar(currentTarget.parentNode);
const closeMobileNavbar = () => setMobileNavbar(false);
useEffect(() => {
// A function that sets the display state for the DefaultNavbarMobile.
function displayMobileNavbar() {
if (window.innerWidth < breakpoints.values.lg) {
setMobileView(true);
setMobileNavbar(false);
} else {
setMobileView(false);
setMobileNavbar(false);
}
}
/**
The event listener that's calling the displayMobileNavbar function when
resizing the window.
*/
window.addEventListener("resize", displayMobileNavbar);
// Call the displayMobileNavbar function to set the state with the initial value.
displayMobileNavbar();
// Remove event listener on cleanup
return () => window.removeEventListener("resize", displayMobileNavbar);
}, []);
return (
(<Container>
<SoftBox
py={1.5}
px={{ xs: transparent ? 4 : 5, sm: transparent ? 2 : 5, lg: transparent ? 0 : 5 }}
my={2}
mx={3}
width="calc(100% - 48px)"
borderRadius="section"
shadow={transparent ? "none" : "md"}
color={light ? "white" : "dark"}
display="flex"
justifyContent="space-between"
alignItems="center"
position="absolute"
left={0}
zIndex={3}
sx={({ palette: { transparent: transparentColor, white }, functions: { rgba } }) => ({
backgroundColor: transparent ? transparentColor.main : rgba(white.main, 0.8),
backdropFilter: transparent ? "none" : `saturate(200%) blur(30px)`,
})}
>
<SoftBox component={Link} to="/" py={transparent ? 1.5 : 0.75} lineHeight={1}>
<SoftTypography variant="button" fontWeight="bold" color={light ? "white" : "dark"}>
Soft UI Dashboard
</SoftTypography>
</SoftBox>
<SoftBox color="inherit" display={{ xs: "none", lg: "flex" }} m={0} p={0}>
<DefaultNavbarLink icon="donut_large" name="dashboard" route="/dashboard" light={light} />
<DefaultNavbarLink icon="person" name="profile" route="/profile" light={light} />
<DefaultNavbarLink
icon="account_circle"
name="sign up"
route="/authentication/sign-up"
light={light}
/>
<DefaultNavbarLink
icon="key"
name="sign in"
route="/authentication/sign-in"
light={light}
/>
</SoftBox>
{action &&
(action.type === "internal" ? (
<SoftBox display={{ xs: "none", lg: "inline-block" }}>
<SoftBox
component={Link}
to={action.route}
variant="gradient"
color={action.color ? action.color : 'dark'}
borderRadius="none"
shadow="none"
>
{action.label}
</SoftBox>
</SoftBox>
) : (
<SoftBox display={{ xs: "none", lg: "inline-block" }}>
<SoftButton
component="a"
href={action.route}
target="_blank"
rel="noreferrer"
variant="gradient"
color={action.color ? action.color : "info"}
size="small"
circular
>
{action.label}
</SoftButton>
</SoftBox>
))}
<SoftBox
display={{ xs: "inline-block", lg: "none" }}
lineHeight={0}
py={1.5}
pl={1.5}
color="inherit"
sx={{ cursor: "pointer" }}
onClick={openMobileNavbar}
>
<Icon fontSize="default">{mobileNavbar ? "close" : "menu"}</Icon>
</SoftBox>
</SoftBox>
{mobileView && <DefaultNavbarMobile open={mobileNavbar} close={closeMobileNavbar} />}
</Container>)
);
}
// Setting default values for the props of DefaultNavbar
DefaultNavbar.defaultProps = {
transparent: false,
light: false,
action: false,
};
// Typechecking props for the DefaultNavbar
DefaultNavbar.propTypes = {
transparent: PropTypes.bool,
light: PropTypes.bool,
action: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.shape({
type: PropTypes.oneOf(["external", "internal"]).isRequired,
route: PropTypes.string.isRequired,
color: PropTypes.oneOf([
"primary",
"secondary",
"info",
"success",
"warning",
"error",
"dark",
"light",
]),
label: PropTypes.string.isRequired,
}),
]),
};
export default DefaultNavbar;