---
title: "DocsLayout"
description: "The docs layout with a sidebar, built on the shadcn/ui sidebar."
url: https://docscn.dev/docs/components/docs-layout
lastModified: 2026-11-10T02:16:05.000Z
---

# DocsLayout (/docs/components/docs-layout)

> The docs layout with a sidebar, built on the shadcn/ui sidebar.

## Installation [#installation]

```npm
npx shadcn@latest add @docscn/docs-layout
```

## Usage [#usage]

```tsx title="app/docs/layout.tsx"
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 (<kbd>⌘</kbd> <kbd>B</kbd>), leaving a small panel to reopen it.

Because it uses the shadcn/ui sidebar, `useSidebar()` from `@/components/ui/sidebar` works anywhere inside it.

## Props [#props]

<TypeTable
  type={{
    tree: {
      description: (
        <>
          The page tree, usually <code>{"source.getPageTree()"}</code>.
        </>
      ),
      type: "PageTree.Root",
      required: true,
    },
    nav: {
      description: (
        <>
          <code>{"title"}</code>, <code>{"url"}</code> (defaults to{" "}
          <code>{"/"}</code>), <code>{"enabled"}</code>,{" "}
          <code>{"children"}</code> (extra navbar content) and{" "}
          <code>{"transparentMode"}</code>.
        </>
      ),
      type: "NavOptions",
    },
    links: {
      description: (
        <>
          Links shown in the sidebar. Icon links show in the sidebar footer.{" "}
          <code>{'on: "nav" | "menu" | "all"'}</code> restricts where a link
          shows.
        </>
      ),
      type: "LinkItemType[]",
    },
    githubUrl: {
      description: <>Adds a GitHub icon link.</>,
      type: "string",
    },
    sidebar: {
      description: <>See below.</>,
      type: "SidebarOptions",
    },
    tabs: {
      description: (
        <>
          Layout tabs, by default one per root folder (
          <code>{'"root": true'}</code> in <code>{"meta.json"}</code>).
        </>
      ),
      type: "LayoutTab[] | GetLayoutTabsOptions | false",
    },
    tabMode: {
      description: (
        <>
          Show tabs as a dropdown in the sidebar (<code>{"auto"}</code>), or
          above the page on desktop (<code>{"top"}</code>).
        </>
      ),
      type: '"auto" | "top"',
    },
    themeSwitch: {
      description: (
        <>
          The theme switch in the sidebar footer.{" "}
          <code>{'mode: "light-dark-system"'}</code> adds a system option.
        </>
      ),
      type: "{ enabled?, mode? }",
    },
    searchToggle: {
      description: (
        <>The search triggers, with props for the small and full variants.</>
      ),
      type: "{ enabled?, sm?, full? }",
    },
    containerProps: {
      description: (
        <>
          Props for the <code>{"SidebarInset"}</code> that wraps the page.
        </>
      ),
      type: 'ComponentProps<"main">',
    },
    aiChat: {
      description: (
        <>
          An AI chat panel and whether it's open. See{" "}
          <a href="#ai-chat">AI chat</a>.
        </>
      ),
      type: "{ open, onOpenChange, panel?, trigger? }",
    },
  }}
/>

### `sidebar` [#sidebar]

<TypeTable
  type={{
    enabled: {
      description: <>Show the sidebar.</>,
      type: "boolean",
      default: "true",
    },
    banner: {
      description: <>Content above the page tree.</>,
      type: "ReactNode",
    },
    footer: {
      description: <>Content in the sidebar footer.</>,
      type: "ReactNode",
    },
    collapsible: {
      description: <>Allow collapsing the sidebar on desktop.</>,
      type: "boolean",
      default: "true",
    },
    defaultOpenLevel: {
      description: <>Open folders up to this depth by default.</>,
      type: "number",
      default: "0",
    },
    prefetch: {
      description: <>Prefetch pages linked from the sidebar.</>,
      type: "boolean",
    },
    defaultOpen: {
      description: (
        <>
          Whether the desktop sidebar starts open. Read shadcn/ui's{" "}
          <code>{"sidebar_state"}</code> cookie and pass it to keep the state
          across page loads.
        </>
      ),
      type: "boolean",
    },
    open: {
      description: <>Control the desktop open state.</>,
      type: "boolean",
    },
    onOpenChange: {
      description: <>Called when the desktop open state changes.</>,
      type: "(open: boolean) => void",
    },
    components: {
      description: <>Replace how page tree nodes render.</>,
      type: "{ Item?, Folder?, Separator? }",
    },
  }}
/>

The rest are passed to the shadcn/ui `Sidebar` (e.g. `variant`, `side`, `className`).

## AI chat [#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:

```tsx title="components/ai/layout.tsx"
"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](/docs/components/ai-chat) block, which adds this layout with docscn's chat UI and a chat route.