docs: use builtin active link detection (#1850)

This commit is contained in:
Marvin Hagemeister
2023-10-04 14:34:42 +02:00
committed by GitHub
parent 3e1b78736d
commit 9fdb0d5b01
3 changed files with 19 additions and 27 deletions
+12 -16
View File
@@ -9,7 +9,6 @@ import { type VersionLink } from "../routes/docs/[...slug].tsx";
export default function DocsSidebar(
props: {
path: string;
mobile?: boolean;
versionLinks: VersionLink[];
selectedVersion: string;
@@ -63,33 +62,30 @@ export default function DocsSidebar(
<ul class="list-inside font-semibold nested ml-2.5">
{CATEGORIES[props.selectedVersion].map((category) => (
<SidebarCategory path={props.path} category={category} />
<SidebarCategory key={category.href} category={category} />
))}
</ul>
</>
);
}
const link = "text(gray-900 hover:gray-600)";
const linkActive = "text-green-700 hover:underline font-bold";
export function SidebarCategory(props: {
path: string;
category: TableOfContentsCategory;
}) {
const { title, href, entries } = props.category;
const outerLink = `${href == props.path ? linkActive : link} font-bold`;
return (
<li class="my-2 block">
<a href={href} class={outerLink}>
<a
href={href}
class="text(gray-900 hover:gray-600) [data-current]:text-green-700 [data-current]:hover:underline font-bold"
>
{title}
</a>
{entries.length > 0 && (
<ul class="py-2 pl-4 nested list-outside">
{entries.map((entry) => (
<SidebarEntry path={props.path} entry={entry} />
<SidebarEntry key={entry.href} entry={entry} />
))}
</ul>
)}
@@ -98,18 +94,18 @@ export function SidebarCategory(props: {
}
export function SidebarEntry(props: {
path: string;
entry: TableOfContentsCategoryEntry;
}) {
const { title, href } = props.entry;
const innerLink = `${
href == props.path ? linkActive : link
} transition-colors hover:text-green-500 font-normal`;
return (
<li class="py-0.5">
<a href={href} class={innerLink}>{title}</a>
<a
href={href}
class="[data-current]:text-green-700 transition-colors hover:text-green-500 font-normal"
>
{title}
</a>
</li>
);
}
+1 -3
View File
@@ -31,9 +31,7 @@ export default function NavigationBar(
href={item.href}
class={`p-2 ${
isHome ? "text-green-900" : "text-gray-600"
} hover:underline ${
props.active == item.href ? "font-bold" : ""
}`}
} hover:underline [data-current]:font-bold [data-ancestor]:font-bold`}
>
{item.name}
</a>