diff --git a/.changeset/cool-cameras-smile.md b/.changeset/cool-cameras-smile.md new file mode 100644 index 000000000..725d0b391 --- /dev/null +++ b/.changeset/cool-cameras-smile.md @@ -0,0 +1,5 @@ +--- +'fumadocs-ui': patch +--- + +Support `children` prop in custom `Folder` component diff --git a/apps/docs/source.config.ts b/apps/docs/source.config.ts index 43583ec6a..a5cb918eb 100644 --- a/apps/docs/source.config.ts +++ b/apps/docs/source.config.ts @@ -55,6 +55,8 @@ export default defineConfig({ return { rehypeCodeOptions: { + lazy: true, + langs: ['ts', 'js', 'html'], inline: 'tailing-curly-colon', themes: { light: 'catppuccin-latte', diff --git a/packages/ui/src/layouts/docs/shared.tsx b/packages/ui/src/layouts/docs/shared.tsx index c48609ff3..078331a30 100644 --- a/packages/ui/src/layouts/docs/shared.tsx +++ b/packages/ui/src/layouts/docs/shared.tsx @@ -47,7 +47,7 @@ export interface SidebarOptions extends SidebarProps { export interface SidebarComponents { Item: FC<{ item: PageTree.Item }>; - Folder: FC<{ item: PageTree.Folder; level: number }>; + Folder: FC<{ item: PageTree.Folder; level: number; children: ReactNode }>; Separator: FC<{ item: PageTree.Separator }>; } diff --git a/packages/ui/src/layouts/docs/sidebar.tsx b/packages/ui/src/layouts/docs/sidebar.tsx index f0f3c5cb4..2f441e06c 100644 --- a/packages/ui/src/layouts/docs/sidebar.tsx +++ b/packages/ui/src/layouts/docs/sidebar.tsx @@ -396,35 +396,42 @@ export function SidebarPageTree(props: { ): ReactNode[] { return items.map((item, i) => { const id = `${item.type}_${i.toString()}`; + if (item.type === 'separator') { + if (Separator) return ; + return ( + + {item.name} + + ); + } - switch (item.type) { - case 'separator': - if (Separator) return ; - return ( - - {item.name} - - ); - case 'folder': - if (Folder) return ; - return ( - - {renderSidebarList(item.children, level + 1)} - - ); - default: - if (Item) return ; + if (item.type === 'folder') { + const children = renderSidebarList(item.children, level + 1); + + if (Folder) return ( - - {item.name} - + + {children} + ); + return ( + + {children} + + ); } + + if (Item) return ; + return ( + + {item.name} + + ); }); }