{
  "schemaVersion": 1,
  "target": "react",
  "name": "sidebar",
  "version": "0.1.1",
  "category": "navigation",
  "title": "Sidebar",
  "description": "An app sidebar with a header, labelled and collapsible groups, icons, counts, an active item, an icon-only mode with tooltips, and a sheet on narrow screens.",
  "tags": [
    "navigation",
    "sidebar",
    "app-shell",
    "layout",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "tooltip",
      "version": "0.1.1"
    }
  ],
  "docsPath": "/components/sidebar",
  "props": [
    {
      "name": "SidebarProvider collapsed / defaultCollapsed / onCollapsedChange",
      "type": "boolean / boolean / (collapsed) => void",
      "description": "Icon-only state. Leave collapsed unset for an uncontrolled sidebar."
    },
    {
      "name": "SidebarProvider mobileBreakpoint",
      "type": "number",
      "default": "768",
      "description": "Below this width (measured on the provider, not the window) the sidebar moves into a sheet."
    },
    {
      "name": "SidebarProvider keyboardShortcut",
      "type": "string | false",
      "default": "\"b\"",
      "description": "Letter that toggles the sidebar with Cmd or Ctrl. Ignored while typing in a field."
    },
    {
      "name": "SidebarProvider width / collapsedWidth",
      "type": "string",
      "default": "\"16rem\" / \"3.5rem\"",
      "description": "Expanded and icon-only column widths as CSS lengths."
    },
    {
      "name": "Sidebar aria-label",
      "type": "string",
      "default": "\"Sidebar\"",
      "description": "Name of the nav landmark, and of the sheet on mobile."
    },
    {
      "name": "SidebarMenuButton href / render",
      "type": "string / ReactElement",
      "description": "With href the row is an <a>; or pass render={<Link href=\"…\" />}. Otherwise a <button>."
    },
    {
      "name": "SidebarMenuButton isActive",
      "type": "boolean",
      "default": "false",
      "description": "The current page: aria-current=\"page\" and the selected tint."
    },
    {
      "name": "SidebarMenuButton tooltip",
      "type": "ReactNode",
      "description": "Shown on the right while the sidebar is icon-only."
    },
    {
      "name": "SidebarMenuButton size",
      "type": "\"md\" | \"lg\"",
      "default": "\"md\"",
      "description": "32px rows, or 48px rows with a 32px tile for the header and footer."
    },
    {
      "name": "SidebarMenuBadge tone",
      "type": "\"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\"",
      "default": "\"neutral\"",
      "description": "A plain mono count at the end of a row, colored only when it carries meaning."
    },
    {
      "name": "SidebarCollapsibleGroup label / defaultOpen / open / onOpenChange",
      "type": "ReactNode / boolean / boolean / (open) => void",
      "default": "defaultOpen true",
      "description": "A group whose label toggles its menu. Stays open while icon-only."
    },
    {
      "name": "SidebarGroup / SidebarGroupLabel",
      "type": "ComponentProps<\"div\">",
      "description": "A role=\"group\" section named by its label."
    },
    {
      "name": "SidebarTrigger",
      "type": "ComponentProps<\"button\">",
      "description": "Collapses or expands on desktop and opens the sheet on mobile."
    },
    {
      "name": "useSidebar()",
      "type": "() => { collapsed, setCollapsed, mobile, mobileOpen, setMobileOpen, toggle }",
      "description": "Reads and changes the state from custom controls."
    }
  ],
  "accessibility": [
    "The sidebar is a nav landmark; groups are role=\"group\" named by their labels with aria-labelledby, and each menu is a list.",
    "The current page row has aria-current=\"page\" and reads by tint and weight, not color.",
    "Labels stay in the accessibility tree while icon-only (they are only faded), and each row shows its tooltip on hover or keyboard focus.",
    "SidebarTrigger reports aria-expanded, points at the sidebar with aria-controls, and lists the shortcut in aria-keyshortcuts. Cmd or Ctrl + B toggles it, except while typing in a field.",
    "Collapsible group toggles are buttons with aria-expanded; while icon-only they are disabled and hidden so focus does not land on invisible controls.",
    "On narrow layouts the sidebar is a modal sheet (Base UI Dialog): focus moves into it and is trapped, Escape or the backdrop closes it, and following a link closes it.",
    "Collapsing animates the column width in 220ms while labels fade in 150ms, so icons never move; the sheet slides in over 260ms and out in 180ms. All of it is instant with reduced motion."
  ],
  "states": [
    "expanded",
    "collapsed",
    "mobile-sheet"
  ],
  "files": [
    {
      "path": "ui/sidebar.tsx",
      "content": "\"use client\";\n\nimport { Collapsible } from \"@base-ui/react/collapsible\";\nimport { Dialog } from \"@base-ui/react/dialog\";\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\nimport {\n  type ComponentProps,\n  createContext,\n  type CSSProperties,\n  type MouseEvent,\n  type ReactNode,\n  useCallback,\n  useContext,\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n} from \"react\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"./tooltip\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst quint = \"ease-[cubic-bezier(0.22,1,0.36,1)]\";\nconst focusRing = \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\";\n\ninterface SidebarContextValue {\n  /** Whether the desktop sidebar shows icons only. */\n  collapsed: boolean;\n  setCollapsed: (collapsed: boolean) => void;\n  /** Whether the provider is narrower than `mobileBreakpoint`, so the sidebar lives in a sheet. */\n  mobile: boolean;\n  /** Whether the mobile sheet is open. */\n  mobileOpen: boolean;\n  setMobileOpen: (open: boolean) => void;\n  /** Collapses or expands on desktop; opens or closes the sheet on mobile. */\n  toggle: () => void;\n  /** Id of the sidebar element, for `aria-controls`. */\n  sidebarId: string;\n  shortcut: string | false;\n}\n\nconst SidebarContext = createContext<SidebarContextValue | null>(null);\n\n/** Reads the sidebar state from the nearest `SidebarProvider`, for custom triggers and layouts. */\nexport function useSidebar() {\n  const context = useContext(SidebarContext);\n  if (!context) throw new Error(\"useSidebar must be used inside a SidebarProvider.\");\n  return context;\n}\n\nexport interface SidebarProviderProps extends ComponentProps<\"div\"> {\n  /** Whether the sidebar shows icons only. Pass with `onCollapsedChange` to control it. */\n  collapsed?: boolean;\n  /** Initial collapsed state when uncontrolled. */\n  defaultCollapsed?: boolean;\n  /** Called when the sidebar collapses or expands. */\n  onCollapsedChange?: (collapsed: boolean) => void;\n  /**\n   * Below this width, in pixels, the sidebar moves into a sheet opened by `SidebarTrigger`.\n   * Measured on the provider itself, not the window, so it also works in a narrow pane.\n   */\n  mobileBreakpoint?: number;\n  /** Letter that toggles the sidebar with Cmd (macOS) or Ctrl. `false` turns the shortcut off. */\n  keyboardShortcut?: string | false;\n  /** Expanded width, as a CSS length. */\n  width?: string;\n  /** Icon-only width, as a CSS length. The default centers 16px icons in the column. */\n  collapsedWidth?: string;\n}\n\n/**\n * Holds the sidebar state and lays out a `Sidebar` beside a `SidebarInset`, its two direct children.\n * Collapsing animates the sidebar column (220ms, quint ease-out) while labels fade, so icons never\n * move; with reduced motion it switches instantly.\n */\nexport function SidebarProvider({\n  collapsed: collapsedProp,\n  defaultCollapsed = false,\n  onCollapsedChange,\n  mobileBreakpoint = 768,\n  keyboardShortcut = \"b\",\n  width = \"16rem\",\n  collapsedWidth = \"3.5rem\",\n  className,\n  style,\n  children,\n  ...props\n}: SidebarProviderProps) {\n  const [uncontrolled, setUncontrolled] = useState(defaultCollapsed);\n  const collapsed = collapsedProp ?? uncontrolled;\n  const [mobile, setMobile] = useState(false);\n  const [mobileOpen, setMobileOpen] = useState(false);\n  const wrapperRef = useRef<HTMLDivElement>(null);\n  const sidebarId = useId();\n\n  const setCollapsed = useCallback(\n    (next: boolean) => {\n      if (collapsedProp === undefined) setUncontrolled(next);\n      onCollapsedChange?.(next);\n    },\n    [collapsedProp, onCollapsedChange],\n  );\n\n  const toggle = useCallback(() => {\n    if (mobile) setMobileOpen((open) => !open);\n    else setCollapsed(!collapsed);\n  }, [mobile, collapsed, setCollapsed]);\n\n  useEffect(() => {\n    const wrapper = wrapperRef.current;\n    if (!wrapper) return;\n    const observer = new ResizeObserver(([entry]) => {\n      if (entry) setMobile(entry.contentRect.width < mobileBreakpoint);\n    });\n    observer.observe(wrapper);\n    return () => observer.disconnect();\n  }, [mobileBreakpoint]);\n\n  // Leaving mobile layout closes the sheet, so it is not open behind the desktop sidebar.\n  useEffect(() => {\n    if (!mobile) setMobileOpen(false);\n  }, [mobile]);\n\n  useEffect(() => {\n    if (!keyboardShortcut) return;\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key.toLowerCase() !== keyboardShortcut.toLowerCase() || !(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey) return;\n      const target = event.target as HTMLElement | null;\n      // Leave Cmd+B to text fields and editors, where it usually means bold.\n      if (target?.closest(\"input, textarea, select, [contenteditable=''], [contenteditable='true']\")) return;\n      event.preventDefault();\n      toggle();\n    };\n    window.addEventListener(\"keydown\", onKeyDown);\n    return () => window.removeEventListener(\"keydown\", onKeyDown);\n  }, [keyboardShortcut, toggle]);\n\n  const value = useMemo<SidebarContextValue>(\n    () => ({ collapsed, setCollapsed, mobile, mobileOpen, setMobileOpen, toggle, sidebarId, shortcut: keyboardShortcut }),\n    [collapsed, setCollapsed, mobile, mobileOpen, toggle, sidebarId, keyboardShortcut],\n  );\n\n  return (\n    <SidebarContext.Provider value={value}>\n      <div\n        ref={wrapperRef}\n        data-slot=\"sidebar-wrapper\"\n        data-collapsed={(collapsed && !mobile) || undefined}\n        data-mobile={mobile || undefined}\n        className={cx(\n          \"grid h-full min-h-0 w-full\",\n          mobile\n            ? \"grid-cols-[minmax(0,1fr)]\"\n            : cx(\n                \"grid-cols-[var(--sidebar-width)_minmax(0,1fr)] data-[collapsed]:grid-cols-[var(--sidebar-width-collapsed)_minmax(0,1fr)]\",\n                `transition-[grid-template-columns] duration-220 ${quint} motion-reduce:transition-none`,\n              ),\n          className,\n        )}\n        style={{ ...style, \"--sidebar-width\": width, \"--sidebar-width-collapsed\": collapsedWidth } as CSSProperties}\n        {...props}\n      >\n        {children}\n      </div>\n    </SidebarContext.Provider>\n  );\n}\n\nconst surface = \"bg-white text-zinc-950 dark:bg-black dark:text-white\";\n\nexport interface SidebarProps extends ComponentProps<\"nav\"> {\n  /** Accessible name of the navigation landmark and, on mobile, of the sheet. */\n  \"aria-label\"?: string;\n}\n\n/**\n * The sidebar column, a `<nav>` landmark holding `SidebarHeader`, `SidebarContent`, and\n * `SidebarFooter`. In the mobile layout the same children render in a sheet that slides in from\n * the left edge (260ms in, 180ms out); it traps focus, closes on Escape or a backdrop press, and\n * closes when a `SidebarMenuButton` is followed.\n */\nexport function Sidebar({ \"aria-label\": label = \"Sidebar\", className, children, ...props }: SidebarProps) {\n  const sidebar = useSidebar();\n  const sheetValue = useMemo(() => ({ ...sidebar, collapsed: false }), [sidebar]);\n\n  if (sidebar.mobile) {\n    return (\n      <Dialog.Root open={sidebar.mobileOpen} onOpenChange={sidebar.setMobileOpen}>\n        <Dialog.Portal>\n          <Dialog.Backdrop\n            className={cx(\n              \"fixed inset-0 z-50 bg-black/40 dark:bg-black/70\",\n              \"transition-opacity duration-260 ease-out motion-reduce:transition-none\",\n              \"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 data-[ending-style]:duration-180\",\n            )}\n          />\n          <Dialog.Popup\n            id={sidebar.sidebarId}\n            aria-label={label}\n            className={cx(\n              \"fixed inset-y-0 left-0 z-50 flex w-[min(18rem,calc(100vw-3rem))] flex-col outline-none\",\n              surface,\n              \"border-r border-zinc-950/10 shadow-[0_12px_32px_-8px_rgb(0_0_0/0.25)] dark:border-white/15 dark:shadow-[0_16px_48px_-12px_rgb(0_0_0/1)]\",\n              `transition-[translate,opacity] duration-260 ${quint} motion-reduce:transition-none`,\n              \"data-[starting-style]:-translate-x-full\",\n              // Exit is quicker and only partly slides, so the sheet gets out of the way.\n              \"data-[ending-style]:-translate-x-1/2 data-[ending-style]:opacity-0 data-[ending-style]:duration-180 data-[ending-style]:ease-out\",\n              \"motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0\",\n            )}\n          >\n            <SidebarContext.Provider value={sheetValue}>\n              <nav aria-label={label} className={cx(\"flex min-h-0 flex-1 flex-col\", className)} {...props}>\n                {children}\n              </nav>\n            </SidebarContext.Provider>\n          </Dialog.Popup>\n        </Dialog.Portal>\n      </Dialog.Root>\n    );\n  }\n\n  return (\n    <nav\n      id={sidebar.sidebarId}\n      aria-label={label}\n      data-slot=\"sidebar\"\n      data-collapsed={sidebar.collapsed || undefined}\n      className={cx(\n        \"group/sidebar flex min-h-0 min-w-0 flex-col overflow-hidden border-r border-zinc-950/10 dark:border-white/10\",\n        surface,\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </nav>\n  );\n}\n\n/** Top of the sidebar, usually a workspace switcher. Stays put while the content scrolls. */\nexport function SidebarHeader({ className, ...props }: ComponentProps<\"div\">) {\n  return <div className={cx(\"flex shrink-0 flex-col gap-1 p-2\", className)} {...props} />;\n}\n\n/** Bottom of the sidebar, usually the signed-in account. Separated by a hairline. */\nexport function SidebarFooter({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div className={cx(\"flex shrink-0 flex-col gap-1 border-t border-zinc-950/[0.07] p-2 dark:border-white/[0.08]\", className)} {...props} />\n  );\n}\n\n/** The scrolling middle of the sidebar, holding groups of menus. */\nexport function SidebarContent({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      className={cx(\n        \"flex min-h-0 flex-1 flex-col gap-3 overflow-x-hidden overflow-y-auto overscroll-contain px-2 py-1 [scrollbar-width:thin]\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** A hairline between sections. */\nexport function SidebarSeparator({ className, ...props }: ComponentProps<\"hr\">) {\n  return <hr className={cx(\"mx-2 my-1 h-px shrink-0 border-0 bg-zinc-950/[0.07] dark:bg-white/[0.08]\", className)} {...props} />;\n}\n\nconst GroupLabelContext = createContext<string | undefined>(undefined);\n\n/** A labelled section of the sidebar. Put a `SidebarGroupLabel` and a `SidebarMenu` inside. */\nexport function SidebarGroup({ className, ...props }: ComponentProps<\"div\">) {\n  const labelId = useId();\n  return (\n    <GroupLabelContext.Provider value={labelId}>\n      <div role=\"group\" aria-labelledby={labelId} className={cx(\"flex min-w-0 flex-col\", className)} {...props} />\n    </GroupLabelContext.Provider>\n  );\n}\n\n// In icon-only mode the label fades out and a short hairline fades in at the same height,\n// so the icons below keep their position.\nconst labelRow = cx(\n  \"relative flex h-8 min-w-0 shrink-0 items-center rounded-lg px-3 text-xs font-medium whitespace-nowrap text-zinc-500\",\n  \"before:pointer-events-none before:absolute before:inset-x-3 before:top-1/2 before:h-px before:bg-zinc-950/10 before:opacity-0 dark:before:bg-white/15\",\n  \"before:transition-opacity before:duration-150 before:ease-out group-data-[collapsed]/sidebar:before:opacity-100 motion-reduce:before:transition-none\",\n);\nconst labelText = cx(\n  \"truncate transition-[opacity,visibility] duration-150 ease-out motion-reduce:transition-none\",\n  \"group-data-[collapsed]/sidebar:invisible group-data-[collapsed]/sidebar:opacity-0\",\n);\n\n/** Names a `SidebarGroup`. Replaced by a short hairline while the sidebar is icon-only. */\nexport function SidebarGroupLabel({ className, children, ...props }: ComponentProps<\"div\">) {\n  const id = useContext(GroupLabelContext);\n  return (\n    <div id={id} className={cx(labelRow, className)} {...props}>\n      <span className={labelText}>{children}</span>\n    </div>\n  );\n}\n\nexport interface SidebarCollapsibleGroupProps extends Omit<Collapsible.Root.Props, \"className\" | \"children\"> {\n  /** Text of the group's toggle. */\n  label: ReactNode;\n  className?: string;\n  /** The group's `SidebarMenu`. */\n  children?: ReactNode;\n}\n\n/**\n * A group whose label toggles its menu open and closed. The menu height animates in 220ms\n * (instant with reduced motion). While the sidebar is icon-only the group stays open, since its\n * toggle is hidden.\n */\nexport function SidebarCollapsibleGroup({ label, defaultOpen = true, open, onOpenChange, className, children, ...props }: SidebarCollapsibleGroupProps) {\n  const { collapsed } = useSidebar();\n  const [innerOpen, setInnerOpen] = useState(open ?? defaultOpen);\n  const isOpen = open ?? innerOpen;\n\n  return (\n    <Collapsible.Root\n      open={collapsed || isOpen}\n      onOpenChange={(next, details) => {\n        if (collapsed) return;\n        setInnerOpen(next);\n        onOpenChange?.(next, details);\n      }}\n      className={cx(\"flex min-w-0 flex-col\", className)}\n      {...props}\n    >\n      <Collapsible.Trigger\n        disabled={collapsed}\n        className={cx(\n          labelRow,\n          \"group/trigger w-full cursor-pointer gap-1 text-left\",\n          \"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n          \"hover:bg-zinc-950/[0.04] hover:text-zinc-700 dark:hover:bg-white/[0.06] dark:hover:text-zinc-300\",\n          \"group-data-[collapsed]/sidebar:pointer-events-none\",\n          focusRing,\n        )}\n      >\n        <span className={labelText}>{label}</span>\n        <svg\n          aria-hidden=\"true\"\n          viewBox=\"0 0 16 16\"\n          fill=\"none\"\n          className={cx(\n            \"size-3 shrink-0 -rotate-90 group-data-[panel-open]/trigger:rotate-0\",\n            `transition-[rotate,opacity,visibility] duration-200 ${quint} motion-reduce:transition-none`,\n            \"group-data-[collapsed]/sidebar:invisible group-data-[collapsed]/sidebar:opacity-0\",\n          )}\n        >\n          <path d=\"m4.5 6.25 3.5 3.5 3.5-3.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n        </svg>\n      </Collapsible.Trigger>\n      <Collapsible.Panel\n        className={cx(\n          \"h-(--collapsible-panel-height) overflow-hidden\",\n          `transition-[height,opacity] duration-220 ${quint} motion-reduce:transition-none`,\n          \"data-[starting-style]:h-0 data-[starting-style]:opacity-0\",\n          \"data-[ending-style]:h-0 data-[ending-style]:opacity-0 data-[ending-style]:duration-180\",\n        )}\n      >\n        {children}\n      </Collapsible.Panel>\n    </Collapsible.Root>\n  );\n}\n\n/** A list of `SidebarMenuItem`s. */\nexport function SidebarMenu({ className, ...props }: ComponentProps<\"ul\">) {\n  return <ul className={cx(\"m-0 flex min-w-0 list-none flex-col gap-px p-0\", className)} {...props} />;\n}\n\n/** Wraps one `SidebarMenuButton`. */\nexport function SidebarMenuItem({ className, ...props }: ComponentProps<\"li\">) {\n  return <li className={cx(\"relative flex min-w-0\", className)} {...props} />;\n}\n\nconst buttonSizes = {\n  /** A 32px row: icon, label, optional badge. */\n  md: \"h-8 gap-2.5 px-3 text-sm\",\n  /** A 48px row for the header and footer: a 32px tile and two lines of text. */\n  lg: \"h-12 gap-2.5 px-1 text-sm\",\n} as const;\n\nexport interface SidebarMenuButtonProps extends Omit<useRender.ComponentProps<\"button\">, \"children\"> {\n  /** Destination. With `href` the button renders an `<a>`; or pass `render={<Link href=\"…\" />}`. */\n  href?: string;\n  /** Marks the current page: sets `aria-current=\"page\"` and the selected tint. */\n  isActive?: boolean;\n  /** Row height. `lg` suits a workspace switcher or account row. */\n  size?: keyof typeof buttonSizes;\n  /** Text of the tooltip shown beside the icon while the sidebar is icon-only. */\n  tooltip?: ReactNode;\n  /** A leading icon or tile, then the label wrapped in a `<span>` (so it can fade), then an optional `SidebarMenuBadge`. */\n  children?: ReactNode;\n}\n\n/**\n * A navigation row. Hover and the current page are shown with tints only (no moving indicator).\n * While the sidebar is icon-only, the label and badge fade out, the icon stays where it was, and\n * hovering or focusing the row shows `tooltip` on the right.\n */\nexport function SidebarMenuButton({\n  href,\n  isActive = false,\n  size = \"md\",\n  tooltip,\n  render,\n  className,\n  onClick,\n  ...props\n}: SidebarMenuButtonProps) {\n  const sidebar = useSidebar();\n  const asLink = href !== undefined;\n\n  const element = useRender({\n    defaultTagName: asLink ? \"a\" : \"button\",\n    render,\n    props: mergeProps<\"button\">(\n      {\n        ...(asLink ? { href } : { type: \"button\" }),\n        \"aria-current\": isActive ? \"page\" : undefined,\n        className: cx(\n          \"flex w-full min-w-0 items-center overflow-hidden rounded-lg text-left whitespace-nowrap no-underline outline-none select-none\",\n          buttonSizes[size],\n          \"text-zinc-600 dark:text-zinc-400\",\n          \"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n          \"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n          \"aria-[current=page]:bg-zinc-950/[0.06] aria-[current=page]:font-medium aria-[current=page]:text-zinc-950\",\n          \"dark:aria-[current=page]:bg-white/[0.09] dark:aria-[current=page]:text-white\",\n          \"data-[popup-open]:bg-zinc-950/[0.04] dark:data-[popup-open]:bg-white/[0.06]\",\n          focusRing,\n          \"[&_svg]:size-4 [&_svg]:shrink-0\",\n          // Everything after the leading icon or tile (label, badge) is a span that fades while icon-only.\n          // Opacity only: the label must stay in the accessibility tree as the row's name.\n          \"[&>span:not(:first-child)]:transition-opacity [&>span:not(:first-child)]:duration-150 [&>span:not(:first-child)]:ease-out\",\n          \"motion-reduce:[&>span:not(:first-child)]:transition-none\",\n          \"group-data-[collapsed]/sidebar:[&>span:not(:first-child)]:opacity-0\",\n          className,\n        ),\n        onClick: (event: MouseEvent<HTMLButtonElement>) => {\n          onClick?.(event);\n          if (sidebar.mobile && sidebar.mobileOpen && !event.defaultPrevented && asLink) sidebar.setMobileOpen(false);\n        },\n      },\n      props,\n    ),\n  });\n\n  if (!tooltip) return element;\n  return (\n    <Tooltip disabled={!sidebar.collapsed}>\n      <TooltipTrigger render={element} delay={0} />\n      <TooltipContent side=\"right\" sideOffset={10} arrow={false}>\n        {tooltip}\n      </TooltipContent>\n    </Tooltip>\n  );\n}\n\nconst badgeTones = {\n  neutral: \"text-zinc-500\",\n  info: \"text-sky-600 dark:text-sky-400\",\n  success: \"text-emerald-600 dark:text-emerald-400\",\n  warning: \"text-amber-600 dark:text-amber-400\",\n  danger: \"text-red-600 dark:text-red-400\",\n} as const;\n\nexport interface SidebarMenuBadgeProps extends ComponentProps<\"span\"> {\n  /** Colors the count when it carries meaning, for example `warning` for approvals waiting on someone. */\n  tone?: keyof typeof badgeTones;\n}\n\n/**\n * A count at the end of a row, set in mono with tabular figures. Plain text rather than a pill,\n * so a long menu does not turn into a column of badges. Include context for screen readers when\n * the number alone is unclear, for example with a visually hidden \"waiting\".\n */\nexport function SidebarMenuBadge({ tone = \"neutral\", className, ...props }: SidebarMenuBadgeProps) {\n  return <span className={cx(\"ml-auto pl-2 font-mono text-xs font-normal tabular-nums\", badgeTones[tone], className)} {...props} />;\n}\n\nexport interface SidebarTriggerProps extends ComponentProps<\"button\"> {\n  /** Accessible name. */\n  \"aria-label\"?: string;\n}\n\n/**\n * Collapses and expands the sidebar on desktop, and opens the sheet on mobile. Announces its state\n * with `aria-expanded` and the keyboard shortcut with `aria-keyshortcuts`.\n */\nexport function SidebarTrigger({ \"aria-label\": label = \"Toggle sidebar\", className, onClick, children, ...props }: SidebarTriggerProps) {\n  const sidebar = useSidebar();\n  const expanded = sidebar.mobile ? sidebar.mobileOpen : !sidebar.collapsed;\n  const shortcut = sidebar.shortcut ? sidebar.shortcut.toUpperCase() : null;\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      aria-expanded={expanded}\n      aria-controls={sidebar.mobile && !sidebar.mobileOpen ? undefined : sidebar.sidebarId}\n      aria-keyshortcuts={shortcut ? `Meta+${shortcut} Control+${shortcut}` : undefined}\n      className={cx(\n        \"inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-zinc-500\",\n        \"transition-[background-color,color,scale] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.94] motion-reduce:transition-none\",\n        \"hover:bg-zinc-950/[0.05] hover:text-zinc-950 dark:hover:bg-white/[0.08] dark:hover:text-white\",\n        \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n        className,\n      )}\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) sidebar.toggle();\n      }}\n      {...props}\n    >\n      {children ?? (\n        <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-4\">\n          <rect x=\"2.25\" y=\"2.75\" width=\"11.5\" height=\"10.5\" rx=\"2\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n          <path d=\"M6.25 3v10\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n        </svg>\n      )}\n    </button>\n  );\n}\n\n/** The main area beside the sidebar. Render your page header and content inside. */\nexport function SidebarInset({ className, ...props }: ComponentProps<\"div\">) {\n  return <div className={cx(\"flex min-h-0 min-w-0 flex-col\", className)} {...props} />;\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport {\n  Sidebar,\n  SidebarCollapsibleGroup,\n  SidebarContent,\n  SidebarFooter,\n  SidebarGroup,\n  SidebarGroupLabel,\n  SidebarHeader,\n  SidebarInset,\n  SidebarMenu,\n  SidebarMenuBadge,\n  SidebarMenuButton,\n  SidebarMenuItem,\n  SidebarProvider,\n  SidebarTrigger,\n} from \"@/components/shaken/ui/sidebar\";\n\nconst icon = { \"aria-hidden\": true, viewBox: \"0 0 16 16\", fill: \"none\" } as const;\nconst stroke = { stroke: \"currentColor\", strokeWidth: 1.5, strokeLinecap: \"round\", strokeLinejoin: \"round\" } as const;\n\nconst icons = {\n  inbox: (\n    <svg {...icon}>\n      <path d=\"M2.75 9.25 4.4 3.9a1 1 0 0 1 .96-.65h5.28a1 1 0 0 1 .96.65l1.65 5.35v2.5a1 1 0 0 1-1 1h-8.5a1 1 0 0 1-1-1z\" {...stroke} />\n      <path d=\"M2.75 9.25h3l.75 1.5h3l.75-1.5h3\" {...stroke} />\n    </svg>\n  ),\n  runs: (\n    <svg {...icon}>\n      <path d=\"M4.5 3.25v9.5L12.5 8z\" {...stroke} />\n    </svg>\n  ),\n  approvals: (\n    <svg {...icon}>\n      <circle cx=\"8\" cy=\"8\" r=\"5.25\" {...stroke} />\n      <path d=\"M6.6 6.1v3.8M9.4 6.1v3.8\" {...stroke} />\n    </svg>\n  ),\n  artifacts: (\n    <svg {...icon}>\n      <path d=\"M4.25 2.75h5l2.5 2.5v7a1 1 0 0 1-1 1h-6.5a1 1 0 0 1-1-1v-8.5a1 1 0 0 1 1-1z\" {...stroke} />\n      <path d=\"M9 2.75v2.75h2.75\" {...stroke} />\n    </svg>\n  ),\n  integrations: (\n    <svg {...icon}>\n      <path d=\"M6 2.75v2.5M10 2.75v2.5M4.5 5.25h7v2.5a3.5 3.5 0 0 1-7 0zM8 11.25v2\" {...stroke} />\n    </svg>\n  ),\n  members: (\n    <svg {...icon}>\n      <circle cx=\"6\" cy=\"5.75\" r=\"2.25\" {...stroke} />\n      <path d=\"M2.25 12.75c.5-1.9 1.9-3 3.75-3s3.25 1.1 3.75 3M10.5 3.75a2.25 2.25 0 0 1 0 4.25M11.75 9.9c1 .4 1.7 1.4 2 2.85\" {...stroke} />\n    </svg>\n  ),\n  billing: (\n    <svg {...icon}>\n      <rect x=\"2.25\" y=\"3.75\" width=\"11.5\" height=\"8.5\" rx=\"1.5\" {...stroke} />\n      <path d=\"M2.25 6.75h11.5M4.75 9.75h2\" {...stroke} />\n    </svg>\n  ),\n};\n\nconst workspace = [\n  { key: \"inbox\", label: \"Inbox\", count: 4 },\n  { key: \"runs\", label: \"Runs\" },\n  { key: \"approvals\", label: \"Approvals\", count: 2, tone: \"warning\" as const },\n  { key: \"artifacts\", label: \"Artifacts\" },\n] as const;\n\nconst settings = [\n  { key: \"integrations\", label: \"Integrations\" },\n  { key: \"members\", label: \"Members\" },\n  { key: \"billing\", label: \"Billing\" },\n] as const;\n\ntype Page = (typeof workspace)[number][\"key\"] | (typeof settings)[number][\"key\"];\n\nexport default function SidebarExample() {\n  const [page, setPage] = useState<Page>(\"runs\");\n  const title = [...workspace, ...settings].find((item) => item.key === page)?.label;\n\n  return (\n    <div className=\"h-[30rem] w-full max-w-3xl overflow-hidden rounded-xl border border-zinc-950/10 bg-white dark:border-white/10 dark:bg-black\">\n      <SidebarProvider mobileBreakpoint={600}>\n        <Sidebar aria-label=\"Workspace\">\n          <SidebarHeader>\n            <SidebarMenu>\n              <SidebarMenuItem>\n                <SidebarMenuButton size=\"lg\" tooltip=\"Northwind\">\n                  <span className=\"flex size-8 shrink-0 items-center justify-center rounded-lg bg-zinc-950 text-xs font-semibold text-white dark:bg-white dark:text-black\">\n                    N\n                  </span>\n                  <span className=\"flex min-w-0 flex-col leading-tight\">\n                    <span className=\"truncate font-medium text-zinc-950 dark:text-white\">Northwind</span>\n                    <span className=\"truncate text-xs text-zinc-500\">Team plan</span>\n                  </span>\n                </SidebarMenuButton>\n              </SidebarMenuItem>\n            </SidebarMenu>\n          </SidebarHeader>\n\n          <SidebarContent>\n            <SidebarGroup>\n              <SidebarGroupLabel>Workspace</SidebarGroupLabel>\n              <SidebarMenu>\n                {workspace.map((item) => (\n                  <SidebarMenuItem key={item.key}>\n                    <SidebarMenuButton isActive={page === item.key} tooltip={item.label} onClick={() => setPage(item.key)}>\n                      {icons[item.key]}\n                      <span className=\"truncate\">{item.label}</span>\n                      {\"count\" in item ? (\n                        <SidebarMenuBadge tone={\"tone\" in item ? item.tone : \"neutral\"}>\n                          {item.count}\n                          <span className=\"sr-only\"> {item.key === \"approvals\" ? \"waiting\" : \"unread\"}</span>\n                        </SidebarMenuBadge>\n                      ) : null}\n                    </SidebarMenuButton>\n                  </SidebarMenuItem>\n                ))}\n              </SidebarMenu>\n            </SidebarGroup>\n\n            <SidebarCollapsibleGroup label=\"Settings\">\n              <SidebarMenu>\n                {settings.map((item) => (\n                  <SidebarMenuItem key={item.key}>\n                    <SidebarMenuButton isActive={page === item.key} tooltip={item.label} onClick={() => setPage(item.key)}>\n                      {icons[item.key]}\n                      <span className=\"truncate\">{item.label}</span>\n                    </SidebarMenuButton>\n                  </SidebarMenuItem>\n                ))}\n              </SidebarMenu>\n            </SidebarCollapsibleGroup>\n          </SidebarContent>\n\n          <SidebarFooter>\n            <SidebarMenu>\n              <SidebarMenuItem>\n                <SidebarMenuButton size=\"lg\" tooltip=\"Maya Chen\">\n                  <span className=\"flex size-8 shrink-0 items-center justify-center rounded-full border border-zinc-950/10 text-xs font-medium text-zinc-600 dark:border-white/15 dark:text-zinc-300\">\n                    MC\n                  </span>\n                  <span className=\"flex min-w-0 flex-col leading-tight\">\n                    <span className=\"truncate font-medium text-zinc-950 dark:text-white\">Maya Chen</span>\n                    <span className=\"truncate text-xs text-zinc-500\">maya@northwind.dev</span>\n                  </span>\n                </SidebarMenuButton>\n              </SidebarMenuItem>\n            </SidebarMenu>\n          </SidebarFooter>\n        </Sidebar>\n\n        <SidebarInset>\n          <header className=\"flex h-12 shrink-0 items-center gap-2 border-b border-zinc-950/[0.07] px-3 dark:border-white/[0.08]\">\n            <SidebarTrigger />\n            <span className=\"h-4 w-px bg-zinc-950/10 dark:bg-white/15\" aria-hidden=\"true\" />\n            <h2 className=\"m-0 text-sm font-semibold text-zinc-950 dark:text-white\">{title}</h2>\n          </header>\n          <div className=\"flex flex-1 flex-col gap-2 overflow-auto p-4\">\n            <p className=\"m-0 text-sm text-zinc-600 dark:text-zinc-400\">\n              Press the panel button or <kbd className=\"font-mono text-xs\">⌘B</kbd> to switch between the full sidebar and icons only.\n            </p>\n            <div className=\"mt-2 grid gap-2 sm:grid-cols-2\">\n              {[\"Fix invoice rounding\", \"Upgrade to React 19\", \"Nightly evaluation\", \"Rotate API keys\"].map((name) => (\n                <div key={name} className=\"rounded-lg border border-zinc-950/[0.07] px-3 py-2.5 text-sm text-zinc-700 dark:border-white/[0.08] dark:text-zinc-300\">\n                  {name}\n                </div>\n              ))}\n            </div>\n          </div>\n        </SidebarInset>\n      </SidebarProvider>\n    </div>\n  );\n}\n"
  }
}
