{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-docs",
  "type": "registry:component",
  "title": "Sidebar Docs",
  "description": "Documentation navigation with a search field, collapsible groups that animate their height, nested links on a connected guide line and a marker that follows the active page.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "docs",
    "documentation",
    "search",
    "accordion",
    "scroll spy"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-docs",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-docs.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-docs.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SidebarDocsLink {\n  id: string;\n  label: string;\n  href?: string;\n  badge?: string;\n  children?: SidebarDocsLink[];\n}\n\nexport interface SidebarDocsGroup {\n  id: string;\n  title: string;\n  items: SidebarDocsLink[];\n}\n\nexport interface SidebarDocsProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  groups?: SidebarDocsGroup[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  openGroups?: string[];\n  defaultOpenGroups?: string[];\n  onOpenGroupsChange?: (ids: string[]) => void;\n  search?: boolean;\n  placeholder?: string;\n  rowHeight?: number;\n  color?: string;\n}\n\nconst defaultGroups: SidebarDocsGroup[] = [\n  {\n    id: \"start\",\n    title: \"Getting started\",\n    items: [\n      { id: \"introduction\", label: \"Introduction\" },\n      { id: \"installation\", label: \"Installation\" },\n      { id: \"quickstart\", label: \"Quick start\", badge: \"New\" },\n    ],\n  },\n  {\n    id: \"concepts\",\n    title: \"Core concepts\",\n    items: [\n      { id: \"routing\", label: \"Routing\" },\n      {\n        id: \"theming\",\n        label: \"Theming\",\n        children: [\n          { id: \"theming-colors\", label: \"Colors\" },\n          { id: \"theming-type\", label: \"Typography\" },\n        ],\n      },\n      { id: \"data\", label: \"Data fetching\" },\n    ],\n  },\n  {\n    id: \"reference\",\n    title: \"API reference\",\n    items: [\n      { id: \"config\", label: \"Configuration\" },\n      { id: \"cli\", label: \"CLI\", badge: \"New\" },\n      { id: \"plugins\", label: \"Plugins\" },\n    ],\n  },\n];\n\nconst css = `\n.hb-sdoc {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: var(--hb-sdoc-w, 264px);\n  max-width: 100%;\n  height: 100%;\n  min-height: 0;\n  border-right: 1px solid #262626;\n  background: #0d0d0d;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  font-size: 13px;\n  line-height: 18px;\n  --hb-sdoc-accent: #2f7bff;\n}\n.hb-sdoc *, .hb-sdoc *::before, .hb-sdoc *::after { box-sizing: border-box; }\n.hb-sdoc-top { flex: none; padding: 10px 12px 6px; }\n.hb-sdoc-search {\n  position: relative;\n  display: flex;\n  align-items: center;\n  height: 32px;\n  padding: 0 8px 0 10px;\n  border: 1px solid #262626;\n  border-radius: 9px;\n  background: #141414;\n  transition: border-color .18s ease, box-shadow .18s ease;\n}\n.hb-sdoc-search:focus-within { border-color: var(--hb-sdoc-accent); box-shadow: 0 0 0 3px rgba(47, 123, 255, .18); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-sdoc-accent) 22%, transparent); }\n.hb-sdoc-search > svg { flex: none; width: 15px; height: 15px; color: #77777f; }\n.hb-sdoc-input {\n  flex: 1;\n  min-width: 0;\n  height: 100%;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n}\n.hb-sdoc-input::placeholder { color: #77777f; }\n.hb-sdoc-clear {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 20px;\n  height: 20px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 6px;\n  background: #222222;\n  color: #a1a1a1;\n  cursor: pointer;\n}\n.hb-sdoc-clear:hover { color: #ededed; }\n.hb-sdoc-clear:focus-visible { outline: 2px solid var(--hb-sdoc-accent); outline-offset: 1px; }\n.hb-sdoc-clear svg { width: 10px; height: 10px; }\n.hb-sdoc-nav { position: relative; flex: 1; min-height: 0; padding: 4px 12px 10px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2a2a2a transparent; }\n.hb-sdoc-group + .hb-sdoc-group { margin-top: 6px; }\n.hb-sdoc-ghead {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 8px;\n  width: 100%;\n  height: var(--hb-sdoc-row, 30px);\n  margin: 0;\n  padding: 0 6px 0 4px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 600;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-sdoc-ghead:hover { background: #171717; }\n.hb-sdoc-ghead:focus-visible { outline: 2px solid var(--hb-sdoc-accent); outline-offset: -2px; }\n.hb-sdoc-chev { flex: none; width: 14px; height: 14px; color: #77777f; transition: transform .3s cubic-bezier(.2, .9, .2, 1); }\n.hb-sdoc-ghead[aria-expanded=\"true\"] .hb-sdoc-chev { transform: rotate(90deg); }\n.hb-sdoc-collapse {\n  display: grid;\n  grid-template-rows: 0fr;\n  visibility: hidden;\n  transition: grid-template-rows .32s cubic-bezier(.2, .9, .2, 1), visibility 0s linear .32s;\n}\n.hb-sdoc-collapse[data-open=\"true\"] { grid-template-rows: 1fr; visibility: visible; transition-delay: 0s; }\n.hb-sdoc-inner { min-height: 0; overflow: hidden; }\n.hb-sdoc-list { position: relative; margin: 2px 0 2px 9px; padding: 0; border-left: 1px solid #262626; list-style: none; }\n.hb-sdoc-list .hb-sdoc-list { margin: 0 0 0 12px; }\n.hb-sdoc-link {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: calc(100% - 4px);\n  height: var(--hb-sdoc-row, 30px);\n  margin: 0 0 0 4px;\n  padding: 0 8px 0 10px;\n  border: 0;\n  border-radius: 7px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\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-sdoc-link::before {\n  content: \"\";\n  position: absolute;\n  top: 5px;\n  bottom: 5px;\n  left: -5px;\n  width: 2px;\n  border-radius: 2px;\n  background: var(--hb-sdoc-accent);\n  opacity: 0;\n  transform: scaleY(.2);\n  transition: opacity .2s ease, transform .3s cubic-bezier(.2, .9, .2, 1);\n}\n.hb-sdoc-link:hover { background: #151515; color: #ededed; }\n.hb-sdoc-link[aria-current=\"page\"] { color: #ffffff; font-weight: 500; }\n.hb-sdoc-link[aria-current=\"page\"]::before { opacity: 1; transform: scaleY(1); }\n.hb-sdoc-link:focus-visible { outline: 2px solid var(--hb-sdoc-accent); outline-offset: -2px; }\n.hb-sdoc-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-sdoc-new {\n  flex: none;\n  padding: 0 6px;\n  border-radius: 999px;\n  background: rgba(47, 123, 255, .16);\n  background: color-mix(in srgb, var(--hb-sdoc-accent) 18%, transparent);\n  color: #7fb3ff;\n  font-size: 10.5px;\n  font-weight: 600;\n  line-height: 16px;\n}\n.hb-sdoc-empty { padding: 20px 8px; color: #77777f; text-align: center; }\n.hb-sdoc-empty strong { color: #ededed; font-weight: 500; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-sdoc-search, .hb-sdoc-ghead, .hb-sdoc-chev, .hb-sdoc-collapse, .hb-sdoc-link, .hb-sdoc-link::before { transition: none; }\n}\n`;\n\nfunction filterLinks(links: SidebarDocsLink[], q: string): SidebarDocsLink[] {\n  return links.flatMap((link) => {\n    if (link.label.toLowerCase().includes(q)) return [link];\n    const kids = link.children ? filterLinks(link.children, q) : [];\n    return kids.length > 0 ? [{ ...link, children: kids }] : [];\n  });\n}\n\nfunction findGroup(groups: SidebarDocsGroup[], id: string) {\n  const has = (links: SidebarDocsLink[]): boolean => links.some((l) => l.id === id || (l.children ? has(l.children) : false));\n  return groups.find((g) => has(g.items))?.id;\n}\n\nexport function SidebarDocs({\n  groups = defaultGroups,\n  active,\n  defaultActive,\n  onChange,\n  openGroups,\n  defaultOpenGroups,\n  onOpenGroupsChange,\n  search = true,\n  placeholder = \"Search docs\",\n  rowHeight = 30,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SidebarDocsProps) {\n  const uid = React.useId();\n  const navRef = React.useRef<HTMLElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [innerActive, setInnerActive] = React.useState(defaultActive ?? \"\");\n  const [innerOpen, setInnerOpen] = React.useState<string[]>(defaultOpenGroups ?? groups.map((g) => g.id));\n  const [query, setQuery] = React.useState(\"\");\n  const current = active ?? innerActive;\n  const [seen, setSeen] = React.useState(current);\n  const openIds = openGroups ?? innerOpen;\n\n  if (seen !== current) {\n    setSeen(current);\n    const gid = findGroup(groups, current);\n    if (gid && openGroups === undefined && !innerOpen.includes(gid)) setInnerOpen([...innerOpen, gid]);\n  }\n\n  const q = query.trim().toLowerCase();\n  const view = React.useMemo(() => {\n    if (!q) return groups.map((g) => ({ group: g, items: g.items }));\n    return groups\n      .map((g) => ({ group: g, items: g.title.toLowerCase().includes(q) ? g.items : filterLinks(g.items, q) }))\n      .filter((entry) => entry.items.length > 0);\n  }, [groups, q]);\n\n  React.useEffect(() => {\n    const nav = navRef.current;\n    if (!nav || !current) return;\n    const el = Array.from(nav.querySelectorAll<HTMLElement>(\"[data-sdoc-id]\")).find((n) => n.dataset.sdocId === current);\n    if (!el) return;\n    const top = el.offsetTop;\n    let node: HTMLElement | null = el.offsetParent as HTMLElement | null;\n    let offset = top;\n    while (node && node !== nav) {\n      offset += node.offsetTop;\n      node = node.offsetParent as HTMLElement | null;\n    }\n    const bottom = offset + el.offsetHeight;\n    if (offset < nav.scrollTop) nav.scrollTop = Math.max(0, offset - 40);\n    else if (bottom > nav.scrollTop + nav.clientHeight) nav.scrollTop = bottom - nav.clientHeight + 40;\n  }, [current]);\n\n  function select(id: string) {\n    if (active === undefined) setInnerActive(id);\n    onChange?.(id);\n  }\n\n  function toggle(id: string) {\n    const next = openIds.includes(id) ? openIds.filter((x) => x !== id) : [...openIds, id];\n    if (openGroups === undefined) setInnerOpen(next);\n    onOpenGroupsChange?.(next);\n  }\n\n  function navItems() {\n    return Array.from(navRef.current?.querySelectorAll<HTMLElement>(\"[data-sdoc-nav]\") ?? []).filter((n) => !n.closest(\"[inert]\"));\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    const list = navItems();\n    const here = list.indexOf(e.target as HTMLElement);\n    if (here < 0) return;\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = Math.min(list.length - 1, here + 1);\n    else if (e.key === \"ArrowUp\") next = here === 0 ? -2 : here - 1;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = list.length - 1;\n    if (next === -2) {\n      e.preventDefault();\n      inputRef.current?.focus();\n      return;\n    }\n    if (next < 0) return;\n    e.preventDefault();\n    list[next]?.focus();\n  }\n\n  function renderLinks(links: SidebarDocsLink[], level: number): React.ReactNode {\n    return (\n      <ul className=\"hb-sdoc-list\" role=\"list\">\n        {links.map((link) => {\n          const common = {\n            className: \"hb-sdoc-link\",\n            \"data-sdoc-nav\": \"\",\n            \"data-sdoc-id\": link.id,\n            \"aria-current\": link.id === current ? (\"page\" as const) : undefined,\n            onClick: () => select(link.id),\n          };\n          const body = (\n            <>\n              <span className=\"hb-sdoc-text\">{link.label}</span>\n              {link.badge ? <span className=\"hb-sdoc-new\">{link.badge}</span> : null}\n            </>\n          );\n          return (\n            <li key={link.id}>\n              {link.href ? (\n                <a href={link.href} {...common}>\n                  {body}\n                </a>\n              ) : (\n                <button type=\"button\" {...common}>\n                  {body}\n                </button>\n              )}\n              {link.children && link.children.length > 0 && level < 3 ? renderLinks(link.children, level + 1) : null}\n            </li>\n          );\n        })}\n      </ul>\n    );\n  }\n\n  const vars = { \"--hb-sdoc-accent\": color, \"--hb-sdoc-row\": `${rowHeight}px`, ...style } as React.CSSProperties;\n\n  return (\n    <aside className={`hb-sdoc ${className}`} style={vars} {...rest}>\n      <style href=\"hb-sidebar-docs\" precedence=\"default\">{css}</style>\n      {search ? (\n        <div className=\"hb-sdoc-top\">\n          <div className=\"hb-sdoc-search\">\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <circle cx=\"7\" cy=\"7\" r=\"4.5\" />\n              <path d=\"M10.5 10.5L14 14\" />\n            </svg>\n            <input\n              ref={inputRef}\n              className=\"hb-sdoc-input\"\n              type=\"text\"\n              role=\"searchbox\"\n              aria-label={placeholder}\n              placeholder={placeholder}\n              value={query}\n              autoComplete=\"off\"\n              spellCheck={false}\n              onChange={(e) => setQuery(e.target.value)}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\") setQuery(\"\");\n                else if (e.key === \"ArrowDown\") {\n                  e.preventDefault();\n                  navItems()[0]?.focus();\n                }\n              }}\n            />\n            {query ? (\n              <button\n                type=\"button\"\n                className=\"hb-sdoc-clear\"\n                aria-label=\"Clear search\"\n                onClick={() => {\n                  setQuery(\"\");\n                  inputRef.current?.focus();\n                }}\n              >\n                <svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                  <path d=\"M2 2l6 6M8 2L2 8\" />\n                </svg>\n              </button>\n            ) : null}\n          </div>\n        </div>\n      ) : null}\n      <nav ref={navRef} className=\"hb-sdoc-nav\" aria-label=\"Documentation\" onKeyDown={handleKeyDown}>\n        {view.length === 0 ? (\n          <div className=\"hb-sdoc-empty\" role=\"status\">\n            No results for <strong>{query.trim()}</strong>\n          </div>\n        ) : null}\n        {view.map(({ group, items }) => {\n          const isOpen = q ? true : openIds.includes(group.id);\n          const panelId = `${uid}-${group.id}`;\n          return (\n            <section key={group.id} className=\"hb-sdoc-group\">\n              <button\n                type=\"button\"\n                className=\"hb-sdoc-ghead\"\n                data-sdoc-nav=\"\"\n                aria-expanded={isOpen}\n                aria-controls={panelId}\n                onClick={() => {\n                  if (!q) toggle(group.id);\n                }}\n              >\n                <span>{group.title}</span>\n                <svg className=\"hb-sdoc-chev\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path d=\"M6 3.5L10.5 8 6 12.5\" />\n                </svg>\n              </button>\n              <div id={panelId} className=\"hb-sdoc-collapse\" data-open={isOpen} inert={!isOpen}>\n                <div className=\"hb-sdoc-inner\">{renderLinks(items, 1)}</div>\n              </div>\n            </section>\n          );\n        })}\n      </nav>\n    </aside>\n  );\n}\n"
    }
  ]
}