Sidebar

An app's menu: a SidebarProvider that starts collapsed around a Sidebar that keeps its icons and widens while the pointer or the focus is on it (expandOnHover), the page moving over for it, and a SidebarTrigger with toggle at the start of the page's top bar, outside the sidebar, that keeps it wide or narrow. The workspace sits on top, its pages are transparent buttons with the open one soft and a count after its label, and the signed-in person is at the foot.

Title

Description

import {
  Add01Icon,
  Building03Icon,
  Calendar03Icon,
  ChartHistogramIcon,
  DashboardSquare01Icon,
  FileTextIcon,
  Folder01Icon,
  InboxIcon,
  Settings01Icon,
  UserGroupIcon,
} from "@hugeicons/core-free-icons";
import { Avatar, AvatarFallback } from "@produkto/ui/Avatar";
import { Badge } from "@produkto/ui/Badge";
import {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbList,
  BreadcrumbPage,
  BreadcrumbSeparator,
} from "@produkto/ui/Breadcrumb";
import { Button } from "@produkto/ui/Button";
import { cssVariables } from "@produkto/ui/helpers/cssVariables";
import { Icon, type IconSvgElement } from "@produkto/ui/Icon";
import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarGroupContent,
  SidebarHeader,
  SidebarInset,
  SidebarProvider,
  SidebarTrigger,
} from "@produkto/ui/Sidebar";

const pages: { label: string; icon: IconSvgElement; badge?: string }[] = [
  { label: "Item 1", icon: DashboardSquare01Icon },
  { label: "Item 2", icon: InboxIcon, badge: "3" },
  { label: "Item 3", icon: Calendar03Icon },
  { label: "Item 4", icon: Folder01Icon },
  { label: "Item 5", icon: FileTextIcon },
  { label: "Item 6", icon: UserGroupIcon },
  { label: "Item 7", icon: ChartHistogramIcon },
  { label: "Item 8", icon: Settings01Icon },
];

const Example = () => (
  <SidebarProvider
    defaultOpen={false}
    style={cssVariables({ "--sidebar-width": "13rem" })}
    className="relative h-136 min-h-0 overflow-hidden rounded-xl border border-border"
  >
    <Sidebar expandOnHover className="absolute h-full">
      <SidebarHeader>
        <Button
          appearance="transparent"
          size="sm"
          block
          align="start"
          className="overflow-hidden"
        >
          <Icon icon={Building03Icon} />
          <span className="truncate">Title</span>
        </Button>
      </SidebarHeader>
      <SidebarContent>
        <SidebarGroup>
          <SidebarGroupContent className="space-y-2">
            {pages.map((page, index) => (
              <Button
                key={page.label}
                appearance={index === 0 ? "soft" : "transparent"}
                size="sm"
                block
                align="start"
                aria-current={index === 0 ? "page" : undefined}
                className="overflow-hidden"
              >
                <Icon icon={page.icon} />
                <span className="truncate">{page.label}</span>
                {page.badge ? (
                  <Badge
                    tone="success"
                    borderRadius="full"
                    className="group-data-[collapsible=icon]:hidden"
                  >
                    {page.badge}
                  </Badge>
                ) : null}
              </Button>
            ))}
          </SidebarGroupContent>
        </SidebarGroup>
      </SidebarContent>
      <SidebarFooter>
        <Button
          appearance="transparent"
          size="sm"
          block
          align="start"
          className="min-w-0"
        >
          <Avatar size="sm" aria-hidden>
            <AvatarFallback>U1</AvatarFallback>
          </Avatar>
          <span className="truncate">User 1</span>
        </Button>
      </SidebarFooter>
    </Sidebar>
    <SidebarInset>
      <header className="flex items-center gap-2 border-b border-border p-3">
        <SidebarTrigger toggle />
        <Breadcrumb>
          <BreadcrumbList>
            <BreadcrumbItem>Title</BreadcrumbItem>
            <BreadcrumbSeparator />
            <BreadcrumbItem>
              <BreadcrumbPage>Item 1</BreadcrumbPage>
            </BreadcrumbItem>
          </BreadcrumbList>
        </Breadcrumb>
        <div className="ms-auto flex items-center gap-2">
          <Button size="sm">
            <Icon icon={Add01Icon} data-icon="inline-start" />
            Button
          </Button>
          <SidebarTrigger />
        </div>
      </header>
      <div className="flex flex-col gap-1 p-3">
        <h2 className="heading-base">Title</h2>
        <p className="description-sm">Description</p>
      </div>
    </SidebarInset>
  </SidebarProvider>
);

export default Example;

Usage

import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarHeader,
  SidebarInset,
  SidebarProvider,
  SidebarTrigger,
} from "@produkto/ui/Sidebar";
<SidebarProvider defaultOpen={false}>
  <Sidebar expandOnHover>
    <SidebarHeader>{header}</SidebarHeader>
    <SidebarContent>{pages}</SidebarContent>
    <SidebarFooter>{person}</SidebarFooter>
  </Sidebar>
  <SidebarInset>
    <header>
      <SidebarTrigger toggle />
      {breadcrumbs}
      <SidebarTrigger />
    </header>
    {children}
  </SidebarInset>
</SidebarProvider>

Examples

Border radius

borderRadius sets the corners of the sidebar's rows on the kit's one scale: none, xs 4px, sm 6px, base 8px (the default), lg 12px, xl 16px, or full to round them. A menu button takes it, and a sub-menu button and a group's label sit one step inside; here the open page and its parent are marked so their corners show.

import {
  Sidebar,
  SidebarContent,
  SidebarGroup,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarMenuSub,
  SidebarMenuSubButton,
  SidebarMenuSubItem,
  SidebarProvider,
  type SidebarBorderRadius,
} from "@produkto/ui/Sidebar";

const radii: SidebarBorderRadius[] = [
  "none",
  "xs",
  "sm",
  "base",
  "lg",
  "xl",
  "full",
];

const pages: string[] = ["Item 3", "Item 4"];

const Example = () => (
  <div className="flex w-full flex-wrap justify-center gap-4">
    {radii.map((borderRadius) => (
      <SidebarProvider
        className="relative h-56 min-h-0 w-64 overflow-hidden rounded-xl border border-border"
        key={borderRadius}
      >
        <Sidebar className="absolute h-full" borderRadius={borderRadius}>
          <SidebarContent>
            <SidebarGroup>
              <SidebarGroupLabel>{borderRadius}</SidebarGroupLabel>
              <SidebarGroupContent>
                <SidebarMenu>
                  <SidebarMenuItem>
                    <SidebarMenuButton>Item 1</SidebarMenuButton>
                  </SidebarMenuItem>
                  <SidebarMenuItem>
                    <SidebarMenuButton active>Item 2</SidebarMenuButton>
                    <SidebarMenuSub>
                      {pages.map((page, index) => (
                        <SidebarMenuSubItem key={page}>
                          <SidebarMenuSubButton href="#" active={index === 0}>
                            {page}
                          </SidebarMenuSubButton>
                        </SidebarMenuSubItem>
                      ))}
                    </SidebarMenuSub>
                  </SidebarMenuItem>
                </SidebarMenu>
              </SidebarGroupContent>
            </SidebarGroup>
          </SidebarContent>
        </Sidebar>
      </SidebarProvider>
    ))}
  </div>
);

export default Example;

Loading

While the workspace, its pages and the signed-in person load: a SidebarMenuSkeleton for the workspace, three for the pages and one for the person, each its icon's square alone while the menu is narrow.

import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarHeader,
  SidebarInset,
  SidebarMenu,
  SidebarMenuItem,
  SidebarMenuSkeleton,
  SidebarProvider,
  SidebarTrigger,
} from "@produkto/ui/Sidebar";
import { cssVariables } from "@produkto/ui/helpers/cssVariables";

const Example = () => (
  <SidebarProvider
    defaultOpen={false}
    style={cssVariables({ "--sidebar-width": "13rem" })}
    className="relative h-80 min-h-0 overflow-hidden rounded-xl border border-border"
  >
    <Sidebar expandOnHover className="absolute h-full">
      <SidebarHeader>
        <SidebarMenuSkeleton showIcon aria-hidden className="min-w-0 flex-1" />
      </SidebarHeader>
      <SidebarContent>
        <SidebarMenu aria-hidden>
          {Array.from({ length: 3 }, (_, row) => (
            <SidebarMenuItem key={row}>
              <SidebarMenuSkeleton showIcon />
            </SidebarMenuItem>
          ))}
        </SidebarMenu>
      </SidebarContent>
      <SidebarFooter aria-hidden>
        <SidebarMenuSkeleton showIcon />
      </SidebarFooter>
    </Sidebar>
    <SidebarInset>
      <header className="flex items-center gap-2 border-b border-border p-3">
        <SidebarTrigger toggle />
      </header>
    </SidebarInset>
  </SidebarProvider>
);

export default Example;

API Reference

Sidebar

SidebarProps · components/Sidebar/Sidebar.types.ts
PropTypeDefault
sideSidebarSide"start" | "end""start"
expandOnHoverbooleanfalse
borderRadiusSidebarBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full""base"

SidebarProvider

SidebarProviderProps · also takes the props of <div>
PropTypeDefault
defaultOpenbooleantrue

SidebarTrigger

SidebarTriggerProps · also takes the props of Button
PropTypeDefault
togglebooleanfalse

SidebarInset

SidebarInsetProps · takes the props of <main>

SidebarHeader

SidebarHeaderProps · takes the props of <div>

SidebarFooter

SidebarFooterProps · takes the props of <div>

SidebarContent

SidebarContentProps · takes the props of <div>

SidebarGroup

SidebarGroupProps · takes the props of <div>

SidebarGroupLabel

SidebarGroupLabelProps · takes the props of <div>

SidebarGroupContent

SidebarGroupContentProps · takes the props of <div>

SidebarMenu

SidebarMenuProps · takes the props of <ul>

SidebarMenuItem

SidebarMenuItemProps · takes the props of <li>

SidebarMenuButton

SidebarMenuButtonProps · also takes the props of <button>
PropTypeDefault
asChildbooleanfalse
activebooleanfalse

SidebarMenuSkeleton

SidebarMenuSkeletonProps · also takes the props of <div>
PropTypeDefault
showIconbooleanfalse

SidebarMenuSub

SidebarMenuSubProps · takes the props of <ul>

SidebarMenuSubItem

SidebarMenuSubItemProps · takes the props of <li>

SidebarMenuSubButton

SidebarMenuSubButtonProps · also takes the props of <a>
PropTypeDefault
asChildbooleanfalse
activebooleanfalse

It also takes the props of <div>.