-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathNavigation.tsx
92 lines (90 loc) · 2.33 KB
/
Navigation.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
import Link from "next/link";
import { useRouter } from "next/router";
import Burger from "./Burger";
import { useState } from "react";
export default function Navigation() {
const router = useRouter();
const [active, setActive] = useState(false);
return (
<>
<Burger active={active} onClick={() => setActive(!active)} />
<div className={"container " + (active ? "active" : "")}>
<ul>
<li>
<Link href="/">
<a className={router.pathname === "/" ? "active" : null}>about</a>
</Link>
</li>
<li>
<Link href="/posts">
<a
className={
router.pathname.startsWith("/posts") ? "active" : null
}
>
blog
</a>
</Link>
</li>
</ul>
<style jsx>
{`
.container {
width: 0;
}
ul {
opacity: 0;
width: 100%;
height: 100vh;
text-align: right;
list-style: none;
margin: 0;
padding: 0;
position: fixed;
top: 0;
background-color: #fff;
display: flex;
flex-direction: column;
justify-content: center;
z-index: 1;
transform: translateY(100%);
transition: opacity 200ms;
}
.active ul {
opacity: 1;
transform: translateY(0);
}
li {
margin-bottom: 1.75rem;
font-size: 2rem;
padding: 0 1.5rem 0 0;
}
li:last-child {
margin-bottom: 0;
}
.active {
color: #222;
}
@media (min-width: 769px) {
.container {
width: 7rem;
display: block;
}
ul {
opacity: 1;
width: 7rem;
top: auto;
display: block;
transform: translateY(0);
}
li {
font-size: 1rem;
padding: 0;
}
}
`}
</style>
</div>
</>
);
}