{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-nav",
  "type": "registry:component",
  "title": "Sidebar Nav",
  "description": "A collapsible app sidebar with a sliding active indicator, badges and icon-only tooltips.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "navigation",
    "collapse",
    "app shell"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-nav",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-nav.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-nav.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SidebarNavItem {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  badge?: string | number;\n  href?: string;\n}\n\nexport interface SidebarNavGroup {\n  label?: string;\n  items: SidebarNavItem[];\n}\n\nexport interface SidebarNavProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  groups: SidebarNavGroup[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  collapsed?: boolean;\n  defaultCollapsed?: boolean;\n  onCollapsedChange?: (collapsed: boolean) => void;\n  width?: number;\n  brand?: React.ReactNode;\n  footer?: React.ReactNode;\n  color?: string;\n}\n\nconst css = `\n.hb-sb {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: var(--hb-sb-w, 240px);\n  height: 100%;\n  min-height: 0;\n  border-right: 1px solid #262626;\n  background: #111111;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  font-size: 13px;\n  transition: width .3s cubic-bezier(.2, .9, .2, 1);\n  --hb-sb-accent: #2f7bff;\n}\n.hb-sb[data-collapsed=\"true\"] { width: 64px; }\n.hb-sb-head {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 8px;\n  box-sizing: border-box;\n  height: var(--hb-sb-headh, 52px);\n  padding: 0 12px 0 16px;\n  flex: none;\n}\n.hb-sb[data-collapsed=\"true\"] .hb-sb-head { justify-content: center; padding: 0 12px; }\n.hb-sb-brand {\n  display: flex;\n  flex: 1;\n  align-items: center;\n  min-width: 0;\n  max-width: 100%;\n  overflow: hidden;\n  font-weight: 600;\n  white-space: nowrap;\n  transition: opacity .2s ease, max-width .3s cubic-bezier(.2, .9, .2, 1);\n}\n.hb-sb[data-collapsed=\"true\"] .hb-sb-brand { flex: none; max-width: 0; opacity: 0; pointer-events: none; }\n.hb-sb-toggle {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #8f8f8f;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-sb-toggle:hover { background: #1f1f1f; color: #ededed; }\n.hb-sb-toggle:focus-visible { outline: 2px solid var(--hb-sb-accent); outline-offset: 1px; }\n.hb-sb-toggle svg { width: 16px; height: 16px; transition: transform .3s cubic-bezier(.2, .9, .2, 1); }\n.hb-sb[data-collapsed=\"true\"] .hb-sb-toggle svg { transform: rotate(180deg); }\n.hb-sb-nav {\n  position: relative;\n  display: flex;\n  flex: 1;\n  flex-direction: column;\n  gap: 14px;\n  min-height: 0;\n  padding: 6px 12px;\n}\n.hb-sb-ind {\n  position: absolute;\n  top: 0;\n  left: 12px;\n  right: 12px;\n  height: var(--hb-sb-ih, 0px);\n  border-radius: 8px;\n  background: #1f1f1f;\n  opacity: 0;\n  pointer-events: none;\n  transform: translate3d(0, var(--hb-sb-iy, 0px), 0);\n  transition: transform .32s cubic-bezier(.2, .9, .2, 1), height .32s cubic-bezier(.2, .9, .2, 1), opacity .2s ease;\n}\n.hb-sb-ind::before {\n  content: \"\";\n  position: absolute;\n  left: -12px;\n  top: 8px;\n  bottom: 8px;\n  width: 3px;\n  border-radius: 0 3px 3px 0;\n  background: var(--hb-sb-accent);\n}\n.hb-sb-ind[data-ready=\"true\"] { opacity: 1; }\n.hb-sb-group { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }\n.hb-sb-glabel {\n  height: 18px;\n  padding: 0 10px;\n  overflow: hidden;\n  color: #8f8f8f;\n  font-size: 11px;\n  font-weight: 500;\n  letter-spacing: .04em;\n  line-height: 18px;\n  text-transform: uppercase;\n  white-space: nowrap;\n  transition: opacity .2s ease;\n}\n.hb-sb[data-collapsed=\"true\"] .hb-sb-glabel { opacity: 0; }\n.hb-sb-item {\n  position: relative;\n  z-index: 1;\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  box-sizing: border-box;\n  width: 100%;\n  height: var(--hb-sb-row, 36px);\n  margin: 0;\n  padding: 0 10px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-weight: 500;\n  text-align: left;\n  text-decoration: none;\n  cursor: pointer;\n  transition: color .15s ease, background-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-sb-item:hover { color: #ededed; background: rgba(255, 255, 255, .04); }\n.hb-sb-item[aria-current=\"page\"] { color: #ededed; background: transparent; }\n.hb-sb-item:focus-visible { outline: 2px solid var(--hb-sb-accent); outline-offset: -2px; }\n.hb-sb-ico { display: grid; flex: none; place-items: center; width: 20px; height: 20px; }\n.hb-sb-ico svg { width: 18px; height: 18px; }\n.hb-sb-letter {\n  display: grid;\n  place-items: center;\n  width: 18px;\n  height: 18px;\n  border: 1px solid currentColor;\n  border-radius: 5px;\n  font-size: 10px;\n  line-height: 1;\n}\n.hb-sb-label {\n  flex: 1;\n  min-width: 0;\n  max-width: 200px;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n  transition: opacity .2s ease, max-width .3s cubic-bezier(.2, .9, .2, 1);\n}\n.hb-sb[data-collapsed=\"true\"] .hb-sb-label { flex: none; max-width: 0; opacity: 0; }\n.hb-sb[data-collapsed=\"true\"] .hb-sb-item { gap: 0; }\n.hb-sb-badge {\n  flex: none;\n  min-width: 18px;\n  padding: 0 6px;\n  border-radius: 999px;\n  background: #262626;\n  color: #ededed;\n  font-size: 11px;\n  font-weight: 500;\n  line-height: 18px;\n  text-align: center;\n  transition: opacity .2s ease;\n}\n.hb-sb-item[aria-current=\"page\"] .hb-sb-badge { background: var(--hb-sb-accent); color: #ffffff; }\n.hb-sb[data-collapsed=\"true\"] .hb-sb-badge {\n  position: absolute;\n  top: 6px;\n  right: 6px;\n  min-width: 8px;\n  height: 8px;\n  padding: 0;\n  overflow: hidden;\n  border: 2px solid #111111;\n  box-sizing: content-box;\n  background: var(--hb-sb-accent);\n  font-size: 0;\n  line-height: 0;\n  color: transparent;\n}\n.hb-sb-tip {\n  position: absolute;\n  top: 50%;\n  left: calc(100% + 12px);\n  z-index: 20;\n  padding: 5px 9px;\n  border: 1px solid #262626;\n  border-radius: 8px;\n  background: #171717;\n  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);\n  color: #ededed;\n  font-size: 12px;\n  line-height: 16px;\n  white-space: nowrap;\n  opacity: 0;\n  pointer-events: none;\n  transform: translate3d(-4px, -50%, 0);\n  transition: opacity .15s ease, transform .15s ease;\n  visibility: hidden;\n}\n.hb-sb[data-collapsed=\"true\"] .hb-sb-item:hover .hb-sb-tip,\n.hb-sb[data-collapsed=\"true\"] .hb-sb-item:focus-visible .hb-sb-tip {\n  opacity: 1;\n  transform: translate3d(0, -50%, 0);\n  visibility: visible;\n}\n.hb-sb-foot {\n  flex: none;\n  box-sizing: border-box;\n  max-width: 100%;\n  padding: 12px;\n  overflow: hidden;\n  border-top: 1px solid #262626;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-sb, .hb-sb-brand, .hb-sb-toggle, .hb-sb-toggle svg, .hb-sb-ind, .hb-sb-glabel,\n  .hb-sb-item, .hb-sb-label, .hb-sb-badge, .hb-sb-tip { transition: none; }\n}\n`;\n\nfunction ChevronsIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M9.5 4L5.5 8l4 4\" />\n    </svg>\n  );\n}\n\nexport function SidebarNav({\n  groups,\n  active,\n  defaultActive,\n  onChange,\n  collapsed,\n  defaultCollapsed = false,\n  onCollapsedChange,\n  width = 240,\n  brand,\n  footer,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SidebarNavProps) {\n  const navRef = React.useRef<HTMLElement>(null);\n  const indRef = React.useRef<HTMLSpanElement>(null);\n  const itemRefs = React.useRef<Map<string, HTMLElement>>(new Map());\n  const placedRef = React.useRef(false);\n  const all = React.useMemo(() => groups.flatMap((g) => g.items), [groups]);\n  const [innerActive, setInnerActive] = React.useState(defaultActive ?? all[0]?.id ?? \"\");\n  const [innerCollapsed, setInnerCollapsed] = React.useState(defaultCollapsed);\n  const [focusId, setFocusId] = React.useState(\"\");\n  const current = active ?? innerActive;\n  const isCollapsed = collapsed ?? innerCollapsed;\n  const currentRef = React.useRef(current);\n\n  const place = React.useCallback((instant: boolean) => {\n    const ind = indRef.current;\n    if (!ind) return;\n    const el = itemRefs.current.get(currentRef.current);\n    if (!el) {\n      ind.dataset.ready = \"false\";\n      return;\n    }\n    if (instant) ind.style.transition = \"none\";\n    ind.style.setProperty(\"--hb-sb-ih\", `${el.offsetHeight}px`);\n    ind.style.setProperty(\"--hb-sb-iy\", `${el.offsetTop}px`);\n    ind.dataset.ready = \"true\";\n    if (instant) {\n      void ind.offsetHeight;\n      ind.style.transition = \"\";\n    }\n  }, []);\n\n  React.useEffect(() => {\n    currentRef.current = current;\n    place(!placedRef.current);\n    placedRef.current = true;\n  }, [current, groups, place]);\n\n  React.useEffect(() => {\n    const nav = navRef.current;\n    if (!nav) return;\n    const update = () => place(true);\n    if (typeof ResizeObserver === \"undefined\") {\n      window.addEventListener(\"resize\", update);\n      return () => window.removeEventListener(\"resize\", update);\n    }\n    const ro = new ResizeObserver(update);\n    ro.observe(nav);\n    return () => ro.disconnect();\n  }, [place]);\n\n  function select(id: string) {\n    if (active === undefined) setInnerActive(id);\n    onChange?.(id);\n  }\n\n  function toggle() {\n    const next = !isCollapsed;\n    if (collapsed === undefined) setInnerCollapsed(next);\n    onCollapsedChange?.(next);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    if (all.length === 0) return;\n    const ids = all.map((i) => i.id);\n    const here = ids.indexOf(focusId);\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = here < 0 ? 0 : Math.min(ids.length - 1, here + 1);\n    else if (e.key === \"ArrowUp\") next = here < 0 ? ids.length - 1 : Math.max(0, here - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = ids.length - 1;\n    if (next < 0) return;\n    e.preventDefault();\n    itemRefs.current.get(ids[next])?.focus();\n  }\n\n  const tabStop = all.some((i) => i.id === focusId)\n    ? focusId\n    : all.some((i) => i.id === current)\n      ? current\n      : all[0]?.id;\n\n  const vars = { \"--hb-sb-w\": `${width}px`, \"--hb-sb-accent\": color, ...style } as React.CSSProperties;\n\n  return (\n    <aside className={`hb-sb ${className}`} data-collapsed={isCollapsed} style={vars} {...rest}>\n      <style href=\"hb-sidebar-nav\" precedence=\"default\">{css}</style>\n      <div className=\"hb-sb-head\">\n        {brand ? <div className=\"hb-sb-brand\">{brand}</div> : null}\n        <button\n          type=\"button\"\n          className=\"hb-sb-toggle\"\n          aria-label={isCollapsed ? \"Expand sidebar\" : \"Collapse sidebar\"}\n          aria-expanded={!isCollapsed}\n          onClick={toggle}\n        >\n          <ChevronsIcon />\n        </button>\n      </div>\n      <nav ref={navRef} className=\"hb-sb-nav\" aria-label=\"Main\" onKeyDown={handleKeyDown}>\n        <span ref={indRef} className=\"hb-sb-ind\" aria-hidden=\"true\" />\n        {groups.map((group, gi) => (\n          <div key={group.label ?? gi}>\n            {group.label ? <div className=\"hb-sb-glabel\">{group.label}</div> : null}\n            <ul className=\"hb-sb-group\" role=\"list\">\n              {group.items.map((item) => {\n                const selected = item.id === current;\n                const setRef = (el: HTMLElement | null) => {\n                  if (el) itemRefs.current.set(item.id, el);\n                  else itemRefs.current.delete(item.id);\n                };\n                const content = (\n                  <>\n                    <span className=\"hb-sb-ico\" aria-hidden=\"true\">\n                      {item.icon ?? <span className=\"hb-sb-letter\">{item.label.charAt(0).toUpperCase()}</span>}\n                    </span>\n                    <span className=\"hb-sb-label\">{item.label}</span>\n                    {item.badge !== undefined && item.badge !== \"\" ? (\n                      <span className=\"hb-sb-badge\">{item.badge}</span>\n                    ) : null}\n                    <span className=\"hb-sb-tip\" aria-hidden=\"true\">\n                      {item.label}\n                    </span>\n                  </>\n                );\n                const common = {\n                  className: \"hb-sb-item\",\n                  \"aria-current\": selected ? (\"page\" as const) : undefined,\n                  \"aria-label\": isCollapsed\n                    ? item.badge !== undefined && item.badge !== \"\"\n                      ? `${item.label}, ${item.badge}`\n                      : item.label\n                    : undefined,\n                  tabIndex: item.id === tabStop ? 0 : -1,\n                  onFocus: () => setFocusId(item.id),\n                  onClick: () => select(item.id),\n                };\n                return (\n                  <li key={item.id}>\n                    {item.href ? (\n                      <a ref={setRef} href={item.href} {...common}>\n                        {content}\n                      </a>\n                    ) : (\n                      <button ref={setRef} type=\"button\" {...common}>\n                        {content}\n                      </button>\n                    )}\n                  </li>\n                );\n              })}\n            </ul>\n          </div>\n        ))}\n      </nav>\n      {footer ? <div className=\"hb-sb-foot\">{footer}</div> : null}\n    </aside>\n  );\n}\n"
    }
  ]
}