DocsLayout
The docs layout with a sidebar, built on the shadcn/ui sidebar.
Installation
npx shadcn@latest add @docscn/docs-layoutUsage
import { DocsLayout } from "@/components/docs/layouts/docs";
import { baseOptions } from "@/lib/layout.shared";
import { source } from "@/lib/source";
export default function Layout({ children }: LayoutProps<"/docs">) {
return (
<DocsLayout tree={source.getPageTree()} {...baseOptions()}>
{children}
</DocsLayout>
);
}DocsLayout renders the shadcn/ui SidebarProvider, a Sidebar with the page tree, and a SidebarInset for the page. On mobile, the sidebar opens as a sheet from a navbar with the title, search and a sidebar trigger. On desktop, the sidebar can be collapsed (⌘ B), leaving a small panel to reopen it.
Because it uses the shadcn/ui sidebar, useSidebar() from @/components/ui/sidebar works anywhere inside it.
Props
Prop
Type
sidebar
Prop
Type
The rest are passed to the shadcn/ui Sidebar (e.g. variant, side, className).
AI chat
Pass your chat as aiChat.panel, with its open state. While it's open, the layout docks the panel against the right edge of the window from the xl breakpoint, narrowing the page and hiding the table of contents. Below xl, it floats over the page. The panel renders the first time it opens. Set aiChat.trigger to add a floating Ask AI button that toggles it, unless your chat has its own button.
The open state lives on the client, so render the layout from a client component:
"use client";
import { useState } from "react";
import {
DocsLayout as Layout,
type DocsLayoutProps,
} from "@/components/docs/layouts/docs";
import { Chat } from "@/components/chat"; // your chat UI
export function DocsLayout(props: DocsLayoutProps) {
const [open, setOpen] = useState(false);
return (
<Layout
{...props}
aiChat={{
open,
onOpenChange: setOpen,
panel: <Chat onClose={() => setOpen(false)} />,
}}
/>
);
}Then import DocsLayout from @/components/ai/layout in app/docs/layout.tsx. The layout has no button to open the chat, so add one to your chat UI, for example a floating button or a link in nav.children.
For a ready-made chat, install the AI chat block, which adds this layout with docscn's chat UI and a chat route.