{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-split-menu",
  "type": "registry:component",
  "title": "Button Split Menu",
  "description": "A split button whose chevron opens a menu of alternative actions; choosing one swaps the primary label with a rolling transition. Full keyboard support with arrows, Home, End and Escape.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "split button",
    "menu",
    "dropdown",
    "merge",
    "keyboard"
  ],
  "docs": "https://hyperblur.dev/effects/button-split-menu",
  "files": [
    {
      "path": "registry/hyperblur/button-split-menu.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-split-menu.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonSplitMenuOption {\n  id: string;\n  label: string;\n  action?: string;\n  description?: string;\n}\n\nexport interface ButtonSplitMenuProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  options?: ButtonSplitMenuOption[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  onAction?: (id: string) => void;\n  placement?: \"bottom\" | \"top\";\n  align?: \"start\" | \"end\";\n  menuLabel?: string;\n  accent?: string;\n  disabled?: boolean;\n}\n\nconst css = `\n.hb-xb7 {\n  --hb-xb7-c: #2ea05b;\n  position: relative;\n  display: inline-flex;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #fff;\n}\n.hb-xb7 *, .hb-xb7 *::before, .hb-xb7 *::after { box-sizing: border-box; }\n.hb-xb7-group {\n  display: inline-flex;\n  border-radius: 10px;\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xb7-c) 88%, #fff) 0%, var(--hb-xb7-c) 55%, color-mix(in srgb, var(--hb-xb7-c) 90%, #000) 100%);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), inset 0 0 0 1px color-mix(in srgb, var(--hb-xb7-c) 60%, #000), 0 8px 18px -10px var(--hb-xb7-c), 0 1px 2px rgba(0, 0, 0, 0.4);\n}\n.hb-xb7-main, .hb-xb7-tog {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  margin: 0;\n  border: 0;\n  background: transparent;\n  color: inherit;\n  font: inherit;\n  cursor: pointer;\n  height: 38px;\n  -webkit-tap-highlight-color: transparent;\n  transition: background 0.2s ease;\n}\n.hb-xb7-main { padding: 0 14px 0 13px; gap: 8px; border-radius: 10px 0 0 10px; font-size: 14px; font-weight: 600; overflow: hidden; }\n.hb-xb7-tog { padding: 0 10px; border-radius: 0 10px 10px 0; }\n.hb-xb7-tog::before { content: \"\"; position: absolute; left: 0; top: 7px; bottom: 7px; width: 1px; background: rgba(0, 0, 0, 0.28); box-shadow: 1px 0 0 rgba(255, 255, 255, 0.18); }\n.hb-xb7-main:hover:not(:disabled), .hb-xb7-tog:hover:not(:disabled), .hb-xb7-tog[aria-expanded=\"true\"] { background: rgba(255, 255, 255, 0.1); }\n.hb-xb7-main:active:not(:disabled), .hb-xb7-tog:active:not(:disabled) { background: rgba(0, 0, 0, 0.12); }\n.hb-xb7-main:focus-visible, .hb-xb7-tog:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }\n.hb-xb7-main:disabled, .hb-xb7-tog:disabled { cursor: not-allowed; opacity: 0.55; }\n.hb-xb7-main svg, .hb-xb7-tog svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }\n.hb-xb7-tog svg { transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xb7-tog[aria-expanded=\"true\"] svg { transform: rotate(180deg); }\n.hb-xb7-lbl { display: inline-block; white-space: nowrap; animation: hb-xb7-in 0.42s cubic-bezier(0.22, 1, 0.36, 1); }\n.hb-xb7-menu {\n  position: absolute;\n  z-index: 30;\n  width: max-content;\n  min-width: 100%;\n  max-width: 300px;\n  margin: 0;\n  padding: 5px;\n  list-style: none;\n  border-radius: 12px;\n  background: rgba(22, 22, 22, 0.96);\n  -webkit-backdrop-filter: blur(14px);\n  backdrop-filter: blur(14px);\n  box-shadow: 0 0 0 1px #2a2a2a, inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 22px 44px -16px rgba(0, 0, 0, 0.95), 0 6px 14px -6px rgba(0, 0, 0, 0.7);\n  color: #ededed;\n  opacity: 0;\n  visibility: hidden;\n  transform: translateY(-6px) scale(0.96);\n  filter: blur(2px);\n  transition: opacity 0.18s ease, transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), filter 0.2s ease, visibility 0s linear 0.32s;\n}\n.hb-xb7-menu[data-placement=\"bottom\"] { top: calc(100% + 6px); }\n.hb-xb7-menu[data-placement=\"top\"] { bottom: calc(100% + 6px); transform: translateY(6px) scale(0.96); }\n.hb-xb7-menu[data-align=\"end\"] { right: 0; transform-origin: 100% 0; }\n.hb-xb7-menu[data-align=\"start\"] { left: 0; transform-origin: 0 0; }\n.hb-xb7-menu[data-placement=\"top\"][data-align=\"end\"] { transform-origin: 100% 100%; }\n.hb-xb7-menu[data-placement=\"top\"][data-align=\"start\"] { transform-origin: 0 100%; }\n.hb-xb7-menu[data-open=\"true\"] { opacity: 1; visibility: visible; transform: none; filter: none; transition: opacity 0.18s ease, transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), filter 0.2s ease, visibility 0s; }\n.hb-xb7-item {\n  position: relative;\n  display: grid;\n  grid-template-columns: 18px 1fr;\n  column-gap: 8px;\n  align-items: start;\n  padding: 7px 10px 7px 8px;\n  border-radius: 8px;\n  cursor: pointer;\n  outline: none;\n  transition: background 0.15s ease;\n}\n.hb-xb7-item[data-active=\"true\"] { background: #232323; }\n.hb-xb7-item:focus-visible { box-shadow: inset 0 0 0 1.5px var(--hb-xb7-c); }\n.hb-xb7-ck { width: 16px; height: 16px; margin-top: 1px; fill: none; stroke: var(--hb-xb7-c); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: scale(0.5); transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xb7-item[aria-checked=\"true\"] .hb-xb7-ck { opacity: 1; transform: none; }\n.hb-xb7-t { font-size: 13px; font-weight: 600; letter-spacing: -0.005em; white-space: nowrap; }\n.hb-xb7-d { grid-column: 2; font-size: 11.5px; line-height: 1.35; color: #8f8f8f; margin-top: 1px; }\n@keyframes hb-xb7-in { from { opacity: 0; transform: translateY(70%); filter: blur(3px); } to { opacity: 1; transform: none; filter: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xb7 *, .hb-xb7-menu { transition-duration: 0.01s !important; animation: none !important; }\n  .hb-xb7-menu { filter: none; transform: none !important; }\n}\n`;\n\nconst defaultOptions: ButtonSplitMenuOption[] = [\n  { id: \"merge\", label: \"Create a merge commit\", action: \"Merge pull request\", description: \"All 14 commits are added to main.\" },\n  { id: \"squash\", label: \"Squash and merge\", description: \"One clean commit on main.\" },\n  { id: \"rebase\", label: \"Rebase and merge\", description: \"Replays each commit on top of main.\" },\n];\n\nexport function ButtonSplitMenu({\n  options = defaultOptions,\n  value,\n  defaultValue,\n  onValueChange,\n  onAction,\n  placement = \"bottom\",\n  align = \"end\",\n  menuLabel = \"More merge options\",\n  accent = \"#2ea05b\",\n  disabled = false,\n  className = \"\",\n  style,\n  ...rest\n}: ButtonSplitMenuProps) {\n  const id = React.useId();\n  const [inner, setInner] = React.useState(defaultValue ?? options[0]?.id ?? \"\");\n  const [open, setOpen] = React.useState(false);\n  const [active, setActive] = React.useState(0);\n  const root = React.useRef<HTMLDivElement>(null);\n  const tog = React.useRef<HTMLButtonElement>(null);\n  const items = React.useRef<(HTMLLIElement | null)[]>([]);\n  const selected = value ?? inner;\n  const current = options.find((o) => o.id === selected) ?? options[0];\n  const mainLabel = current ? current.action ?? current.label : \"\";\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onDown = (e: PointerEvent) => {\n      if (root.current && !root.current.contains(e.target as Node)) setOpen(false);\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open]);\n\n  React.useEffect(() => {\n    if (open) items.current[active]?.focus();\n  }, [open, active]);\n\n  const openMenu = (index?: number) => {\n    const i = index ?? Math.max(0, options.findIndex((o) => o.id === selected));\n    setActive(i);\n    setOpen(true);\n  };\n\n  const close = (refocus = true) => {\n    setOpen(false);\n    if (refocus) tog.current?.focus();\n  };\n\n  const choose = (i: number) => {\n    const o = options[i];\n    if (!o) return;\n    if (value === undefined) setInner(o.id);\n    onValueChange?.(o.id);\n    close();\n  };\n\n  const onMenuKey = (e: React.KeyboardEvent<HTMLUListElement>) => {\n    const n = options.length;\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      setActive((a) => (a + 1) % n);\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setActive((a) => (a - 1 + n) % n);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      setActive(0);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      setActive(n - 1);\n    } else if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      choose(active);\n    } else if (e.key === \"Escape\") {\n      e.preventDefault();\n      close();\n    } else if (e.key === \"Tab\") {\n      close(false);\n    }\n  };\n\n  return (\n    <div ref={root} className={`hb-xb7 ${className}`.trim()} style={{ \"--hb-xb7-c\": accent, ...style } as React.CSSProperties} {...rest}>\n      <style href=\"hb-button-split-menu\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xb7-group\">\n        <button type=\"button\" className=\"hb-xb7-main\" disabled={disabled} onClick={() => current && onAction?.(current.id)}>\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <circle cx=\"6\" cy=\"5.5\" r=\"2\" />\n            <circle cx=\"6\" cy=\"18.5\" r=\"2\" />\n            <circle cx=\"18\" cy=\"12\" r=\"2\" />\n            <path d=\"M6 7.5v9M16 12c-5 0-10-1.5-10-4.5\" />\n          </svg>\n          <span key={selected} className=\"hb-xb7-lbl\">{mainLabel}</span>\n        </button>\n        <button\n          ref={tog}\n          type=\"button\"\n          className=\"hb-xb7-tog\"\n          disabled={disabled}\n          aria-label={menuLabel}\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          aria-controls={`${id}-menu`}\n          onClick={() => (open ? close() : openMenu())}\n          onKeyDown={(e) => {\n            if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n              e.preventDefault();\n              openMenu(e.key === \"ArrowUp\" ? options.length - 1 : undefined);\n            }\n          }}\n        >\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M6 9.5l6 6 6-6\" />\n          </svg>\n        </button>\n      </div>\n      <ul\n        id={`${id}-menu`}\n        role=\"menu\"\n        aria-label={menuLabel}\n        className=\"hb-xb7-menu\"\n        data-open={open ? \"true\" : \"false\"}\n        data-placement={placement}\n        data-align={align}\n        onKeyDown={onMenuKey}\n      >\n        {options.map((o, i) => (\n          <li\n            key={o.id}\n            ref={(el) => {\n              items.current[i] = el;\n            }}\n            role=\"menuitemradio\"\n            aria-checked={o.id === selected}\n            tabIndex={open && i === active ? 0 : -1}\n            className=\"hb-xb7-item\"\n            data-active={open && i === active ? \"true\" : \"false\"}\n            onPointerEnter={() => setActive(i)}\n            onClick={() => choose(i)}\n          >\n            <svg className=\"hb-xb7-ck\" viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n              <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n            </svg>\n            <span className=\"hb-xb7-t\">{o.label}</span>\n            {o.description && <span className=\"hb-xb7-d\">{o.description}</span>}\n          </li>\n        ))}\n      </ul>\n    </div>\n  );\n}\n"
    }
  ]
}