on master help sign in
route-sensitive header
commitb16481674f4388387d7a8e6af29f81c0aebf8318 authorGavin Atkinson <gvnatknsn@protonmail.com> dateTue 15 Jun 2021, 12:48 (5 years ago) parentf4d5447
4 files changed+36−7
components/Header.js+33−4 styles/globals.css+2−2 styles/markdown.module.css−1 tailwind.config.js+1
components/Header.js+33−4
@@ -1,15 +1,44 @@
11import Link from 'next/link'
2+import { useRouter } from 'next/router'
3+import classnames from 'classnames'
4+import path from 'path'
5+
6+function ActiveLink({ children, href, className }) {
7+ const router = useRouter()
8+
9+ const firstCrumb = router.asPath.split('/')[1]
10+
11+ const activeClassName = classnames({
12+ 'text-black': '/' + firstCrumb === href,
13+ 'text-gray': '/' + firstCrumb !== href,
14+ })
15+
16+ return (
17+ <Link href={href}><a className={className + ' ' + activeClassName}>
18+ {children}
19+ </a></Link>
20+ )
21+ }
222
323export default function Header() {
24+ const router = useRouter()
25+
426 return (
527 <header className="layout-wide flex justify-between items-center pt-8">
628 <Link href="/"><a className="type-ui">Urbit</a></Link>
729 <nav className="flex items-center">
8− <Link href="/docs"><a className="type-ui text-gray mr-6">Docs</a></Link>
9− <Link href="/blog"><a className="type-ui text-gray mr-6">Blog</a></Link>
10− <Link href="/events"><a className="type-ui text-gray mr-6">Events</a></Link>
11− <button className="button-sm bg-green">Download Port</button>
30+ <ActiveLink className="mr-4 type-ui" href="/docs">Docs</ActiveLink>
31+ <ActiveLink className="mr-4 type-ui" href="/blog">Blog</ActiveLink>
32+ <ActiveLink className="mr-4 type-ui" href="/events">Events</ActiveLink>
33+ {
34+ router.asPath === '/'
35+ ? <button className="button-sm bg-green">Download Port</button>
36+ : <button className="button-sm bg-wall text-gray">Search Urbit.org<div className="ml-4 text-lightGray">⌘K</div></button>
37+ }
1238 </nav>
1339 </header>
1440 )
41+
1542}
43+
44+
styles/globals.css+2−2
@@ -62,12 +62,12 @@ h3, .type-h3 {
6262 }
6363
6464 .button-sm {
65− @apply flex px-4 py-1 rounded text-white type-ui;
65+ @apply flex px-4 py-1 rounded type-ui;
6666 border:none;
6767 }
6868
6969 .button-lg {
70− @apply flex px-6 py-2 rounded-lg text-white h-16 flex-center type-ui;
70+ @apply flex px-6 py-2 rounded-lg h-16 flex-center type-ui;
7171 border:none;
7272 }
7373
styles/markdown.module.css−1
@@ -31,7 +31,6 @@
3131 line-height: 32px;
3232 letter-spacing: -0.011em;
3333 text-align: left;
34−
3534 }
3635
3736 .markdown img {
tailwind.config.js+1
@@ -6,6 +6,7 @@ module.exports = {
66 black: '#000',
77 white: '#FFF',
88 gray: 'rgba(0, 0, 0, 0.6)',
9+ lightGray: 'rgba(0, 0, 0, 0.2)',
910 wall: 'rgba(244, 243, 241, 1)',
1011 yellow: '#FCDB63',
1112 midYellow: 'rgba(255, 199, 0, 0.6)',