-
Notifications
You must be signed in to change notification settings - Fork 3
/
Navigation.tsx
51 lines (46 loc) · 1.52 KB
/
Navigation.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
/* @jsx preact.h */
/* @jsxFrag preact.Fragment */
import * as preact from 'preact';
import { cx } from '../dep/frugal/styled.ts';
import { usePathname } from '../dep/frugal/frugal_preact.server.ts';
import * as s from './Navigation.style.ts';
export function Navigation() {
const pathname = usePathname();
const isHome = pathname === '/';
const isDocs = pathname.startsWith('/docs');
const isExample = pathname.startsWith('/example');
return (
<div class={cx(s.wrapper)}>
<nav class={cx(s.navigation)}>
<NavigationEntry active={isHome} href='/'>
Home
</NavigationEntry>
<NavigationEntry active={isDocs} href='/docs'>
Docs
</NavigationEntry>
<NavigationEntry active={isExample} href='/example'>
Example
</NavigationEntry>
<NavigationEntry
active={false}
href='https://github.com/PaulBlanche/frugal'
>
Github ⧉
</NavigationEntry>
</nav>
</div>
);
}
type NavigationEntryProps = {
children: preact.ComponentChildren;
active?: boolean;
href?: string;
};
function NavigationEntry(
{ active = false, children, href }: NavigationEntryProps,
) {
if (active) {
return <span class={cx(s.entry, s.entryActive)}>{children}</span>;
}
return <a class={cx(s.entry)} href={href}>{children}</a>;
}