Skip to content

Commit ef98892

Browse files
committed
feat: add app/pages & version switcher
1 parent a223351 commit ef98892

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

apps/docs/src/components/layout.tsx

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
'use client';
22

33
import { useBaseOptions } from '@/hooks/useLayoutOptions';
4+
import { parseDocId } from '@/lib/utils';
5+
import {
6+
NextAppIcon,
7+
NextLastedVersionIcon,
8+
NextOldVersionIcon,
9+
NextPagesIcon,
10+
} from '@/mdx/Icon';
411
import type { PageTree } from 'fumadocs-core/server';
12+
import { RootToggle } from 'fumadocs-ui/components/layout/root-toggle';
513
import {
614
type DocsLayoutProps,
715
DocsLayout as FumaDocsLayout,
8-
} from 'fumadocs-ui/layouts/docs';
16+
} from 'fumadocs-ui/layouts/notebook';
917
import type { ReactNode } from 'react';
1018

1119
export function DocsLayout({
@@ -18,10 +26,57 @@ export function DocsLayout({
1826
docId: string;
1927
}) {
2028
const baseOptions = useBaseOptions();
29+
const { appDocsRoot, pagesDocsRoot, docsRoot } = parseDocId(docId);
30+
2131
const docsLayout: DocsLayoutProps = {
2232
...baseOptions,
33+
links: [],
2334
tree: pageTree,
24-
sidebar: {},
35+
sidebar: {
36+
banner: (
37+
<>
38+
<RootToggle
39+
options={[
40+
{
41+
title: 'Using App Router',
42+
description: 'Features available in /app',
43+
icon: <NextAppIcon />,
44+
url: appDocsRoot,
45+
urls: new Set([docsRoot, appDocsRoot]),
46+
},
47+
{
48+
title: 'Using Pages Router',
49+
description: 'Features available in /pages',
50+
icon: <NextPagesIcon />,
51+
url: pagesDocsRoot,
52+
},
53+
]}
54+
/>
55+
<RootToggle
56+
options={[
57+
{
58+
title: 'Using Latest Version',
59+
description: '15.3.2',
60+
icon: <NextLastedVersionIcon />,
61+
url: '/docs/',
62+
},
63+
{
64+
title: 'Using Version 14',
65+
description: '14.2.29',
66+
icon: <NextOldVersionIcon />,
67+
url: '/docs/14',
68+
},
69+
{
70+
title: 'Using Version 13',
71+
description: '13.5.11',
72+
icon: <NextOldVersionIcon />,
73+
url: '/docs/13',
74+
},
75+
]}
76+
/>
77+
</>
78+
),
79+
},
2580
};
2681

2782
return <FumaDocsLayout {...docsLayout}>{children}</FumaDocsLayout>;

apps/docs/src/mdx/Icon.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,39 @@ export const NextPagesIcon = () => (
3535
/>
3636
</svg>
3737
);
38+
39+
export const NextLastedVersionIcon = () => (
40+
<svg
41+
height="16"
42+
stroke-linejoin="round"
43+
style={{ color: 'currentColor' }}
44+
viewBox="0 0 16 16"
45+
width="16"
46+
>
47+
<title>Next.js Latest Version Icon</title>
48+
<path
49+
fillRule="evenodd"
50+
clipRule="evenodd"
51+
d="M1.5 1.5H6.34315C7.00619 1.5 7.64207 1.76339 8.11091 2.23223L13.8787 8L8 13.8787L2.23223 8.11091C1.76339 7.64207 1.5 7.00619 1.5 6.34315V1.5ZM16 8L14.9393 6.93934L9.17157 1.17157C8.42143 0.421427 7.40401 0 6.34315 0H1.5H0V1.5V6.34315C0 7.40401 0.421426 8.42143 1.17157 9.17157L6.93934 14.9393L8 16L9.06066 14.9393L14.9393 9.06066L16 8ZM4.5 5.25C4.91421 5.25 5.25 4.91421 5.25 4.5C5.25 4.08579 4.91421 3.75 4.5 3.75C4.08579 3.75 3.75 4.08579 3.75 4.5C3.75 4.91421 4.08579 5.25 4.5 5.25Z"
52+
fill="currentColor"
53+
/>
54+
</svg>
55+
);
56+
57+
export const NextOldVersionIcon = () => (
58+
<svg
59+
height="16"
60+
strokeLinejoin="round"
61+
viewBox="0 0 16 16"
62+
width="16"
63+
style={{ color: 'currentcolor' }}
64+
>
65+
<title>Next.js Old Version Icon</title>
66+
<path
67+
fillRule="evenodd"
68+
clipRule="evenodd"
69+
d="M1.5 3.5H14.5V5.5H13.5H2.5H1.5V3.5ZM1 7H0V5.5V3.5V2H1.5H14.5H16V3.5V5.5V7H15V12.5C15 13.8807 13.8807 15 12.5 15H3.5C2.11929 15 1 13.8807 1 12.5V7ZM2.5 7V12.5C2.5 13.0523 2.94772 13.5 3.5 13.5H12.5C13.0523 13.5 13.5 13.0523 13.5 12.5V7H2.5ZM6 9.5H6.75H9.25H10V11H9.25H6.75H6V9.5Z"
70+
fill="currentColor"
71+
/>
72+
</svg>
73+
);

0 commit comments

Comments
 (0)