on a2fcb7f help sign in
160 lines 4.2 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>
65 <ActiveLink
66 currentPath={currentPath}
67 className="mr-5 type-ui"
68 href="/ecosystem"
69 >
70 Ecosystem
71 </ActiveLink>
73 <ActiveLink
74 currentPath={currentPath}
75 className="mr-5 type-ui"
76 href="/using"
77 >
78 Manual
79 </ActiveLink>
81 <ActiveLink
82 currentPath={currentPath}
83 className="mr-5 type-ui"
84 href="/events"
85 >
86 Events
87 </ActiveLink>
89 <ActiveLink
90 currentPath={currentPath}
91 className="mr-5 type-ui"
92 href="/blog"
93 >
94 Blog
95 </ActiveLink>
96 </nav>
98 {
99 // Small screen header
100 }
101 <MenuTray isOpen={isOpen} setTray={setTray} search={props.search}>
102 <Link href="/" passHref>
103 <a className="font-semibold mb-4">Urbit</a>
104 </Link>
105 <Link href="https://urbit.org" passHref>
106 <a className="font-semibold mt-2">Urbit.org</a>
107 </Link>
108 <Link href="https://operators.urbit.org" passHref>
109 <a className="mt-2">Operators</a>
110 </Link>
111 <Link href="https://developers.urbit.org" passHref>
112 <a className="mt-2 mb-4">Developers</a>
113 </Link>
114 <hr className="border-wall-200" />
115 <ActiveLink
116 currentPath={currentPath}
117 className="mt-4 mr-5 mb-4"
118 href="/overview"
119 >
120 Overview
121 </ActiveLink>
122 <ActiveLink
123 currentPath={currentPath}
124 className="mr-5 mb-4"
125 href="/ecosystem"
126 >
127 Ecosystem
128 </ActiveLink>
129 <ActiveLink
130 currentPath={currentPath}
131 className="mr-5 mb-4"
132 href="/using"
133 >
134 Manual
135 </ActiveLink>
136 <ActiveLink
137 currentPath={currentPath}
138 className="mr-5 mb-4"
139 href="/blog"
140 >
141 Blog
142 </ActiveLink>
143 <ActiveLink
144 currentPath={currentPath}
145 className="mr-5 mb-4"
146 href="/events"
147 >
148 Events
149 </ActiveLink>
150 <ActiveLink
151 currentPath={currentPath}
152 className="mr-5 mb-4 text-green-400"
153 href="/getting-started"
154 >
155 Get Started
156 </ActiveLink>
157 </MenuTray>
158 </header>
159 );