{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-sections-accordion",
  "type": "registry:component",
  "title": "Sidebar Sections Accordion",
  "description": "Grouped sidebar sections that expand with animated height, stagger their items in and can remember which ones were open.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "accordion",
    "sections",
    "groups",
    "badges",
    "persist"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-sections-accordion",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-sections-accordion.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-sections-accordion.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst ICONS = {\n  layers: \"M10 3.5l6.5 3.3L10 10 3.5 6.8zM3.5 10.2L10 13.5l6.5-3.3M3.5 13.4L10 16.7l6.5-3.3\",\n  users:\n    \"M7.5 9a2.7 2.7 0 1 0 0-5.4 2.7 2.7 0 0 0 0 5.4zM2.5 16.2c.4-2.7 2.5-4.2 5-4.2s4.6 1.5 5 4.2M13 4.2a2.7 2.7 0 0 1 0 5M14.5 12.2c1.6.5 2.7 1.8 3 4\",\n  card: \"M3.5 5.5h13a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1h-13a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1zM2.5 8.5h15M5.5 12h3\",\n  bolt: \"M11 3L4.5 11h4.5l-1 6 6.5-8H10z\",\n  book: \"M4 4.2A1.2 1.2 0 0 1 5.2 3H16v12.5H5.7A1.7 1.7 0 0 0 4 17.2zM4 17.2V4.2M7.5 6.5h5.5\",\n  gear: \"M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM10 2.8v2M10 15.2v2M17.2 10h-2M4.8 10h-2M15.1 4.9l-1.4 1.4M6.3 13.7l-1.4 1.4M15.1 15.1l-1.4-1.4M6.3 6.3L4.9 4.9\",\n} as const;\n\nexport type SidebarSectionsIconName = keyof typeof ICONS;\n\nexport function SidebarSectionsIcon({ name }: { name: SidebarSectionsIconName }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={ICONS[name]} />\n    </svg>\n  );\n}\n\nexport interface SidebarSectionItem {\n  id: string;\n  label: string;\n  badge?: string | number;\n}\n\nexport interface SidebarSection {\n  id: string;\n  title: string;\n  icon?: SidebarSectionsIconName;\n  badge?: string | number;\n  items: SidebarSectionItem[];\n}\n\nexport interface SidebarSectionsAccordionProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  sections?: SidebarSection[];\n  open?: string[];\n  defaultOpen?: string[];\n  onOpenChange?: (open: string[]) => void;\n  multiple?: boolean;\n  persistKey?: string;\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  title?: string;\n  accent?: string;\n}\n\nconst defaultSections: SidebarSection[] = [\n  {\n    id: \"projects\",\n    title: \"Projects\",\n    icon: \"layers\",\n    badge: 3,\n    items: [\n      { id: \"overview\", label: \"Overview\" },\n      { id: \"roadmap\", label: \"Roadmap\" },\n      { id: \"releases\", label: \"Releases\", badge: \"New\" },\n    ],\n  },\n  {\n    id: \"team\",\n    title: \"Team\",\n    icon: \"users\",\n    items: [\n      { id: \"members\", label: \"Members\", badge: 12 },\n      { id: \"roles\", label: \"Roles\" },\n    ],\n  },\n  {\n    id: \"billing\",\n    title: \"Billing\",\n    icon: \"card\",\n    items: [\n      { id: \"plan\", label: \"Plan\" },\n      { id: \"invoices\", label: \"Invoices\" },\n      { id: \"usage\", label: \"Usage\" },\n    ],\n  },\n  {\n    id: \"developers\",\n    title: \"Developers\",\n    icon: \"bolt\",\n    items: [\n      { id: \"keys\", label: \"API keys\" },\n      { id: \"webhooks\", label: \"Webhooks\" },\n    ],\n  },\n];\n\nconst STORE_EVENT = \"hb-yc4-store\";\n\nfunction subscribe(cb: () => void) {\n  window.addEventListener(\"storage\", cb);\n  window.addEventListener(STORE_EVENT, cb);\n  return () => {\n    window.removeEventListener(\"storage\", cb);\n    window.removeEventListener(STORE_EVENT, cb);\n  };\n}\n\nfunction readStore(key: string) {\n  try {\n    return window.localStorage.getItem(key);\n  } catch {\n    return null;\n  }\n}\n\nfunction writeStore(key: string, value: string) {\n  try {\n    window.localStorage.setItem(key, value);\n  } catch {\n    return;\n  } finally {\n    window.dispatchEvent(new Event(STORE_EVENT));\n  }\n}\n\nfunction parseStore(raw: string | null): string[] | null {\n  if (!raw) return null;\n  try {\n    const value: unknown = JSON.parse(raw);\n    return Array.isArray(value) ? value.filter((x): x is string => typeof x === \"string\") : null;\n  } catch {\n    return null;\n  }\n}\n\nconst css = `\n.hb-yc4 {\n  --hb-yc4-a: #2f7bff;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  min-height: 0;\n  border-right: 1px solid #262626;\n  background: #0f0f0f;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 18px;\n}\n.hb-yc4 *, .hb-yc4 *::before, .hb-yc4 *::after { box-sizing: border-box; }\n.hb-yc4-title { flex: none; margin: 0; padding: 14px 16px 8px; color: #ededed; font-size: 14px; font-weight: 600; letter-spacing: -.01em; line-height: 20px; }\n.hb-yc4-scroll { flex: 1; min-height: 0; padding: 4px 8px 10px; overflow-y: auto; scrollbar-width: none; }\n.hb-yc4-scroll::-webkit-scrollbar { display: none; }\n.hb-yc4-sec { border-radius: 10px; transition: background-color .2s ease; }\n.hb-yc4-sec[data-open=\"true\"] { background: #131313; }\n.hb-yc4-sec + .hb-yc4-sec { margin-top: 2px; }\n.hb-yc4-head {\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  width: 100%;\n  height: 34px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 10px;\n  background: transparent;\n  color: #b4b4b4;\n  font: inherit;\n  font-weight: 500;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n}\n.hb-yc4-head:hover { background: #181818; color: #ededed; }\n.hb-yc4-sec[data-open=\"true\"] > .hb-yc4-head { color: #ffffff; }\n.hb-yc4-head:focus-visible { outline: 2px solid var(--hb-yc4-a); outline-offset: -2px; }\n.hb-yc4-ico { display: grid; flex: none; place-items: center; width: 18px; height: 18px; color: #77777f; transition: color .2s ease; }\n.hb-yc4-ico svg { width: 17px; height: 17px; }\n.hb-yc4-sec[data-open=\"true\"] .hb-yc4-ico { color: var(--hb-yc4-a); }\n.hb-yc4-tx { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc4-bdg { flex: none; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--hb-yc4-a); color: #ffffff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }\n.hb-yc4-chev { width: 14px; height: 14px; flex: none; color: #6f6f6f; transition: transform .28s cubic-bezier(.2, .9, .2, 1), color .15s ease; }\n.hb-yc4-sec[data-open=\"true\"] .hb-yc4-chev { color: #ededed; transform: rotate(180deg); }\n.hb-yc4-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s cubic-bezier(.2, .9, .2, 1); }\n.hb-yc4-sec[data-open=\"true\"] > .hb-yc4-panel { grid-template-rows: 1fr; }\n.hb-yc4-in { min-height: 0; overflow: hidden; }\n.hb-yc4-list { position: relative; margin: 0 0 6px 17px; padding: 2px 0 0 10px; list-style: none; border-left: 1px solid #262626; }\n.hb-yc4-item {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  height: 28px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 7px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  opacity: 0;\n  transform: translateX(-6px);\n  transition: background-color .15s ease, color .15s ease, opacity .25s ease, transform .3s cubic-bezier(.2, .9, .2, 1);\n}\n.hb-yc4-sec[data-open=\"true\"] .hb-yc4-item { opacity: 1; transform: none; }\n.hb-yc4-item:hover { background: #1a1a1a; color: #ededed; }\n.hb-yc4-item:focus-visible { outline: 2px solid var(--hb-yc4-a); outline-offset: -2px; }\n.hb-yc4-item[aria-current=\"true\"] { background: color-mix(in srgb, var(--hb-yc4-a) 15%, transparent); color: #ffffff; }\n.hb-yc4-item[aria-current=\"true\"]::before {\n  content: \"\";\n  position: absolute;\n  top: 5px;\n  bottom: 5px;\n  left: -11px;\n  width: 2px;\n  border-radius: 2px;\n  background: var(--hb-yc4-a);\n  box-shadow: 0 0 8px var(--hb-yc4-a);\n}\n.hb-yc4-it { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc4-tag { flex: none; padding: 0 6px; border-radius: 999px; background: #232323; color: #d4d4d4; font-size: 10.5px; font-weight: 600; line-height: 16px; }\n.hb-yc4-tag[data-new=\"true\"] { background: color-mix(in srgb, #30a46c 22%, transparent); color: #5ed49b; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-yc4-sec, .hb-yc4-head, .hb-yc4-ico, .hb-yc4-chev, .hb-yc4-panel, .hb-yc4-item { transition: none; }\n}\n`;\n\nexport function SidebarSectionsAccordion({\n  sections = defaultSections,\n  open,\n  defaultOpen = [\"projects\"],\n  onOpenChange,\n  multiple = true,\n  persistKey,\n  active,\n  defaultActive,\n  onChange,\n  title,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: SidebarSectionsAccordionProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const [innerOpen, setInnerOpen] = React.useState(defaultOpen);\n  const [inner, setInner] = React.useState(defaultActive ?? \"\");\n  const [focusKey, setFocusKey] = React.useState(\"\");\n  const stored = React.useSyncExternalStore(\n    subscribe,\n    () => (persistKey ? readStore(persistKey) : null),\n    () => null,\n  );\n  const saved = persistKey ? parseStore(stored) : null;\n  const openIds = open ?? saved ?? innerOpen;\n  const current = active ?? inner;\n\n  function commit(next: string[]) {\n    if (open === undefined) setInnerOpen(next);\n    if (persistKey) writeStore(persistKey, JSON.stringify(next));\n    onOpenChange?.(next);\n  }\n\n  function setSection(id: string, next: boolean) {\n    const has = openIds.includes(id);\n    if (has === next) return;\n    if (next) commit(multiple ? [...openIds, id] : [id]);\n    else commit(openIds.filter((x) => x !== id));\n  }\n\n  function select(id: string) {\n    if (active === undefined) setInner(id);\n    onChange?.(id);\n  }\n\n  function ring() {\n    return Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-yc4-nav]\") ?? []).filter((el) => !el.closest(\"[inert]\"));\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    if (e.key === \"Escape\") {\n      (document.activeElement as HTMLElement | null)?.blur();\n      return;\n    }\n    const target = e.target as HTMLElement;\n    if (!target.hasAttribute(\"data-yc4-nav\")) return;\n    const list = ring();\n    const at = list.indexOf(target);\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = Math.min(list.length - 1, at + 1);\n    else if (e.key === \"ArrowUp\") next = Math.max(0, at - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = list.length - 1;\n    if (next >= 0) {\n      e.preventDefault();\n      list[next]?.focus();\n      return;\n    }\n    const head = target.dataset.yc4Head;\n    const parent = target.dataset.yc4Parent;\n    if (head && e.key === \"ArrowRight\") {\n      e.preventDefault();\n      setSection(head, true);\n    } else if (head && e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      setSection(head, false);\n    } else if (parent && e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      rootRef.current?.querySelector<HTMLElement>(`[data-yc4-head=\"${parent}\"]`)?.focus();\n    }\n  }\n\n  const keys = sections.flatMap((s) => [`h:${s.id}`, ...(openIds.includes(s.id) ? s.items.map((i) => i.id) : [])]);\n  const wanted = keys.includes(focusKey) ? focusKey : keys.includes(current) ? current : keys[0];\n\n  const vars = { \"--hb-yc4-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <nav ref={rootRef} className={`hb-yc4 ${className}`} aria-label=\"Sections\" style={vars} onKeyDown={handleKeyDown} {...rest}>\n      <style href=\"hb-sidebar-sections-accordion\" precedence=\"default\">{css}</style>\n      {title ? <p className=\"hb-yc4-title\">{title}</p> : null}\n      <div className=\"hb-yc4-scroll\">\n        {sections.map((section) => {\n          const isOpen = openIds.includes(section.id);\n          const panelId = `${uid}-${section.id}`;\n          return (\n            <div key={section.id} className=\"hb-yc4-sec\" data-open={isOpen}>\n              <button\n                type=\"button\"\n                className=\"hb-yc4-head\"\n                data-yc4-nav=\"\"\n                data-yc4-head={section.id}\n                aria-expanded={isOpen}\n                aria-controls={panelId}\n                tabIndex={wanted === `h:${section.id}` ? 0 : -1}\n                onFocus={() => setFocusKey(`h:${section.id}`)}\n                onClick={() => setSection(section.id, !isOpen)}\n              >\n                <span className=\"hb-yc4-ico\">\n                  <SidebarSectionsIcon name={section.icon ?? \"layers\"} />\n                </span>\n                <span className=\"hb-yc4-tx\">{section.title}</span>\n                {section.badge !== undefined && section.badge !== \"\" ? <span className=\"hb-yc4-bdg\">{section.badge}</span> : null}\n                <svg className=\"hb-yc4-chev\" viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path d=\"M3.5 5.5L7 9l3.5-3.5\" />\n                </svg>\n              </button>\n              <div id={panelId} className=\"hb-yc4-panel\" role=\"region\" aria-label={section.title}>\n                <div className=\"hb-yc4-in\" inert={!isOpen}>\n                  <ul className=\"hb-yc4-list\" role=\"list\">\n                    {section.items.map((item, i) => (\n                      <li key={item.id}>\n                        <button\n                          type=\"button\"\n                          className=\"hb-yc4-item\"\n                          data-yc4-nav=\"\"\n                          data-yc4-parent={section.id}\n                          aria-current={item.id === current ? true : undefined}\n                          tabIndex={wanted === item.id ? 0 : -1}\n                          style={{ transitionDelay: isOpen ? `${(60 + i * 45).toFixed(0)}ms` : \"0ms\" }}\n                          onFocus={() => setFocusKey(item.id)}\n                          onClick={() => select(item.id)}\n                        >\n                          <span className=\"hb-yc4-it\">{item.label}</span>\n                          {item.badge !== undefined && item.badge !== \"\" ? (\n                            <span className=\"hb-yc4-tag\" data-new={item.badge === \"New\"}>\n                              {item.badge}\n                            </span>\n                          ) : null}\n                        </button>\n                      </li>\n                    ))}\n                  </ul>\n                </div>\n              </div>\n            </div>\n          );\n        })}\n      </div>\n    </nav>\n  );\n}\n"
    }
  ]
}