on 06bf30c help sign in
146 lines 3.9 kB history raw
1import Link from "next/link";
2import { useRouter } from "next/router";
3import { useState, useEffect } from "react";
4import classnames from "classnames";
5import MenuTray from "../components/MenuTray";
6import { capitalize } from "../lib/lib";
8function ActiveLink({ children, href, className, currentPath }) {
9 const firstCrumb = currentPath.split("/")[1];
11 const activeClassName = classnames({
12 "text-wall-600": "/" + firstCrumb === href,
13 "text-wall-500": "/" + firstCrumb !== href,
14 });
16 return (
17 <Link href={href} passHref>
18 <a className={`${className} ${activeClassName}`}>{children}</a>
19 </Link>
20 );
23export default function Header(props) {
24 const [isOpen, setTray] = useState(false);
26 const currentPath = useRouter().asPath;
28 const routeDepth = currentPath.split("/").length;
30 const firstCrumb = currentPath.split("/")[1];
32 return (
33 <header className="layout px-4 md:px-8 flex justify-between items-center pt-8 md:pt-10 lg:pt-12 pb-10 md:pb-12 lg:pb-24">
34 <div>
35 <Link href="/" passHref>
36 <a className="font-semibold text-lg">Urbit</a>
37 </Link>
38 {routeDepth > 2 ? (
39 <Link href={`/${firstCrumb}`} passHref>
40 <a className="inline md:hidden type-ui text-wall-500 ml-2">
41 {capitalize(firstCrumb)}
42 </a>
43 </Link>
44 ) : null}
45 </div>
46 {
47 // Large screen header
48 }
49 <nav className="items-center hidden md:flex">
50 <ActiveLink
51 currentPath={currentPath}
52 className="mr-5 text-green-400 type-ui button-text"
53 href="/getting-started"
54 >
55 Get Started
56 </ActiveLink>
58 <ActiveLink
59 currentPath={currentPath}
60 className="mr-5 type-ui"
61 href="/overview"
62 >
63 Overview
64 </ActiveLink>
66 <ActiveLink
67 currentPath={currentPath}
68 className="mr-5 type-ui"
69 href="/using"
70 >
71 Manual
72 </ActiveLink>
74 <ActiveLink
75 currentPath={currentPath}
76 className="mr-5 type-ui"
77 href="/events"
78 >
79 Events
80 </ActiveLink>
82 <ActiveLink
83 currentPath={currentPath}
84 className="mr-5 type-ui"
85 href="/blog"
86 >
87 Blog
88 </ActiveLink>
89 </nav>
91 {
92 // Small screen header
93 }
94 <MenuTray isOpen={isOpen} setTray={setTray} search={props.search}>
95 <Link href="/" passHref>
96 <a className="font-semibold mb-4">Urbit</a>
97 </Link>
98 <Link href="https://urbit.org" passHref>
99 <a className="font-semibold mt-2">Urbit.org</a>
100 </Link>
101 <Link href="https://operators.urbit.org" passHref>
102 <a className="mt-2">Operators</a>
103 </Link>
104 <Link href="https://developers.urbit.org" passHref>
105 <a className="mt-2 mb-4">Developers</a>
106 </Link>
107 <hr className="border-wall-200" />
108 <ActiveLink
109 currentPath={currentPath}
110 className="mt-4 mr-5 mb-4"
111 href="/overview"
112 >
113 Overview
114 </ActiveLink>
115 <ActiveLink
116 currentPath={currentPath}
117 className="mr-5 mb-4"
118 href="/using"
119 >
120 Manual
121 </ActiveLink>
122 <ActiveLink
123 currentPath={currentPath}
124 className="mr-5 mb-4"
125 href="/blog"
126 >
127 Blog
128 </ActiveLink>
129 <ActiveLink
130 currentPath={currentPath}
131 className="mr-5 mb-4"
132 href="/events"
133 >
134 Events
135 </ActiveLink>
136 <ActiveLink
137 currentPath={currentPath}
138 className="mr-5 mb-4 text-green-400"
139 href="/getting-started"
140 >
141 Get Started
142 </ActiveLink>
143 </MenuTray>
144 </header>
145 );