UI: hide TOC when it has no items and custom banner/footer

This commit is contained in:
Fuma Nama
2024-11-21 20:04:11 +08:00
parent d4d4ba88aa
commit 4c82a3dfe7
2 changed files with 13 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-ui': patch
---
Hide toc when it has no items and custom banner & footer
+8 -2
View File
@@ -120,19 +120,25 @@ export function DocsPage({
} = {},
tableOfContent: {
// disable TOC on full mode, you can still enable it with `enabled` option.
enabled: tocEnabled = !full,
enabled: tocEnabled,
component: tocReplace,
...tocOptions
} = {},
...props
}: DocsPageProps): ReactNode {
tocEnabled ??=
!full &&
(toc.length > 0 ||
tocOptions.footer !== undefined ||
tocOptions.header !== undefined);
return (
<AnchorProvider toc={toc} single={tocOptions.single}>
<PageContainer
id="nd-page"
style={
{
'--fd-toc-width': tocEnabled ? undefined : '0px',
'--fd-toc-width': full && !tocEnabled ? '0px' : undefined,
} as object
}
>