Docs Shell

Sidebar and content frame for a docs site

Docs Shell is the frame of a documentation site: a searchable sidebar built from a navigation config, beside the page content, with a toolbar across the top of the content. On small screens the sidebar becomes an overlay opened from the toolbar's first button. It is built on Womp UI's Shell, Sidebar and Toolbar.

This site runs on it. The sidebar to the left is a Docs Shell.

Installation

Install the dependencies.

npm install @kushagradhawan/kookie-ui @hugeicons/react @hugeicons/core-free-icons

Copy these files into components/blocks/docs-shell. Keep the folder names, since blocks import each other by relative path.

components/blocks/docs-shell/docs-shell.tsx
'use client';

import * as React from 'react';
import { Box, Flex, Shell, Toolbar, ToolbarButton, ToolbarSlot } from '@kushagradhawan/kookie-ui';
import { HugeiconsIcon } from '@hugeicons/react';
import { SidebarLeftIcon } from '@hugeicons/core-free-icons';
import { DocsSidebar } from './docs-sidebar';
import type { DocsLinkComponent, DocsLogoConfig, DocsNavigationConfig } from './types';

export interface DocsShellProps {
  children: React.ReactNode;
  navigation: DocsNavigationConfig;
  logo?: DocsLogoConfig;
  /** Rendered next to the logo, e.g. a GitHub link or version badge. */
  headerActions?: React.ReactNode;
  sidebarFooter?: React.ReactNode;
  height?: React.ComponentProps<typeof Shell.Root>['height'];
  /** @default true */
  sidebarResizable?: boolean;
  /** Replaces the icon of the sidebar button in the top bar. */
  mobileTriggerIcon?: React.ReactNode;
  /** Current path, used to mark the active item. */
  pathname?: string;
  /** Your router's link, e.g. `next/link`. Defaults to a plain anchor. */
  linkComponent?: DocsLinkComponent;
  /** A band at the top of the content pane, edge to edge, with the top bar floating over it. */
  hero?: React.ReactNode;
  /**
   * Controls at the end of the top bar, inside its `Toolbar`: `ToolbarGroup`s, `ToolbarButton`s
   * or a `ToolbarOverflow`. The page's own actions follow them.
   */
  toolbar?: React.ReactNode;
}

/** The `ToolbarSlot` at the end of the top bar. A page fills it with `<ToolbarFill name={DOCS_PAGE_ACTIONS}>`. */
export const DOCS_PAGE_ACTIONS = 'docs-page-actions';

/** Documentation app frame: a searchable sidebar beside the page content. */
export function DocsShell({
  children,
  navigation,
  logo,
  headerActions,
  sidebarFooter,
  height,
  sidebarResizable = true,
  mobileTriggerIcon,
  pathname = '',
  linkComponent,
  hero,
  toolbar,
}: DocsShellProps) {
  return (
    <Shell.Root height={height}>
      <Shell.Sidebar
        aria-label="Documentation"
        resizable={sidebarResizable}
        defaultState={{ initial: 'collapsed', sm: 'expanded' }}
        presentation={{ initial: 'overlay', sm: 'fixed' }}
      >
        <DocsSidebar
          navigation={navigation}
          logo={logo}
          headerActions={headerActions}
          footer={sidebarFooter}
          pathname={pathname}
          linkComponent={linkComponent}
        />
      </Shell.Sidebar>

      <Shell.Content className="kd-shell-content">
        {/* The top bar floats over the page, the way the sidebar's header floats over its list:
            the pane gives it its inset and the page starts below it. The sidebar button comes
            first, then `toolbar`, then the current page's actions (Source and the like) through a
            ToolbarSlot. One Toolbar for the whole band, as in v2: one tab stop, arrow keys between
            every control, and `backdrop` gives each control and group a raised surface. Its size
            is one step above the Shell's. */}
        <Shell.PaneHeader float>
          <Toolbar backdrop aria-label="Page">
            <Shell.Trigger target="sidebar" asChild>
              <ToolbarButton iconOnly aria-label="Toggle navigation">
                {mobileTriggerIcon ?? <HugeiconsIcon icon={SidebarLeftIcon} strokeWidth={1.75} />}
              </ToolbarButton>
            </Shell.Trigger>
            {/* The trailing cluster grows, so a ToolbarOverflow in `toolbar` has the room to measure. */}
            <Flex align="center" justify="end" gap="3" flexGrow="1" minWidth="0">
              {toolbar}
              <ToolbarSlot name={DOCS_PAGE_ACTIONS} />
            </Flex>
          </Toolbar>
        </Shell.PaneHeader>

        <Shell.Scroll fade>
          {/* The page starts below the bar. A hero gives that room back, so it runs to the pane's
              top edge with the bar over it. */}
          {hero && <Box mt="calc(-1 * var(--kui-pane-inset-start))">{hero}</Box>}
          {children}
        </Shell.Scroll>
      </Shell.Content>
    </Shell.Root>
  );
}
components/blocks/docs-shell/docs-search.tsx
'use client';

import * as React from 'react';
import { Command, CommandContent, CommandEmpty, CommandInput, CommandItem, CommandList, Text, ToolbarButton } from '@kushagradhawan/kookie-ui';
import { HugeiconsIcon } from '@hugeicons/react';
import { Search01Icon } from '@hugeicons/core-free-icons';
import type { DocsLinkComponent, DocsNavigationConfig } from './types';

interface Entry {
  href: string;
  title: string;
  /** The group the page sits in, shown after its title. */
  context: string;
}

/** Every page in the navigation, nested pages included, with the group it sits in. */
function entriesOf(navigation: DocsNavigationConfig): Entry[] {
  return navigation.groups.flatMap((group) =>
    group.items.flatMap((item) => [{ href: item.href, title: item.title, context: group.label }, ...(item.items ?? []).map((sub) => ({ href: sub.href, title: sub.title, context: item.title }))]),
  );
}

/** An exact title over a title that starts with the query, over one that contains it, over a group that does. */
function rank(entries: Entry[], query: string): Entry[] {
  const q = query.trim().toLowerCase();
  if (q.length === 0) return [];
  const score = (entry: Entry) => {
    const title = entry.title.toLowerCase();
    if (title === q) return 0;
    if (title.startsWith(q)) return 1;
    if (title.includes(q)) return 2;
    if (entry.context.toLowerCase().includes(q)) return 3;
    return -1;
  };
  return entries
    .map((entry) => ({ entry, score: score(entry) }))
    .filter((hit) => hit.score >= 0)
    .sort((a, b) => a.score - b.score)
    .slice(0, 12)
    .map((hit) => hit.entry);
}

/**
 * Search, as v2's docs have it: a toolbar button that opens the package's Command, and ⌘K from
 * anywhere. The app narrows and ranks the pages itself, so the palette's own filter is off, and
 * each result is a link, so Enter, a press and a middle-click all go where a link goes.
 */
export function DocsSearch({ navigation, linkComponent: LinkComponent }: { navigation: DocsNavigationConfig; linkComponent: DocsLinkComponent }) {
  const [open, setOpen] = React.useState(false);
  const [query, setQuery] = React.useState('');
  const entries = React.useMemo(() => entriesOf(navigation), [navigation]);
  const results = React.useMemo(() => rank(entries, query), [entries, query]);

  // ⌘K / Ctrl-K opens it from anywhere; Chrome's own ⌘K would take the address bar.
  React.useEffect(() => {
    const onKey = (event: KeyboardEvent) => {
      if (event.key?.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) {
        event.preventDefault();
        setOpen((value) => !value);
      }
    };
    document.addEventListener('keydown', onKey);
    return () => document.removeEventListener('keydown', onKey);
  }, []);

  return (
    <>
      <ToolbarButton iconOnly aria-label="Search the documentation" onClick={() => setOpen(true)}>
        <HugeiconsIcon icon={Search01Icon} strokeWidth={1.75} />
      </ToolbarButton>
      {/* Size 3, as v2's docs: a title and its group fit on one line at its width. */}
      <Command size="3" items={results} open={open} onOpenChange={setOpen}>
        <CommandContent aria-label="Search the documentation" filter={null} onQueryChange={setQuery}>
          <CommandInput aria-label="Search query" placeholder="Type to search" leading={<HugeiconsIcon icon={Search01Icon} strokeWidth={1.75} />} />
          <CommandList>
            {(entry: Entry) => (
              <CommandItem key={entry.href} value={entry.href} asChild>
                <LinkComponent href={entry.href}>
                  {entry.title}{' '}
                  <Text emphasis="medium" size="2">
                    {entry.context}
                  </Text>
                </LinkComponent>
              </CommandItem>
            )}
          </CommandList>
          {/* Only once something has been typed: an untouched field has no results by design. */}
          {query.trim().length > 0 ? <CommandEmpty>Nothing matches. Search covers the page titles in the sidebar.</CommandEmpty> : null}
        </CommandContent>
      </Command>
    </>
  );
}
components/blocks/docs-shell/docs-sidebar.tsx
'use client';

import * as React from 'react';
import { Avatar, Flex, Shell, Sidebar, Toolbar } from '@kushagradhawan/kookie-ui';
import { Logo } from '@/components/logo';
import { HugeiconsIcon, type IconSvgElement } from '@hugeicons/react';
import { DocsSearch } from './docs-search';
import type { DocsLinkComponent, DocsLinkProps, DocsLogoConfig, DocsNavigationConfig, DocsNavigationItem } from './types';

export interface DocsSidebarProps {
  navigation: DocsNavigationConfig;
  logo?: DocsLogoConfig;
  /** Beside the logo, e.g. a version badge. */
  headerActions?: React.ReactNode;
  /** The footer toolbar's contents: toolbar buttons and groups. */
  footer?: React.ReactNode;
  /** Current path, used to mark the active item. */
  pathname?: string;
  /** Your router's link, e.g. `next/link`. Defaults to a plain anchor. */
  linkComponent?: DocsLinkComponent;
}

function Anchor(props: DocsLinkProps) {
  return <a {...props} />;
}

function isIconSvgElement(icon: unknown): icon is IconSvgElement {
  return Array.isArray(icon) && icon.length > 0 && Array.isArray(icon[0]);
}

function renderIcon(icon: DocsNavigationItem['icon']) {
  if (!icon) return null;
  if (React.isValidElement(icon)) return icon;
  if (isIconSvgElement(icon)) return <HugeiconsIcon icon={icon} strokeWidth={1.75} />;
  if (typeof icon === 'function') {
    const Icon = icon;
    return <Icon />;
  }
  return null;
}

export function DocsSidebar({ navigation, logo, headerActions, footer, pathname = '', linkComponent: LinkComponent = Anchor }: DocsSidebarProps) {
  const renderItem = (item: DocsNavigationItem, withBadge: boolean) => (
    <Sidebar.MenuItem key={item.href}>
      <Sidebar.MenuButton asChild isActive={pathname === item.href} badge={withBadge ? item.badge : undefined}>
        <LinkComponent href={item.href}>
          {renderIcon(item.icon)}
          <span className="kui-SidebarMenuLabel">{item.title}</span>
        </LinkComponent>
      </Sidebar.MenuButton>
    </Sidebar.MenuItem>
  );

  const renderGroupItem = (item: DocsNavigationItem) => {
    if (!item.items?.length) return renderItem(item, true);

    const isNestedActive = item.items.some((subItem) => pathname === subItem.href);
    return (
      <Sidebar.MenuItem key={item.href}>
        <Sidebar.MenuSub defaultOpen={isNestedActive}>
          <Sidebar.MenuSubTrigger>
            {renderIcon(item.icon)}
            {item.title}
          </Sidebar.MenuSubTrigger>
          <Sidebar.MenuSubContent>
            {item.items.map((subItem) => (
              <Sidebar.MenuItem key={subItem.href}>
                <Sidebar.MenuButton asChild isActive={pathname === subItem.href}>
                  <LinkComponent href={subItem.href}>
                    {renderIcon(subItem.icon)}
                    <span className="kui-SidebarMenuLabel">{subItem.title}</span>
                  </LinkComponent>
                </Sidebar.MenuButton>
              </Sidebar.MenuItem>
            ))}
          </Sidebar.MenuSubContent>
        </Sidebar.MenuSub>
      </Sidebar.MenuItem>
    );
  };

  return (
    <>
      {/* The rows float over the list, as in v2: the list runs the pane's full height, starts
          clear of them, and fades out as it passes under them. */}
      <Shell.PaneHeader float>
        <Toolbar backdrop size="3" aria-label="Site">
          <Flex align="center" gap="4">
            {logo && (
              <LinkComponent href={logo.href ?? '/'} aria-label={logo.alt ?? 'Home'}>
                {logo.label ? (
                  /* THE MARK ALONE (2026-09-27, Kushagra): the word said the name a second time
                   in a row that is only ever glanced at. `label` stays the accessible name. */
                  <Logo height="var(--line-height-7)" />
                ) : (
                  <Avatar fallback={logo.alt?.[0] ?? 'K'} size={logo.size ?? '3'} src={logo.src} />
                )}
              </LinkComponent>
            )}
            {headerActions}
          </Flex>
          {/* Search opens the package's Command, as v2's docs do (2026-11-03). */}
          <DocsSearch navigation={navigation} linkComponent={LinkComponent} />
        </Toolbar>
      </Shell.PaneHeader>

      <Shell.Scroll fade>
        {navigation.groups.map((group) => (
          <Sidebar.Group key={group.label}>
            <Sidebar.GroupLabel>{group.label}</Sidebar.GroupLabel>
            <Sidebar.GroupContent>
              <Sidebar.Menu>{group.items.map(renderGroupItem)}</Sidebar.Menu>
            </Sidebar.GroupContent>
          </Sidebar.Group>
        ))}
      </Shell.Scroll>

      {footer && (
        <Shell.PaneFooter float>
          <Toolbar backdrop size="3" aria-label="Site settings">
            {footer}
          </Toolbar>
        </Shell.PaneFooter>
      )}
    </>
  );
}
components/blocks/docs-shell/types.ts
import type * as React from 'react';
import type { Sidebar } from '@kushagradhawan/kookie-ui';
import type { IconSvgElement } from '@hugeicons/react';

export interface DocsNavigationItem {
  href: string;
  title: string;
  /** A HugeIcons icon, a component, or any element. */
  icon?: IconSvgElement | React.ComponentType | React.ReactElement;
  /** Text badge, or a config object for color and variant. */
  badge?: string | Sidebar.BadgeConfig;
  /** Nested pages, shown in a collapsible sub-menu. */
  items?: DocsNavigationItem[];
}

export interface DocsNavigationGroup {
  label: string;
  items: DocsNavigationItem[];
}

export interface DocsNavigationConfig {
  groups: DocsNavigationGroup[];
}

export interface DocsLogoConfig {
  /** An image mark. Ignored when `label` is set. */
  src?: string;
  /** A text wordmark instead of an image. The thin sidebar shows its first letter. */
  label?: string;
  alt?: string;
  /** @default "/" */
  href?: string;
  /** @default "3" */
  size?: '1' | '2' | '3' | '4' | '5';
}

/** Props the shell passes to your link component, e.g. `next/link`. */
export interface DocsLinkProps {
  href: string;
  children: React.ReactNode;
  'aria-label'?: string;
}

export type DocsLinkComponent = React.ComponentType<DocsLinkProps>;

Usage

Describe the navigation once, then wrap your docs layout.

// navigation.ts
import type { DocsNavigationConfig } from '@/components/blocks/docs-shell/types';
 
export const navigation: DocsNavigationConfig = {
  groups: [
    {
      label: 'Get Started',
      items: [{ href: '/docs/installation', title: 'Installation' }],
    },
    {
      label: 'Components',
      items: [
        { href: '/docs/button', title: 'Button', badge: 'New' },
        { href: '/docs/card', title: 'Card' },
      ],
    },
  ],
};
// app/docs/layout.tsx
'use client';
 
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { DocsShell } from '@/components/blocks/docs-shell/docs-shell';
import { navigation } from '@/navigation';
 
export default function DocsLayout({ children }: { children: React.ReactNode }) {
  return (
    <DocsShell
      navigation={navigation}
      logo={{ src: '/logo.png', alt: 'Acme' }}
      pathname={usePathname()}
      linkComponent={Link}
    >
      {children}
    </DocsShell>
  );
}

Anatomy

FileContains
docs-shell.tsxDocsShell: the Shell layout, and a floating header over the page's Shell.Scroll holding the toolbar, with the sidebar button and a ToolbarSlot for the page's actions
docs-sidebar.tsxDocsSidebar: a floating header with the logo and search, the grouped menu, and a floating footer. Usable on its own inside any Shell.Sidebar
types.tsNavigation, logo and link types

Props

PropTypeDefaultDescription
navigationDocsNavigationConfig-Groups and items for the sidebar.
pathnamestring''Current path. The matching item is marked active.
linkComponentDocsLinkComponent<a>Your router's link, such as next/link.
heroReactNode-A band at the top of the content pane, edge to edge. The toolbar floats over it.
toolbarReactNode-Controls at the end of the toolbar: ToolbarGroups, ToolbarButtons or a ToolbarOverflow. The page's own actions follow them.
logoDocsLogoConfig-Logo in the sidebar header.
headerActionsReactNode-Beside the logo, e.g. a version badge.
sidebarFooterReactNode-The floating footer toolbar's contents, e.g. a theme switch.
sidebarResizablebooleantrueLet people drag the sidebar edge.
mobileTriggerIconReactNodeSidebar iconIcon for the sidebar button at the start of the toolbar.
heightShell.Root height-Height of the shell. Leave it unset for an app frame, so the page scrolls on a phone. A value makes the shell contained.
FieldTypeDescription
hrefstringLink target. Also the key, so keep it unique.
titlestringLabel. Search matches against it.
iconIconSvgElement | ComponentType | ReactElementOptional. A HugeIcons icon, a component or an element.
badgestring | Sidebar.BadgeConfigOptional text badge, or a config for color and variant.
itemsDocsNavigationItem[]Optional nested pages, shown in a collapsible sub-menu that opens when one is active.
FieldTypeDefaultDescription
srcstring-Image URL. Ignored when label is set.
labelstring-A text wordmark instead of an image.
altstring-Accessible name. Its first letter is the image fallback.
hrefstring'/'Where the logo links.
size'1' – '5''3'Image size.

Examples

Status Badges

{
  href: '/docs/combobox',
  title: 'Combobox',
  badge: { content: 'Alpha', size: '1', color: 'gray' },
}

Toolbar

Pass your own controls with toolbar. Wrap them in ToolbarOverflow and the ones that don't fit move into a More menu on small screens.

<DocsShell
  navigation={navigation}
  toolbar={
    <ToolbarOverflow label="More actions">
      <ToolbarGroup>
        <ToolbarButton asChild iconOnly aria-label="GitHub">
          <a href="https://github.com/acme/docs">
            <HugeiconsIcon icon={GithubIcon} strokeWidth={1.75} />
          </a>
        </ToolbarButton>
      </ToolbarGroup>
    </ToolbarOverflow>
  }
>
  {children}
</DocsShell>

A page adds its own controls with ToolbarFill. Docs Page puts its Source button there.

<ToolbarFill name={DOCS_PAGE_ACTIONS}>
  <ToolbarButton>Edit</ToolbarButton>
</ToolbarFill>

Nested Pages

{
  href: '/docs/forms',
  title: 'Forms',
  items: [
    { href: '/docs/forms/validation', title: 'Validation' },
    { href: '/docs/forms/submission', title: 'Submission' },
  ],
}

Accessibility

Search filters the menu as you type and shows a flat list of matches. The logo link and the sidebar button have accessible names. Active items are marked through Sidebar.MenuButton, which sets aria-current.

The toolbar is one tab stop. The arrow keys move between its controls, including the ones a page adds through ToolbarFill.