Skip to content

Commit 7a5a7c8

Browse files
sidebar links prototype
1 parent d369b42 commit 7a5a7c8

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

app/docs/SidebarItem.tsx

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"use client";
2+
3+
import { CratesIoLogo, NpmLogo } from "@/lib/logos";
4+
import { type SidebarComponents } from "fumadocs-ui/layouts/docs/shared";
5+
import { SidebarItem } from "fumadocs-ui/layouts/docs/sidebar";
6+
7+
export const components: Partial<SidebarComponents> = {
8+
Item: ({ item }) => {
9+
// TODO: generalise this and configure it for all revelant links
10+
if (item.url === "/docs/rspc/client/vanilla") {
11+
return (
12+
<div className="flex w-full">
13+
<SidebarItem
14+
key={item.url}
15+
href={item.url}
16+
external={item.external}
17+
icon={item.icon}
18+
className="w-full"
19+
>
20+
{item.name}
21+
</SidebarItem>
22+
<SidebarItem
23+
key={item.url + "-npm"}
24+
href="https://www.npmjs.com/package/@rspc/client"
25+
external={item.external}
26+
className="ml-1"
27+
>
28+
<NpmLogo />
29+
</SidebarItem>
30+
</div>
31+
);
32+
} else if (item.url === "/docs/rspc/client/rust") {
33+
return (
34+
<div className="flex w-full">
35+
<SidebarItem
36+
key={item.url}
37+
href={item.url}
38+
external={item.external}
39+
icon={item.icon}
40+
className="w-full"
41+
>
42+
{item.name}
43+
</SidebarItem>
44+
<SidebarItem
45+
key={item.url + "-npm"}
46+
href="https://docs.rs/rspc"
47+
external={item.external}
48+
className="ml-1"
49+
>
50+
<CratesIoLogo />
51+
</SidebarItem>
52+
</div>
53+
);
54+
}
55+
56+
return (
57+
<SidebarItem
58+
key={item.url}
59+
href={item.url}
60+
external={item.external}
61+
icon={item.icon}
62+
>
63+
{item.name}
64+
</SidebarItem>
65+
);
66+
},
67+
};

app/docs/layout.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import { DocsLayout } from "fumadocs-ui/layouts/docs";
22
import type { ReactNode } from "react";
33
import { baseOptions } from "@/app/layout.config";
44
import { source } from "@/lib/source";
5+
import { components } from "./SidebarItem";
56

67
export default function Layout({ children }: { children: ReactNode }) {
78
return (
8-
<DocsLayout tree={source.pageTree} {...baseOptions}>
9+
<DocsLayout
10+
tree={source.pageTree}
11+
{...baseOptions}
12+
sidebar={{
13+
components,
14+
}}
15+
>
916
{children}
1017
</DocsLayout>
1118
);

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
"postcss": "^8.4.49",
2929
"tailwindcss": "^3.4.16",
3030
"typescript": "^5.7.2"
31+
},
32+
"pnpm": {
33+
"patchedDependencies": {
34+
"fumadocs-ui": "patches/fumadocs-ui.patch"
35+
}
3136
}
3237
}

patches/fumadocs-ui.patch

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/dist/layouts/docs/sidebar.js b/dist/layouts/docs/sidebar.js
2+
index ab856d6e6a1e17f6c26fcf9b77c8e106761214c3..983a27c6a60ff3b24aba3e92a7548d52aa1c91b3 100644
3+
--- a/dist/layouts/docs/sidebar.js
4+
+++ b/dist/layouts/docs/sidebar.js
5+
@@ -85,7 +85,7 @@ export function SidebarItem({ icon, ...props }) {
6+
const pathname = usePathname();
7+
const active = props.href !== undefined && isActive(props.href, pathname, false);
8+
const { prefetch } = useInternalContext();
9+
- return (_jsxs(Link, { ...props, "data-active": active, className: cn(itemVariants({ active })), prefetch: prefetch, children: [icon ?? (props.external ? _jsx(ExternalLink, {}) : null), props.children] }));
10+
+ return (_jsxs(Link, { ...props, "data-active": active, className: cn(itemVariants({ active }), props.className), prefetch: prefetch, children: [icon ?? (props.external ? _jsx(ExternalLink, {}) : null), props.children] }));
11+
}
12+
export function SidebarFolder({ defaultOpen = false, ...props }) {
13+
const [open, setOpen] = useState(defaultOpen);

pnpm-lock.yaml

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)