{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar",
  "type": "registry:ui",
  "title": "Sidebar",
  "description": "An application's side navigation: groups of links with icons that fold to a slim rail of icons (their names still read out) and back with a button or Ctrl/⌘+B, and that becomes a sheet from the side on narrow screens; with the main area beside it.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/sheet",
    "@rivier-ui/use-controllable-state",
    "@rivier-ui/use-hotkeys"
  ],
  "files": [
    {
      "path": "registry/ui/sidebar.tsx",
      "type": "registry:ui",
      "target": "components/ui/sidebar.tsx",
      "content": "\"use client\";\n/**\n * @name sidebar\n * @category ui\n * @description An application's side navigation: groups of links with icons that fold to a slim rail of icons (their names still read out) and back with a button or Ctrl/⌘+B, and that becomes a sheet from the side on narrow screens; with the main area beside it.\n * @when The frame of an app with many sections: a dashboard, settings, a workspace. For a site's header links use navbar; for a panel of tools the person resizes use dock or resizable.\n * @example\n * <SidebarProvider>\n *   <Sidebar aria-label=\"Workspace\">\n *     <SidebarHeader>Acme</SidebarHeader>\n *     <SidebarContent>\n *       <SidebarGroup label=\"Work\">\n *         <SidebarMenu>\n *           <SidebarMenuItem><SidebarMenuButton href=\"/inbox\" icon={<Inbox />} current>Inbox</SidebarMenuButton></SidebarMenuItem>\n *           <SidebarMenuItem><SidebarMenuButton href=\"/reports\" icon={<ChartBar />}>Reports</SidebarMenuButton></SidebarMenuItem>\n *         </SidebarMenu>\n *       </SidebarGroup>\n *     </SidebarContent>\n *   </Sidebar>\n *   <SidebarInset>\n *     <SidebarTrigger />\n *     …\n *   </SidebarInset>\n * </SidebarProvider>\n */\nimport { PanelLeft } from \"lucide-react\";\nimport { createContext, use, useId, useSyncExternalStore, type ComponentProps, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable-state\";\nimport { useHotkeys } from \"@/lib/use-hotkeys\";\nimport { Sheet, SheetContent, SheetTitle } from \"@/components/ui/sheet\";\n\ntype SidebarContextValue = {\n  id: string;\n  open: boolean;\n  setOpen: (open: boolean) => void;\n  openMobile: boolean;\n  setOpenMobile: (open: boolean) => void;\n  narrow: boolean;\n  labels: SidebarLabels;\n};\n\nconst SidebarContext = createContext<SidebarContextValue | null>(null);\n\n/** The sidebar's state, for a part of the project's own: whether it is open, and the narrow-screen sheet. */\nexport function useSidebar(): SidebarContextValue {\n  const context = use(SidebarContext);\n  if (!context) throw new Error(\"Sidebar parts must be inside a SidebarProvider.\");\n  return context;\n}\n\nexport type SidebarLabels = { show: string; hide: string; title: string };\nconst LABELS: SidebarLabels = { show: \"Show the sidebar\", hide: \"Fold the sidebar\", title: \"Navigation\" };\n\nconst NARROW = \"(max-width: 767.98px)\";\nconst subscribeNarrow = (change: () => void): (() => void) => {\n  const query = window.matchMedia(NARROW);\n  query.addEventListener(\"change\", change);\n  return () => query.removeEventListener(\"change\", change);\n};\n\nexport type SidebarProviderProps = ComponentProps<\"div\"> & {\n  /** Wide, with names, or folded to icons (on wide screens). Controlled with `onOpenChange`. */\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** The shortcut that folds and unfolds it. Default \"mod+b\"; null for none. */\n  shortcut?: string | null;\n  labels?: Partial<SidebarLabels>;\n};\n\nexport function SidebarProvider({ open: openProp, defaultOpen = true, onOpenChange, shortcut = \"mod+b\", labels: given, className, style, ...props }: SidebarProviderProps) {\n  const [open, setOpen] = useControllableState<boolean>({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n  const [openMobile, setOpenMobile] = useControllableState<boolean>({ defaultValue: false });\n  const narrow = useSyncExternalStore(\n    subscribeNarrow,\n    () => window.matchMedia(NARROW).matches,\n    () => false,\n  );\n  const id = useId();\n  useHotkeys(shortcut ?? \"\", () => (narrow ? setOpenMobile(!openMobile) : setOpen(!open)), { enabled: shortcut !== null });\n  return (\n    <SidebarContext value={{ id, open, setOpen, openMobile, setOpenMobile, narrow, labels: { ...LABELS, ...given } }}>\n      <div\n        data-slot=\"sidebar-provider\"\n        data-state={open ? \"open\" : \"folded\"}\n        className={cn(\"group/sidebar flex min-h-0 w-full\", className)}\n        style={{ [\"--sidebar-w\" as string]: \"16rem\", [\"--sidebar-rail\" as string]: \"3.5rem\", ...style }}\n        {...props}\n      />\n    </SidebarContext>\n  );\n}\n\nexport type SidebarProps = Omit<ComponentProps<\"nav\">, \"children\"> & { children?: ReactNode };\n\n/** The sidebar: a navigation landmark (name it with `aria-label`). On narrow screens it is a sheet opened by SidebarTrigger. */\nexport function Sidebar({ className, children, ...props }: SidebarProps) {\n  const { id, open, narrow, openMobile, setOpenMobile, labels } = useSidebar();\n  if (narrow) {\n    return (\n      <Sheet open={openMobile} onOpenChange={setOpenMobile}>\n        <SheetContent side=\"start\" className=\"w-(--sidebar-w) max-w-[85vw] p-0\">\n          <SheetTitle className=\"sr-only\">{labels.title}</SheetTitle>\n          <nav id={id} data-slot=\"sidebar\" data-state=\"open\" className={cn(\"flex h-full flex-col\", className)} {...props}>\n            {children}\n          </nav>\n        </SheetContent>\n      </Sheet>\n    );\n  }\n  return (\n    <nav\n      id={id}\n      data-slot=\"sidebar\"\n      data-state={open ? \"open\" : \"folded\"}\n      className={cn(\"sticky top-0 flex h-full max-h-dvh shrink-0 flex-col overflow-hidden border-e bg-card text-card-foreground\", open ? \"w-(--sidebar-w)\" : \"w-(--sidebar-rail)\", className)}\n      {...props}\n    >\n      {children}\n    </nav>\n  );\n}\n\nexport function SidebarHeader({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"sidebar-header\" className={cn(\"flex min-h-14 items-center gap-2 border-b px-3 font-medium group-data-[state=folded]/sidebar:justify-center\", className)} {...props} />;\n}\n\nexport function SidebarContent({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"sidebar-content\" className={cn(\"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-2\", className)} {...props} />;\n}\n\nexport function SidebarFooter({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"sidebar-footer\" className={cn(\"mt-auto border-t p-2\", className)} {...props} />;\n}\n\n/** A group of links under a small heading. The heading is hidden while folded, but still names the group. */\nexport function SidebarGroup({ label, className, children, ...props }: ComponentProps<\"div\"> & { label?: string }) {\n  const headingId = useId();\n  return (\n    <div data-slot=\"sidebar-group\" role=\"group\" aria-labelledby={label ? headingId : undefined} className={cn(\"flex flex-col gap-1\", className)} {...props}>\n      {label ? (\n        <span id={headingId} className=\"px-2 text-xs font-medium text-muted-foreground group-data-[state=folded]/sidebar:sr-only\">\n          {label}\n        </span>\n      ) : null}\n      {children}\n    </div>\n  );\n}\n\nexport function SidebarMenu({ className, ...props }: ComponentProps<\"ul\">) {\n  return <ul data-slot=\"sidebar-menu\" className={cn(\"flex flex-col gap-0.5\", className)} {...props} />;\n}\n\nexport function SidebarMenuItem({ className, ...props }: ComponentProps<\"li\">) {\n  return <li data-slot=\"sidebar-menu-item\" className={cn(\"min-w-0\", className)} {...props} />;\n}\n\nexport type SidebarMenuButtonProps = Omit<ComponentProps<\"a\">, \"children\"> & {\n  icon?: ReactNode;\n  /** The page one is on: marked with aria-current and a stronger ground, not by colour alone. */\n  current?: boolean;\n  /** What it is called. Hidden while folded, but still its name. */\n  children: ReactNode;\n  /** A count or a state at the end, such as unread items. */\n  badge?: ReactNode;\n};\n\n/** A link in the sidebar. Use `href`; for an action, put a button of your own with the same classes in the item. */\nexport function SidebarMenuButton({ icon, current = false, badge, className, children, ...props }: SidebarMenuButtonProps) {\n  return (\n    <a\n      data-slot=\"sidebar-menu-button\"\n      aria-current={current ? \"page\" : undefined}\n      className={cn(\n        \"flex min-h-10 items-center gap-3 rounded-control px-2 text-sm hover:bg-accent aria-[current=page]:bg-highlight-soft aria-[current=page]:font-medium group-data-[state=folded]/sidebar:justify-center [&>svg]:size-4 [&>svg]:shrink-0\",\n        className,\n      )}\n      {...props}\n    >\n      {icon ? (\n        <span aria-hidden=\"true\" className=\"flex size-4 shrink-0 items-center justify-center [&>svg]:size-4\">\n          {icon}\n        </span>\n      ) : null}\n      <span className=\"min-w-0 flex-1 truncate group-data-[state=folded]/sidebar:sr-only\">{children}</span>\n      {badge ? <span className=\"ms-auto text-xs tabular-nums text-muted-foreground group-data-[state=folded]/sidebar:sr-only\">{badge}</span> : null}\n    </a>\n  );\n}\n\n/** The main area beside the sidebar. */\nexport function SidebarInset({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"sidebar-inset\" className={cn(\"flex min-w-0 flex-1 flex-col\", className)} {...props} />;\n}\n\n/** The button that folds and unfolds the sidebar, or opens its sheet on narrow screens. */\nexport function SidebarTrigger({ className, onClick, ...props }: Omit<ComponentProps<\"button\">, \"children\">) {\n  const { id, open, setOpen, narrow, openMobile, setOpenMobile, labels } = useSidebar();\n  const expanded = narrow ? openMobile : open;\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"sidebar-trigger\"\n      aria-controls={id}\n      aria-expanded={expanded}\n      aria-label={expanded ? labels.hide : labels.show}\n      onClick={(event) => {\n        onClick?.(event);\n        if (narrow) setOpenMobile(!openMobile);\n        else setOpen(!open);\n      }}\n      className={cn(\"inline-flex size-(--control-h) items-center justify-center rounded-control hover:bg-accent\", className)}\n      {...props}\n    >\n      <PanelLeft aria-hidden=\"true\" className=\"size-4 rtl:-scale-x-100\" />\n    </button>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "The frame of an app with many sections: a dashboard, settings, a workspace. For a site's header links use navbar; for a panel of tools the person resizes use dock or resizable.",
    "example": "<SidebarProvider>\n  <Sidebar aria-label=\"Workspace\">\n    <SidebarHeader>Acme</SidebarHeader>\n    <SidebarContent>\n      <SidebarGroup label=\"Work\">\n        <SidebarMenu>\n          <SidebarMenuItem><SidebarMenuButton href=\"/inbox\" icon={<Inbox />} current>Inbox</SidebarMenuButton></SidebarMenuItem>\n          <SidebarMenuItem><SidebarMenuButton href=\"/reports\" icon={<ChartBar />}>Reports</SidebarMenuButton></SidebarMenuItem>\n        </SidebarMenu>\n      </SidebarGroup>\n    </SidebarContent>\n  </Sidebar>\n  <SidebarInset>\n    <SidebarTrigger />\n    …\n  </SidebarInset>\n</SidebarProvider>",
    "client": true
  }
}
