docs: use builtin active link detection (#1850)
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -157,17 +157,17 @@ export default function DocsPage(props: PageProps<Data>) {
|
||||
</Head>
|
||||
<div class="flex flex-col min-h-screen">
|
||||
<Header title="docs" active="/docs" />
|
||||
<Main path={props.url.pathname} page={props.data.page} />
|
||||
<Main page={props.data.page} />
|
||||
<Footer />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Main(props: { path: string; page: Page }) {
|
||||
function Main(props: { page: Page }) {
|
||||
return (
|
||||
<div class="flex-1">
|
||||
<MobileSidebar path={props.path} page={props.page} />
|
||||
<MobileSidebar page={props.page} />
|
||||
<div class="flex mx-auto max-w-screen-xl px-4 md:px-0 py-5 md:py-0 justify-end">
|
||||
<label
|
||||
for="docs_sidebar"
|
||||
@@ -191,14 +191,14 @@ function Main(props: { path: string; page: Page }) {
|
||||
</label>
|
||||
</div>
|
||||
<div class="mx-auto max-w-screen-xl flex gap-6 md:gap-8">
|
||||
<DesktopSidebar path={props.path} page={props.page} />
|
||||
<DesktopSidebar page={props.page} />
|
||||
<Content page={props.page} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MobileSidebar(props: { path: string; page: Page }) {
|
||||
function MobileSidebar(props: { page: Page }) {
|
||||
return (
|
||||
<>
|
||||
<input
|
||||
@@ -220,7 +220,6 @@ function MobileSidebar(props: { path: string; page: Page }) {
|
||||
<nav class="pt-6 pb-16 px-4 overflow-x-auto">
|
||||
<DocsSidebar
|
||||
mobile
|
||||
path={props.path}
|
||||
versionLinks={props.page.versionLinks}
|
||||
selectedVersion={props.page.version}
|
||||
/>
|
||||
@@ -231,11 +230,10 @@ function MobileSidebar(props: { path: string; page: Page }) {
|
||||
);
|
||||
}
|
||||
|
||||
function DesktopSidebar(props: { path: string; page: Page }) {
|
||||
function DesktopSidebar(props: { page: Page }) {
|
||||
return (
|
||||
<nav class="w-[18rem] flex-shrink-0 hidden md:block py-7 px-4">
|
||||
<DocsSidebar
|
||||
path={props.path}
|
||||
versionLinks={props.page.versionLinks}
|
||||
selectedVersion={props.page.version}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user