From 9fdb0d5b01e4e02c510eb30e4dae91c87b610347 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 4 Oct 2023 14:34:42 +0200 Subject: [PATCH] docs: use builtin active link detection (#1850) --- www/components/DocsSidebar.tsx | 28 ++++++++++++---------------- www/components/NavigationBar.tsx | 4 +--- www/routes/docs/[...slug].tsx | 14 ++++++-------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/www/components/DocsSidebar.tsx b/www/components/DocsSidebar.tsx index 4583496d..4832ea7c 100644 --- a/www/components/DocsSidebar.tsx +++ b/www/components/DocsSidebar.tsx @@ -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( ); } -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 (
  • - + {title} {entries.length > 0 && ( )} @@ -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 (
  • - {title} + + {title} +
  • ); } diff --git a/www/components/NavigationBar.tsx b/www/components/NavigationBar.tsx index 8104684c..f346e167 100644 --- a/www/components/NavigationBar.tsx +++ b/www/components/NavigationBar.tsx @@ -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} diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 3994c669..406f406f 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -157,17 +157,17 @@ export default function DocsPage(props: PageProps) {
    -
    +
    ); } -function Main(props: { path: string; page: Page }) { +function Main(props: { page: Page }) { return (
    - +
    - +
    ); } -function MobileSidebar(props: { path: string; page: Page }) { +function MobileSidebar(props: { page: Page }) { return ( <> @@ -231,11 +230,10 @@ function MobileSidebar(props: { path: string; page: Page }) { ); } -function DesktopSidebar(props: { path: string; page: Page }) { +function DesktopSidebar(props: { page: Page }) { return (