-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathNav.tsx
63 lines (59 loc) · 1.62 KB
/
Nav.tsx
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
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
import { ComponentChildren } from "preact";
import { NavOverflow } from "./NavOverflow.tsx";
export interface NavProps {
children?: ComponentChildren;
noTopMargin?: boolean;
}
export function Nav(props: NavProps) {
return (
<nav
class={`${
props.noTopMargin ? "" : "mt-3"
} border-b border-jsr-cyan-300/30 max-w-full flex justify-between overflow-x-auto items-end`}
>
<style
dangerouslySetInnerHTML={{
__html:
"nav:has(#nav-items[data-unattached]) { visibility: hidden; }",
}}
/>
<noscript>
<style
dangerouslySetInnerHTML={{
__html:
"nav:has(#nav-items[data-unattached]) { visibility: visible !important }",
}}
/>
</noscript>
<ul
id="nav-items"
data-unattached
class="flex flex-row *:border-b-0 *:rounded-b-none"
>
{props.children}
</ul>
<NavOverflow />
</nav>
);
}
export interface NavItemProps {
href: string;
active?: boolean;
children?: ComponentChildren;
}
export function NavItem(props: NavItemProps) {
return (
<a
class={`md:px-3 px-4 py-2 text-sm md:text-base min-h-10 leading-none rounded-md hover:bg-jsr-cyan-100 hover:dark:bg-jsr-cyan-600 flex items-center select-none ${
props.active
? "bg-jsr-cyan-50 dark:bg-jsr-cyan-500 border-1 border-jsr-cyan-300/30 font-semibold"
: ""
}`}
data-active={props.active ? "true" : undefined}
href={props.href}
>
{props.children}
</a>
);
}