{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-flyout-rail",
  "type": "registry:component",
  "title": "Sidebar Flyout Rail",
  "description": "An icon rail that opens a flyout of sub-links beside the hovered icon, gliding and resizing between sections with content sliding in the direction you moved. Arrow keys open, walk and close it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "rail",
    "flyout",
    "submenu",
    "hover intent",
    "dashboard"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-flyout-rail",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-flyout-rail.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-flyout-rail.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst PATHS = {\n  bolt: \"M11 2.8L4.8 11h4.6L8.8 17.2 15.2 9h-4.6z\",\n  box: \"M10 2.8l6.5 3.6v7.2L10 17.2l-6.5-3.6V6.4zM3.5 6.4L10 10l6.5-3.6M10 10v7.2\",\n  globe: \"M10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM3 10h14M10 3c2 2 2.8 4.4 2.8 7S12 15 10 17c-2-2-2.8-4.4-2.8-7S8 5 10 3z\",\n  db: \"M10 7c3.6 0 6-1 6-2.2S13.6 2.6 10 2.6 4 3.6 4 4.8 6.4 7 10 7zM4 4.8v10.4c0 1.2 2.4 2.2 6 2.2s6-1 6-2.2V4.8M4 10c0 1.2 2.4 2.2 6 2.2s6-1 6-2.2\",\n  chart: \"M4 16V9M10 16V4M16 16v-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 SidebarFlyoutRailIconName = keyof typeof PATHS;\n\nexport interface SidebarFlyoutRailLink {\n  id: string;\n  label: string;\n  hint?: string;\n}\n\nexport interface SidebarFlyoutRailSection {\n  id: string;\n  label: string;\n  icon?: SidebarFlyoutRailIconName | React.ReactNode;\n  description?: string;\n  links: SidebarFlyoutRailLink[];\n}\n\nexport interface SidebarFlyoutRailProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  sections?: SidebarFlyoutRailSection[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (linkId: string, sectionId: string) => void;\n  defaultOpenSection?: string | null;\n  openDelay?: number;\n  closeDelay?: number;\n  flyoutWidth?: number;\n  brand?: React.ReactNode;\n  footer?: React.ReactNode;\n  accent?: string;\n}\n\nconst defaultSections: SidebarFlyoutRailSection[] = [\n  {\n    id: \"functions\",\n    label: \"Functions\",\n    icon: \"bolt\",\n    description: \"Serverless code on 38 regions\",\n    links: [\n      { id: \"fn-overview\", label: \"Overview\", hint: \"24 deployed\" },\n      { id: \"fn-logs\", label: \"Live logs\" },\n      { id: \"fn-cron\", label: \"Cron jobs\", hint: \"3\" },\n    ],\n  },\n  {\n    id: \"storage\",\n    label: \"Storage\",\n    icon: \"db\",\n    description: \"Postgres, KV and blob buckets\",\n    links: [\n      { id: \"st-postgres\", label: \"Postgres\", hint: \"2 DBs\" },\n      { id: \"st-kv\", label: \"Key value\" },\n      { id: \"st-blob\", label: \"Blob buckets\" },\n      { id: \"st-backups\", label: \"Backups\" },\n    ],\n  },\n  {\n    id: \"network\",\n    label: \"Network\",\n    icon: \"globe\",\n    description: \"Domains, edge rules and firewall\",\n    links: [\n      { id: \"nw-domains\", label: \"Domains\" },\n      { id: \"nw-firewall\", label: \"Firewall\", hint: \"On\" },\n    ],\n  },\n  {\n    id: \"analytics\",\n    label: \"Analytics\",\n    icon: \"chart\",\n    description: \"Traffic, vitals and usage\",\n    links: [\n      { id: \"an-traffic\", label: \"Traffic\" },\n      { id: \"an-vitals\", label: \"Web vitals\" },\n      { id: \"an-usage\", label: \"Usage\", hint: \"72%\" },\n    ],\n  },\n  {\n    id: \"settings\",\n    label: \"Settings\",\n    icon: \"gear\",\n    description: \"Team, billing and tokens\",\n    links: [\n      { id: \"se-team\", label: \"Team\" },\n      { id: \"se-billing\", label: \"Billing\" },\n      { id: \"se-tokens\", label: \"Access tokens\" },\n    ],\n  },\n];\n\nconst css = `\n.hb-xk9 {\n  --hb-xk9-a: #2f7bff;\n  --hb-xk9-fw: 212px;\n  position: relative;\n  z-index: 10;\n  box-sizing: border-box;\n  display: flex;\n  flex: none;\n  width: 56px;\n  height: 100%;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 18px;\n}\n.hb-xk9 *, .hb-xk9 *::before, .hb-xk9 *::after { box-sizing: border-box; }\n.hb-xk9-rail { position: relative; display: flex; flex-direction: column; align-items: center; width: 56px; height: 100%; padding: 10px 0; border-right: 1px solid #1f1f1f; background: #0c0c0c; }\n.hb-xk9-brand { display: grid; place-items: center; height: 34px; margin-bottom: 10px; }\n.hb-xk9-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }\n.hb-xk9-icon {\n  position: relative;\n  display: grid;\n  place-items: center;\n  width: 38px;\n  height: 38px;\n  margin: 0;\n  padding: 0;\n  border: 1px solid transparent;\n  border-radius: 11px;\n  background: transparent;\n  color: #7c7c84;\n  cursor: pointer;\n  transition: color .18s ease, background-color .18s ease, border-color .18s ease, transform .2s cubic-bezier(.22, 1, .36, 1);\n}\n.hb-xk9-icon svg { width: 18px; height: 18px; }\n.hb-xk9-icon:hover, .hb-xk9-icon[data-open=\"true\"] { background: #171717; border-color: #262626; color: #ededed; }\n.hb-xk9-icon:active { transform: scale(.94); }\n.hb-xk9-icon:focus-visible { outline: 2px solid var(--hb-xk9-a); outline-offset: 2px; }\n.hb-xk9-icon[data-owner=\"true\"] { color: #fff; }\n.hb-xk9-icon[data-owner=\"true\"]::before { content: \"\"; position: absolute; top: 10px; bottom: 10px; left: -10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--hb-xk9-a); box-shadow: 0 0 10px var(--hb-xk9-a); }\n.hb-xk9-foot { margin-top: auto; }\n.hb-xk9-fly {\n  position: absolute;\n  top: 0;\n  left: calc(56px + 8px);\n  width: var(--hb-xk9-fw);\n  height: var(--hb-xk9-h);\n  border: 1px solid #2a2a2a;\n  border-radius: 14px;\n  background: linear-gradient(180deg, #181818, #131313);\n  box-shadow: 0 24px 48px -18px rgba(0, 0, 0, .95), 0 0 0 1px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .05);\n  opacity: 0;\n  pointer-events: none;\n  transform: translate(-8px, var(--hb-xk9-y)) scale(.98);\n  transform-origin: 0 var(--hb-xk9-ay);\n  visibility: hidden;\n  transition: opacity .16s ease, transform .3s cubic-bezier(.22, 1, .36, 1), height .32s cubic-bezier(.22, 1, .36, 1), visibility 0s linear .3s;\n}\n.hb-xk9-fly[data-open=\"true\"] {\n  opacity: 1;\n  pointer-events: auto;\n  transform: translate(0, var(--hb-xk9-y));\n  visibility: visible;\n  transition: opacity .18s ease, transform .34s cubic-bezier(.22, 1, .36, 1), height .32s cubic-bezier(.22, 1, .36, 1), visibility 0s;\n}\n.hb-xk9-notch {\n  position: absolute;\n  top: 0;\n  left: -6px;\n  width: 10px;\n  height: 10px;\n  border-bottom: 1px solid #2a2a2a;\n  border-left: 1px solid #2a2a2a;\n  background: #171717;\n  transform: translateY(calc(var(--hb-xk9-ay) - 5px)) rotate(45deg);\n  transition: transform .32s cubic-bezier(.22, 1, .36, 1);\n}\n.hb-xk9-clip { position: relative; height: 100%; overflow: hidden; border-radius: inherit; }\n.hb-xk9-measure { position: absolute; top: 0; right: 0; left: 0; }\n.hb-xk9-content { padding: 12px 8px 8px; animation: hb-xk9-in .32s cubic-bezier(.22, 1, .36, 1) both; }\n.hb-xk9-content[data-dir=\"up\"] { animation-name: hb-xk9-up; }\n.hb-xk9-title { display: flex; align-items: center; justify-content: space-between; margin: 0 6px; font-size: 13px; font-weight: 600; letter-spacing: -.01em; }\n.hb-xk9-title kbd { padding: 0 5px; border: 1px solid #2c2c2c; border-radius: 4px; color: #6f6f76; font-family: var(--font-mono, ui-monospace, monospace); font-size: 9.5px; line-height: 15px; }\n.hb-xk9-desc { margin: 2px 6px 8px; color: #77777f; font-size: 11px; line-height: 15px; }\n.hb-xk9-links { margin: 0; padding: 6px 0 0; border-top: 1px solid #222; list-style: none; }\n.hb-xk9-link {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  height: 30px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #b4b4ba;\n  font: inherit;\n  font-size: 12.5px;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .14s ease, color .14s ease;\n}\n.hb-xk9-link:hover { background: rgba(255, 255, 255, .05); color: #fff; }\n.hb-xk9-link:focus-visible { outline: 2px solid var(--hb-xk9-a); outline-offset: -2px; }\n.hb-xk9-link[aria-current=\"page\"] { background: color-mix(in srgb, var(--hb-xk9-a) 16%, transparent); color: #fff; }\n.hb-xk9-ll { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-xk9-hint { color: #6f6f76; font-size: 10.5px; }\n.hb-xk9-arrow { width: 12px; height: 12px; color: #6f6f76; opacity: 0; transform: translateX(-4px); transition: opacity .15s ease, transform .2s cubic-bezier(.22, 1, .36, 1); }\n.hb-xk9-link:hover .hb-xk9-arrow, .hb-xk9-link:focus-visible .hb-xk9-arrow { opacity: 1; transform: none; }\n@keyframes hb-xk9-in { from { opacity: 0; transform: translateY(10px); } }\n@keyframes hb-xk9-up { from { opacity: 0; transform: translateY(-10px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xk9 *, .hb-xk9 *::before, .hb-xk9 *::after { transition: none !important; animation: none !important; }\n}\n`;\n\nfunction Glyph({ icon }: { icon?: SidebarFlyoutRailIconName | React.ReactNode }) {\n  if (typeof icon === \"string\" || icon === undefined) {\n    const d = PATHS[(icon as SidebarFlyoutRailIconName | undefined) ?? \"box\"] ?? PATHS.box;\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={d} />\n      </svg>\n    );\n  }\n  return <>{icon}</>;\n}\n\nexport function SidebarFlyoutRail({\n  sections = defaultSections,\n  active,\n  defaultActive,\n  onChange,\n  defaultOpenSection = null,\n  openDelay = 90,\n  closeDelay = 220,\n  flyoutWidth = 212,\n  brand,\n  footer,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onPointerEnter,\n  onPointerLeave,\n  onBlur,\n  ...rest\n}: SidebarFlyoutRailProps) {\n  const [inner, setInner] = React.useState(defaultActive ?? sections[0]?.links[0]?.id ?? \"\");\n  const [openId, setOpenId] = React.useState<string | null>(defaultOpenSection);\n  const [dir, setDir] = React.useState<\"up\" | \"down\">(\"down\");\n  const [railH, setRailH] = React.useState(300);\n  const [h, setH] = React.useState(160);\n  const current = active ?? inner;\n  const rootRef = React.useRef<HTMLElement>(null);\n  const measureRef = React.useRef<HTMLDivElement>(null);\n  const flyRef = React.useRef<HTMLDivElement>(null);\n  const timer = React.useRef<number | undefined>(undefined);\n  const flyId = React.useId();\n\n  React.useEffect(() => {\n    const el = measureRef.current;\n    if (!el || typeof ResizeObserver === \"undefined\") return;\n    const root = rootRef.current;\n    const ro = new ResizeObserver(() => {\n      setH(el.offsetHeight);\n      if (root) setRailH(root.clientHeight);\n    });\n    ro.observe(el);\n    if (root) ro.observe(root);\n    return () => ro.disconnect();\n  }, []);\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const openSection = React.useCallback(\n    (id: string) => {\n      if (openId && openId !== id) {\n        const a = sections.findIndex((s) => s.id === openId);\n        const b = sections.findIndex((s) => s.id === id);\n        setDir(b > a ? \"down\" : \"up\");\n      } else if (!openId) setDir(\"down\");\n      setOpenId(id);\n    },\n    [sections, openId],\n  );\n\n  function schedule(fn: () => void, ms: number) {\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(fn, ms);\n  }\n\n  function focusIcon(id: string) {\n    rootRef.current?.querySelector<HTMLElement>(`[data-xk9-sec=\"${id}\"]`)?.focus();\n  }\n\n  function onIconKey(e: React.KeyboardEvent<HTMLButtonElement>, id: string, i: number) {\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      const n = e.key === \"ArrowDown\" ? Math.min(sections.length - 1, i + 1) : Math.max(0, i - 1);\n      focusIcon(sections[n].id);\n      if (openId) openSection(sections[n].id);\n    } else if (e.key === \"ArrowRight\" || e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      openSection(id);\n      window.setTimeout(() => flyRef.current?.querySelector<HTMLElement>(\"[data-xk9-link]\")?.focus(), 30);\n    } else if (e.key === \"Escape\" && openId) {\n      e.preventDefault();\n      setOpenId(null);\n    }\n  }\n\n  function onFlyKey(e: React.KeyboardEvent<HTMLDivElement>) {\n    const links = Array.from(flyRef.current?.querySelectorAll<HTMLElement>(\"[data-xk9-link]\") ?? []);\n    const at = links.indexOf(document.activeElement as HTMLElement);\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      const n = e.key === \"ArrowDown\" ? Math.min(links.length - 1, at + 1) : Math.max(0, at - 1);\n      links[n]?.focus();\n    } else if ((e.key === \"ArrowLeft\" || e.key === \"Escape\") && openId) {\n      e.preventDefault();\n      const id = openId;\n      setOpenId(null);\n      focusIcon(id);\n    }\n  }\n\n  function pick(link: SidebarFlyoutRailLink, sectionId: string) {\n    if (active === undefined) setInner(link.id);\n    onChange?.(link.id, sectionId);\n    setOpenId(null);\n    focusIcon(sectionId);\n  }\n\n  const section = sections.find((s) => s.id === openId);\n  const iconTop = 10 + (brand ? 44 : 0) + Math.max(0, sections.findIndex((s) => s.id === openId)) * 44;\n  const top = Math.max(6, Math.min(railH - h - 6, iconTop - 10));\n  const ay = Math.max(14, Math.min(h - 14, iconTop + 19 - top));\n\n  const vars = {\n    \"--hb-xk9-a\": accent,\n    \"--hb-xk9-fw\": `${flyoutWidth}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <nav\n      ref={rootRef}\n      aria-label=\"Product\"\n      className={`hb-xk9 ${className}`}\n      style={vars}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        window.clearTimeout(timer.current);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        schedule(() => setOpenId(null), closeDelay);\n      }}\n      onBlur={(e) => {\n        onBlur?.(e);\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setOpenId(null);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-sidebar-flyout-rail\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xk9-rail\">\n        {brand ? <div className=\"hb-xk9-brand\">{brand}</div> : null}\n        <ul className=\"hb-xk9-list\" role=\"list\">\n          {sections.map((s, i) => {\n            const owner = s.links.some((l) => l.id === current);\n            return (\n              <li key={s.id}>\n                <button\n                  type=\"button\"\n                  className=\"hb-xk9-icon\"\n                  data-xk9-sec={s.id}\n                  data-open={openId === s.id}\n                  data-owner={owner}\n                  aria-label={s.label}\n                  aria-haspopup=\"true\"\n                  aria-expanded={openId === s.id}\n                  aria-controls={flyId}\n                  onPointerEnter={(e) => {\n                    if (e.pointerType === \"touch\") return;\n                    if (openId) openSection(s.id);\n                    else schedule(() => openSection(s.id), openDelay);\n                  }}\n                  onClick={() => (openId === s.id ? setOpenId(null) : openSection(s.id))}\n                  onKeyDown={(e) => onIconKey(e, s.id, i)}\n                >\n                  <Glyph icon={s.icon} />\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n        {footer ? <div className=\"hb-xk9-foot\">{footer}</div> : null}\n      </div>\n      <div\n        ref={flyRef}\n        id={flyId}\n        className=\"hb-xk9-fly\"\n        role=\"group\"\n        aria-label={section ? section.label : undefined}\n        data-open={!!section}\n        inert={!section}\n        onKeyDown={onFlyKey}\n        style={{ \"--hb-xk9-y\": `${top.toFixed(0)}px`, \"--hb-xk9-h\": `${h.toFixed(0)}px`, \"--hb-xk9-ay\": `${ay.toFixed(0)}px` } as React.CSSProperties}\n      >\n        <span className=\"hb-xk9-notch\" aria-hidden=\"true\" />\n        <div className=\"hb-xk9-clip\">\n          <div ref={measureRef} className=\"hb-xk9-measure\">\n            {section ? (\n              <div key={section.id} className=\"hb-xk9-content\" data-dir={dir}>\n                <div className=\"hb-xk9-title\">\n                  {section.label}\n                  <kbd aria-hidden=\"true\">{sections.indexOf(section) + 1}</kbd>\n                </div>\n                {section.description ? <p className=\"hb-xk9-desc\">{section.description}</p> : null}\n                <ul className=\"hb-xk9-links\" role=\"list\">\n                  {section.links.map((l) => (\n                    <li key={l.id}>\n                      <button\n                        type=\"button\"\n                        className=\"hb-xk9-link\"\n                        data-xk9-link=\"\"\n                        aria-current={l.id === current ? \"page\" : undefined}\n                        onClick={() => pick(l, section.id)}\n                      >\n                        <span className=\"hb-xk9-ll\">{l.label}</span>\n                        {l.hint ? <span className=\"hb-xk9-hint\">{l.hint}</span> : null}\n                        <svg className=\"hb-xk9-arrow\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                          <path d=\"M4.5 3l3 3-3 3\" />\n                        </svg>\n                      </button>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n            ) : null}\n          </div>\n        </div>\n      </div>\n    </nav>\n  );\n}\n"
    }
  ]
}