Skip to content

Commit 9b45a24

Browse files
authored
Fix navbar link style on sub-routes (#1213)
1 parent b828483 commit 9b45a24

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/ui/layout/main-header.tsx

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Show, createMemo, createSignal, onCleanup, onMount } from "solid-js";
2-
import { A } from "~/ui/i18n-anchor";
2+
import { A, type RouterLinkProps } from "~/ui/i18n-anchor";
33
import { isServer } from "solid-js/web";
44

55
import { Logo, GitHubIcon, DiscordIcon } from "~/ui/logo";
@@ -17,6 +17,26 @@ const ClientSearch = clientOnly(() =>
1717
import("../search").then((m) => ({ default: m.Search }))
1818
);
1919

20+
interface NavLinkProps extends RouterLinkProps {
21+
active?: boolean;
22+
}
23+
24+
function NavLink(props: NavLinkProps) {
25+
return (
26+
<A
27+
class="border-b-2 text-slate-900 dark:text-slate-200 relative overflow-hidden drop-shadow-[0_35px_35px_rgba(1,1,1,1.75)] px-2 transition-all duration-250"
28+
classList={{
29+
"border-b-blue-500 dark:bottom-b-blue-500": props.active,
30+
"border-transparent": !props.active,
31+
}}
32+
addLocale
33+
{...props}
34+
>
35+
{props.children}
36+
</A>
37+
);
38+
}
39+
2040
interface Entry {
2141
title: string;
2242
path: string;
@@ -93,47 +113,30 @@ export function MainHeader(props: NavProps) {
93113

94114
<ul class="order-2 col-span-2 lg:col-span-1 flex pt-6 lg:pt-0 lg:w-auto w-full gap-5 justify-center">
95115
<li>
96-
<A
116+
<NavLink
97117
href="/"
98-
class="text-slate-900 dark:text-slate-200 relative overflow-hidden drop-shadow-[0_35px_35px_rgba(1,1,1,1.75)] px-2"
99-
classList={{
100-
"border-b-2 border-b-blue-500 dark:bottom-b-blue-500 transition-all duration-250":
101-
project() === "solid" && !translatedLocale(),
102-
}}
103-
addLocale
118+
active={project() === "solid" && !translatedLocale()}
104119
>
105120
Core
106-
</A>
121+
</NavLink>
107122
</li>
108123
<li>
109-
<A
124+
<NavLink
110125
href="/solid-router/"
111-
class="text-slate-900 dark:text-slate-200 px-2"
112-
activeClass="border-b-2 border-b-blue-500 dark:bottom-b-blue-500 transition-all duration-250"
113-
addLocale
126+
active={project() === "solid-router"}
114127
>
115128
Router
116-
</A>
129+
</NavLink>
117130
</li>
118131
<li>
119-
<A
120-
href="/solid-start/"
121-
class="text-slate-900 dark:text-slate-200 px-2"
122-
activeClass="border-b-2 border-b-blue-500 dark:bottom-b-blue-500 transition-all duration-250"
123-
addLocale
124-
>
132+
<NavLink href="/solid-start/" active={project() === "solid-start"}>
125133
SolidStart
126-
</A>
134+
</NavLink>
127135
</li>
128136
<li>
129-
<A
130-
href="/solid-meta/"
131-
class="text-slate-900 dark:text-slate-200 px-2"
132-
activeClass="border-b-2 border-b-blue-500 dark:bottom-b-blue-500 transition-all duration-250"
133-
addLocale
134-
>
137+
<NavLink href="/solid-meta/" active={project() === "solid-meta"}>
135138
Meta
136-
</A>
139+
</NavLink>
137140
</li>
138141
</ul>
139142

0 commit comments

Comments
 (0)