-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnavbar.js
More file actions
110 lines (106 loc) · 2.65 KB
/
Copy pathnavbar.js
File metadata and controls
110 lines (106 loc) · 2.65 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
/* eslint-disable import/no-extraneous-dependencies */
import React, { useState, useEffect } from "react";
import { NavLink, useHistory } from "react-router-dom";
import SideDrawer from "../SideDrawer/SideDrawer";
import {
NavBg,
NavWrapper,
Logo,
NavLinksList,
NavLinkItem,
Hamburger,
Line,
} from "./navbar.style";
import logo from "../../static/logo.svg";
const links = [
{
title: "Getting Started",
link: "/",
},
{
title: "Demo",
link: "/demo",
},
{
title: "About",
link: "/about",
},
{
title: "Github",
link: "https://github.com/opensource9ja/dnotebook-react",
},
];
export default function NavBar() {
const history = useHistory();
const { pathname } = history.location;
const [openDrawer, setOpenDrawer] = useState(false);
const [active, setActive] = useState("/");
const handleDrawer = () => {
setOpenDrawer(() => !openDrawer);
};
useEffect(() => {
if (pathname === "/") {
setActive("/");
}
if (pathname.includes("demo")) {
setActive("/demo");
}
if (pathname.includes("about")) {
setActive("/about");
}
}, [pathname]);
return (
<>
<NavBg>
<NavWrapper>
<Logo>
<NavLink
style={{
display: "flex",
alignItems: "center",
}}
to="/"
>
<img
style={{
borderRadius: "5px",
}}
width="35px"
src={logo}
alt="dnotebook-logo"
/>{" "}
<span style={{ marginLeft: "10px" }}>notebook</span>
</NavLink>
</Logo>
<NavLinksList>
{links.map((item, idx) => (
<NavLinkItem key={`NavLink${idx}`}>
{item.link.includes(":") ? (
<a href={item.link}>{item.title}</a>
) : (
<NavLink onClick={() => setActive(item.link)} to={item.link}>
{active === item.link ? (
<div
style={{
color: " #ffdf28",
}}
>
{item.title}
</div>
) : (
<div>{item.title}</div>
)}
</NavLink>
)}
</NavLinkItem>
))}
</NavLinksList>
<Hamburger onClick={handleDrawer} openDrawer={openDrawer}>
<Line />
</Hamburger>
</NavWrapper>
</NavBg>
{openDrawer && <SideDrawer />}
</>
);
}