-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathNavMenu.tsx
More file actions
51 lines (48 loc) · 1.54 KB
/
NavMenu.tsx
File metadata and controls
51 lines (48 loc) · 1.54 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
import { type RefProps } from "@solid-primitives/refs";
import { type Component, For } from "solid-js";
import { scrollIntoView } from "~/utils.js";
import { useLocation } from "@tanstack/solid-router";
const NavMenu: Component<RefProps<HTMLDivElement> & { onClose: () => void }> = props => {
const location = useLocation();
const list = [
"Primitives",
"Contribution Process",
"Philosophy",
"Design Maxims",
"Basic and Compound Primitives",
"Managing Primitive Complexity",
];
return (
<div ref={props.ref}>
<div class="mx-4 my-1 border-b-2 border-slate-200 dark:border-slate-600" />
<div class="p-4">
<ul class="flex flex-col text-lg">
<For each={list}>
{item => {
const hashName = item.replace(/\s/g, "-").toLowerCase();
const href = `#${hashName}`;
return (
<li>
<a
class="block py-2 font-semibold"
href={href}
onClick={() => {
if (location().hash === hashName) {
const anchor = document.querySelector(`a[href="${href}"]`)!;
scrollIntoView(anchor, { offset: 70, behavior: "auto" });
props.onClose();
}
}}
>
{item}
</a>
</li>
);
}}
</For>
</ul>
</div>
</div>
);
};
export default NavMenu;