Open History to see the last commit
1import * as React from 'react'
2import Link from 'next/link'
3import { useRouter } from 'next/router'
4import cn from 'classnames'
5export function SidebarNavLink({
6 route: { href, pathname, title, selected },
7 onClick,
8}) {
9 const router = useRouter()
10 const onlyHashChange = pathname === router.pathname
11β
12 return (
13 <div
14 className={cn('nav-link', {
15 selected,
16 })}
17 >
18 {
19 // NOTE: use just anchor element for triggering `hashchange` event
20 onlyHashChange ? (
21 <a className={selected ? 'selected' : ''} href={pathname}>
22 {title}
23 </a>
24 ) : (
25 <Link href={href} as={pathname}>
26 <a>{title}</a>
27 </Link>
28 )
29 }
30 <style jsx>{`
31 div.selected {
32 box-sizing: border-box;
33 }
34 .nav-link {
35 display: flex;
36 width: 100%;
37 }
38 .nav-link :global(a) {
39 text-decoration: none;
40 font-size: 1rem;
41 line-height: 1.5rem;
42 color: #4b5563;
43 width: 100%;
44 box-sizing: border-box;
45 }
46 .selected :global(a) {
47 font-weight: 600;
48 color: #161e2e;
49 }
50 .nav-link:hover :global(a) {
51 color: #161e2e;
52 }
53 span {
54 color: #a0aec0;
55 }
56 @media screen and (max-width: 950px) {
57 div {
58 padding-top: 0;
59 padding-left: 0;
60 padding-bottom: 0;
61 }
62 div.selected {
63 border-left: none;
64 padding-left: 0;
65 }
66 .nav-link :global(a) {
67 display: flex;
68 align-items: center;
69 }
70 }
71 `}</style>
72 </div>
73 )
74}
75SidebarNavLink.displayName = 'SidebarNavLink'