Repository navigation
Expand file tree
/
Copy pathSidebarNavLink.js
More file actions
75 lines (74 loc) · 1.74 KB
/
Copy pathSidebarNavLink.js
File metadata and controls
75 lines (74 loc) · 1.74 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
import * as React from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import cn from 'classnames'
export function SidebarNavLink({
route: { href, pathname, title, selected },
onClick,
}) {
const router = useRouter()
const onlyHashChange = pathname === router.pathname
return (
<div
className={cn('nav-link', {
selected,
})}
>
{
// NOTE: use just anchor element for triggering `hashchange` event
onlyHashChange ? (
<a className={selected ? 'selected' : ''} href={pathname}>
{title}
</a>
) : (
<Link href={href} as={pathname}>
<a>{title}</a>
</Link>
)
}
<style jsx>{`
div.selected {
box-sizing: border-box;
}
.nav-link {
display: flex;
width: 100%;
}
.nav-link :global(a) {
text-decoration: none;
font-size: 1rem;
line-height: 1.5rem;
color: #4b5563;
width: 100%;
box-sizing: border-box;
}
.selected :global(a) {
font-weight: 600;
color: #161e2e;
}
.nav-link:hover :global(a) {
color: #161e2e;
}
span {
color: #a0aec0;
}
@media screen and (max-width: 950px) {
div {
padding-top: 0;
padding-left: 0;
padding-bottom: 0;
}
div.selected {
border-left: none;
padding-left: 0;
}
.nav-link :global(a) {
display: flex;
align-items: center;
}
}
`}</style>
</div>
)
}
SidebarNavLink.displayName = 'SidebarNavLink'