{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-drawer",
  "type": "registry:component",
  "title": "Sidebar Drawer",
  "description": "A slide-in navigation drawer with a scrim. It fills its nearest positioned parent, traps Tab focus, closes on Escape or a scrim click and returns focus to the trigger.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "drawer",
    "mobile",
    "sidebar",
    "overlay",
    "focus trap",
    "menu"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-drawer",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-drawer.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-drawer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst ICONS = {\n  home: \"M3.5 9.2L10 3.8l6.5 5.4V16a.8.8 0 0 1-.8.8H12v-4.5H8v4.5H4.3a.8.8 0 0 1-.8-.8z\",\n  search: \"M9 15a6 6 0 1 0 0-12 6 6 0 0 0 0 12zM14 14l3 3\",\n  chat: \"M4 5.5a1.5 1.5 0 0 1 1.5-1.5h9A1.5 1.5 0 0 1 16 5.5v6a1.5 1.5 0 0 1-1.5 1.5H9l-3.5 3v-3h0A1.5 1.5 0 0 1 4 11.5z\",\n  bookmark: \"M6 3.8h8a1 1 0 0 1 1 1V16l-5-3.2L5 16V4.8a1 1 0 0 1 1-1z\",\n  sliders: \"M4 6h7M14 6h2M4 14h2M9 14h7M12.5 4v4M7.5 12v4\",\n  bell: \"M5.5 8.5a4.5 4.5 0 0 1 9 0c0 4 1.5 5 1.5 5h-12s1.5-1 1.5-5zM8.5 16a1.7 1.7 0 0 0 3 0\",\n  menu: \"M3.5 6h13M3.5 10h13M3.5 14h13\",\n} as const;\n\nexport type SidebarDrawerIconName = keyof typeof ICONS;\n\nexport function SidebarDrawerIcon({ name }: { name: SidebarDrawerIconName }) {\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 SidebarDrawerItem {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  badge?: string | number;\n  href?: string;\n}\n\nexport interface SidebarDrawerProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\" | \"defaultValue\" | \"title\"> {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  side?: \"left\" | \"right\";\n  items?: SidebarDrawerItem[];\n  header?: React.ReactNode;\n  footer?: React.ReactNode;\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  closeOnSelect?: boolean;\n  rowHeight?: number;\n  position?: \"absolute\" | \"fixed\";\n  width?: number | string;\n  label?: string;\n  color?: string;\n}\n\nconst defaultItems: SidebarDrawerItem[] = [\n  { id: \"home\", label: \"Home\", icon: <SidebarDrawerIcon name=\"home\" /> },\n  { id: \"search\", label: \"Search\", icon: <SidebarDrawerIcon name=\"search\" /> },\n  { id: \"messages\", label: \"Messages\", icon: <SidebarDrawerIcon name=\"chat\" />, badge: 3 },\n  { id: \"saved\", label: \"Saved\", icon: <SidebarDrawerIcon name=\"bookmark\" /> },\n  { id: \"settings\", label: \"Settings\", icon: <SidebarDrawerIcon name=\"sliders\" /> },\n];\n\nconst css = `\n.hb-sdr {\n  position: absolute;\n  inset: 0;\n  z-index: 50;\n  overflow: hidden;\n  box-sizing: border-box;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  font-size: 14px;\n  line-height: 20px;\n  pointer-events: none;\n  --hb-sdr-accent: #2f7bff;\n}\n.hb-sdr[data-position=\"fixed\"] { position: fixed; }\n.hb-sdr *, .hb-sdr *::before, .hb-sdr *::after { box-sizing: border-box; }\n.hb-sdr-scrim {\n  position: absolute;\n  inset: 0;\n  background: rgba(0, 0, 0, .58);\n  -webkit-backdrop-filter: blur(2px);\n  backdrop-filter: blur(2px);\n  opacity: 0;\n  visibility: hidden;\n  transition: opacity .3s ease, visibility 0s linear .3s;\n}\n.hb-sdr[data-open=\"true\"] .hb-sdr-scrim { opacity: 1; visibility: visible; pointer-events: auto; transition-delay: 0s; }\n.hb-sdr-panel {\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  left: 0;\n  display: flex;\n  flex-direction: column;\n  width: var(--hb-sdr-w, min(280px, 84%));\n  max-width: 100%;\n  border-right: 1px solid #262626;\n  background: #111111;\n  box-shadow: 24px 0 60px rgba(0, 0, 0, .5);\n  outline: 0;\n  pointer-events: auto;\n  transform: translate3d(-102%, 0, 0);\n  visibility: hidden;\n  transition: transform .34s cubic-bezier(.2, .9, .2, 1), visibility 0s linear .34s;\n}\n.hb-sdr[data-side=\"right\"] .hb-sdr-panel {\n  left: auto;\n  right: 0;\n  border-right: 0;\n  border-left: 1px solid #262626;\n  box-shadow: -24px 0 60px rgba(0, 0, 0, .5);\n  transform: translate3d(102%, 0, 0);\n}\n.hb-sdr[data-open=\"true\"] .hb-sdr-panel { transform: translate3d(0, 0, 0); visibility: visible; transition-delay: 0s; }\n.hb-sdr-head { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 8px 8px 8px 16px; border-bottom: 1px solid #1f1f1f; }\n.hb-sdr-title { min-width: 0; font-weight: 600; }\n.hb-sdr-close {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 32px;\n  height: 32px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 10px;\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-sdr-close:hover { background: #1f1f1f; color: #ededed; }\n.hb-sdr-close:focus-visible { outline: 2px solid var(--hb-sdr-accent); outline-offset: 1px; }\n.hb-sdr-close svg { width: 16px; height: 16px; }\n.hb-sdr-nav { flex: 1; min-height: 0; padding: 8px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2a2a2a transparent; }\n.hb-sdr-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }\n.hb-sdr-item {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n  width: 100%;\n  height: var(--hb-sdr-row, 44px);\n  margin: 0;\n  padding: 0 12px;\n  border: 0;\n  border-radius: 12px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  font-weight: 500;\n  text-align: left;\n  text-decoration: none;\n  cursor: pointer;\n  opacity: 0;\n  transform: translate3d(-10px, 0, 0);\n  transition: background-color .15s ease, color .15s ease, opacity .3s ease, transform .35s cubic-bezier(.2, .9, .2, 1);\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-sdr[data-side=\"right\"] .hb-sdr-item { transform: translate3d(10px, 0, 0); }\n.hb-sdr[data-open=\"true\"] .hb-sdr-item {\n  opacity: 1;\n  transform: translate3d(0, 0, 0);\n  transition-delay: 0s, 0s, calc(var(--hb-sdr-i, 0) * 35ms + 90ms), calc(var(--hb-sdr-i, 0) * 35ms + 90ms);\n}\n.hb-sdr-item:hover { background: #1a1a1a; color: #ededed; }\n.hb-sdr-item[aria-current=\"page\"] { background: #1f1f1f; color: #ffffff; }\n.hb-sdr-item:focus-visible { outline: 2px solid var(--hb-sdr-accent); outline-offset: -2px; }\n.hb-sdr-ico { display: grid; flex: none; place-items: center; width: 20px; height: 20px; }\n.hb-sdr-ico svg { width: 20px; height: 20px; }\n.hb-sdr-item[aria-current=\"page\"] .hb-sdr-ico { color: var(--hb-sdr-accent); }\n.hb-sdr-letter { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid currentColor; border-radius: 6px; font-size: 11px; line-height: 1; }\n.hb-sdr-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-sdr-badge { flex: none; min-width: 20px; padding: 0 7px; border-radius: 999px; background: var(--hb-sdr-accent); color: #ffffff; font-size: 12px; font-weight: 600; line-height: 20px; text-align: center; }\n.hb-sdr-foot { flex: none; padding: 12px 16px; border-top: 1px solid #1f1f1f; color: #8f8f8f; font-size: 13px; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-sdr-scrim, .hb-sdr-panel, .hb-sdr-item, .hb-sdr-close { transition: none; }\n  .hb-sdr-item { opacity: 1; transform: none; }\n}\n`;\n\nconst focusable = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nexport function SidebarDrawer({\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  side = \"left\",\n  items = defaultItems,\n  header,\n  footer,\n  active,\n  defaultActive,\n  onChange,\n  closeOnSelect = true,\n  rowHeight = 44,\n  position = \"absolute\",\n  width,\n  label = \"Navigation menu\",\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SidebarDrawerProps) {\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const [innerOpen, setInnerOpen] = React.useState(defaultOpen);\n  const [innerActive, setInnerActive] = React.useState(defaultActive ?? items[0]?.id ?? \"\");\n  const isOpen = open ?? innerOpen;\n  const current = active ?? innerActive;\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (open === undefined) setInnerOpen(next);\n      onOpenChange?.(next);\n    },\n    [open, onOpenChange],\n  );\n\n  const skipFocus = React.useRef(isOpen);\n\n  React.useEffect(() => {\n    if (!isOpen) {\n      skipFocus.current = false;\n      return;\n    }\n    if (skipFocus.current) return;\n    const previous = document.activeElement as HTMLElement | null;\n    const panel = panelRef.current;\n    const target = panel?.querySelector<HTMLElement>('[aria-current=\"page\"]') ?? panel?.querySelector<HTMLElement>(focusable) ?? panel;\n    target?.focus({ preventScroll: true });\n    return () => {\n      if (previous && previous !== document.body && previous.isConnected) previous.focus({ preventScroll: true });\n    };\n  }, [isOpen]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        setOpen(false);\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => document.removeEventListener(\"keydown\", onKey);\n  }, [isOpen, setOpen]);\n\n  function select(id: string) {\n    if (active === undefined) setInnerActive(id);\n    onChange?.(id);\n    if (closeOnSelect) setOpen(false);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    const panel = panelRef.current;\n    if (!panel) return;\n    const nodes = Array.from(panel.querySelectorAll<HTMLElement>(focusable));\n    if (nodes.length === 0) return;\n    const at = nodes.indexOf(document.activeElement as HTMLElement);\n    if (e.key === \"Tab\") {\n      const first = nodes[0];\n      const last = nodes[nodes.length - 1];\n      if (e.shiftKey && (at <= 0 || document.activeElement === panel)) {\n        e.preventDefault();\n        last.focus();\n      } else if (!e.shiftKey && (at === nodes.length - 1 || at < 0)) {\n        e.preventDefault();\n        first.focus();\n      }\n      return;\n    }\n    const links = Array.from(panel.querySelectorAll<HTMLElement>(\"[data-sdr-item]\"));\n    const here = links.indexOf(document.activeElement as HTMLElement);\n    if (here < 0) return;\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = Math.min(links.length - 1, here + 1);\n    else if (e.key === \"ArrowUp\") next = Math.max(0, here - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = links.length - 1;\n    if (next < 0) return;\n    e.preventDefault();\n    links[next]?.focus();\n  }\n\n  const w = typeof width === \"number\" ? `${width}px` : width;\n  const vars = { \"--hb-sdr-accent\": color, \"--hb-sdr-row\": `${rowHeight}px`, ...(w ? { \"--hb-sdr-w\": w } : null), ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-sdr ${className}`} data-open={isOpen} data-side={side} data-position={position} style={vars} {...rest}>\n      <style href=\"hb-sidebar-drawer\" precedence=\"default\">{css}</style>\n      <div className=\"hb-sdr-scrim\" aria-hidden=\"true\" onClick={() => setOpen(false)} />\n      <div\n        ref={panelRef}\n        className=\"hb-sdr-panel\"\n        role=\"dialog\"\n        aria-modal=\"true\"\n        aria-label={label}\n        aria-hidden={!isOpen}\n        tabIndex={-1}\n        inert={!isOpen}\n        onKeyDown={handleKeyDown}\n      >\n        <div className=\"hb-sdr-head\">\n          <div className=\"hb-sdr-title\">{header}</div>\n          <button type=\"button\" className=\"hb-sdr-close\" aria-label=\"Close menu\" onClick={() => setOpen(false)}>\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <path d=\"M3.5 3.5l9 9M12.5 3.5l-9 9\" />\n            </svg>\n          </button>\n        </div>\n        <nav className=\"hb-sdr-nav\" aria-label={label}>\n          <ul className=\"hb-sdr-list\" role=\"list\">\n            {items.map((item, i) => {\n              const common = {\n                className: \"hb-sdr-item\",\n                \"data-sdr-item\": \"\",\n                \"aria-current\": item.id === current ? (\"page\" as const) : undefined,\n                style: { \"--hb-sdr-i\": i } as React.CSSProperties,\n                onClick: () => select(item.id),\n              };\n              const body = (\n                <>\n                  <span className=\"hb-sdr-ico\" aria-hidden=\"true\">\n                    {item.icon ?? <span className=\"hb-sdr-letter\">{item.label.charAt(0).toUpperCase()}</span>}\n                  </span>\n                  <span className=\"hb-sdr-text\">{item.label}</span>\n                  {item.badge !== undefined && item.badge !== \"\" ? <span className=\"hb-sdr-badge\">{item.badge}</span> : null}\n                </>\n              );\n              return (\n                <li key={item.id}>\n                  {item.href ? (\n                    <a href={item.href} {...common}>\n                      {body}\n                    </a>\n                  ) : (\n                    <button type=\"button\" {...common}>\n                      {body}\n                    </button>\n                  )}\n                </li>\n              );\n            })}\n          </ul>\n        </nav>\n        {footer ? <div className=\"hb-sdr-foot\">{footer}</div> : null}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}