{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-toolbar-group",
  "type": "registry:component",
  "title": "Button Toolbar Group",
  "description": "A floating tool palette with a springy active pill, a hover highlight that glides between tools and tooltips with shortcut keys. Arrow keys move focus and single-letter shortcuts switch tools.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button group",
    "toolbar",
    "icon buttons",
    "tooltip",
    "shortcuts",
    "editor"
  ],
  "docs": "https://hyperblur.dev/effects/button-toolbar-group",
  "files": [
    {
      "path": "registry/hyperblur/button-toolbar-group.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-toolbar-group.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonToolbarGroupItem {\n  id: string;\n  label: string;\n  shortcut?: string;\n  icon?: React.ReactNode;\n}\n\nexport interface ButtonToolbarGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  items?: ButtonToolbarGroupItem[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  orientation?: \"horizontal\" | \"vertical\";\n  tooltipSide?: \"top\" | \"bottom\" | \"right\" | \"left\";\n  shortcuts?: boolean;\n  label?: string;\n  accent?: string;\n}\n\nconst css = `\n.hb-xb10 {\n  --hb-xb10-c: #2f7bff;\n  --hb-xb10-s: 36px;\n  --hb-xb10-g: 2px;\n  position: relative;\n  display: inline-flex;\n  gap: var(--hb-xb10-g);\n  padding: 4px;\n  box-sizing: border-box;\n  border-radius: 14px;\n  font-family: inherit;\n  color: #a1a1a1;\n  background: linear-gradient(180deg, rgba(30, 30, 30, 0.92), rgba(20, 20, 20, 0.92));\n  -webkit-backdrop-filter: blur(12px);\n  backdrop-filter: blur(12px);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px #2a2a2a, 0 16px 36px -14px rgba(0, 0, 0, 0.95), 0 4px 10px -4px rgba(0, 0, 0, 0.6);\n}\n.hb-xb10 *, .hb-xb10 *::before, .hb-xb10 *::after { box-sizing: border-box; }\n.hb-xb10[data-orientation=\"vertical\"] { flex-direction: column; }\n.hb-xb10-ind, .hb-xb10-hov {\n  position: absolute;\n  left: 4px;\n  top: 4px;\n  width: var(--hb-xb10-s);\n  height: var(--hb-xb10-s);\n  border-radius: 10px;\n  pointer-events: none;\n}\n.hb-xb10-ind {\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xb10-c) 92%, #fff) 0%, var(--hb-xb10-c) 60%);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 6px 16px -6px var(--hb-xb10-c);\n  transform: translate(var(--hb-xb10-ix), var(--hb-xb10-iy));\n  transition: transform 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);\n}\n.hb-xb10-hov {\n  background: rgba(255, 255, 255, 0.06);\n  opacity: 0;\n  transform: translate(var(--hb-xb10-hx), var(--hb-xb10-hy));\n  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease;\n}\n.hb-xb10[data-hover=\"true\"] .hb-xb10-hov { opacity: 1; }\n.hb-xb10-btn {\n  position: relative;\n  z-index: 1;\n  width: var(--hb-xb10-s);\n  height: var(--hb-xb10-s);\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 10px;\n  display: grid;\n  place-items: center;\n  color: inherit;\n  background: transparent;\n  font: inherit;\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: color 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-xb10-btn:hover { color: #ededed; }\n.hb-xb10-btn:active { transform: scale(0.88); }\n.hb-xb10-btn[aria-pressed=\"true\"] { color: #fff; }\n.hb-xb10-btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--hb-xb10-c) 80%, #fff); outline-offset: 1px; }\n.hb-xb10-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }\n.hb-xb10-tip {\n  position: absolute;\n  z-index: 3;\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  padding: 5px 6px 5px 9px;\n  border-radius: 8px;\n  white-space: nowrap;\n  font-size: 12px;\n  font-weight: 550;\n  color: #ededed;\n  background: #1d1d1d;\n  box-shadow: 0 0 0 1px #2e2e2e, 0 10px 22px -10px rgba(0, 0, 0, 0.95);\n  opacity: 0;\n  pointer-events: none;\n  transition: opacity 0.14s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-xb10-tip kbd { font-family: var(--font-mono, ui-monospace, monospace); font-size: 10.5px; min-width: 18px; padding: 1px 4px; text-align: center; border-radius: 4px; color: #a1a1a1; background: #262626; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4); }\n.hb-xb10-tip[data-side=\"top\"] { bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px); }\n.hb-xb10-tip[data-side=\"bottom\"] { top: calc(100% + 8px); left: 50%; transform: translate(-50%, -4px); }\n.hb-xb10-tip[data-side=\"right\"] { left: calc(100% + 8px); top: 50%; transform: translate(-4px, -50%); }\n.hb-xb10-tip[data-side=\"left\"] { right: calc(100% + 8px); top: 50%; transform: translate(4px, -50%); }\n.hb-xb10-btn:hover .hb-xb10-tip, .hb-xb10-btn:focus-visible .hb-xb10-tip { opacity: 1; transition-delay: 0.35s; }\n.hb-xb10-btn:hover .hb-xb10-tip[data-side=\"top\"], .hb-xb10-btn:focus-visible .hb-xb10-tip[data-side=\"top\"],\n.hb-xb10-btn:hover .hb-xb10-tip[data-side=\"bottom\"], .hb-xb10-btn:focus-visible .hb-xb10-tip[data-side=\"bottom\"] { transform: translate(-50%, 0); }\n.hb-xb10-btn:hover .hb-xb10-tip[data-side=\"right\"], .hb-xb10-btn:focus-visible .hb-xb10-tip[data-side=\"right\"],\n.hb-xb10-btn:hover .hb-xb10-tip[data-side=\"left\"], .hb-xb10-btn:focus-visible .hb-xb10-tip[data-side=\"left\"] { transform: translate(0, -50%); }\n.hb-xb10[data-hover=\"true\"] .hb-xb10-btn:hover .hb-xb10-tip { transition-delay: 0.08s; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xb10 *, .hb-xb10-ind, .hb-xb10-hov { transition-duration: 0.01s !important; }\n}\n`;\n\nconst ico = (d: string) => (\n  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n    <path d={d} />\n  </svg>\n);\n\nconst defaultItems: ButtonToolbarGroupItem[] = [\n  { id: \"move\", label: \"Move\", shortcut: \"V\", icon: ico(\"M5.5 4l13 6.2-5.6 1.7-1.8 5.6z\") },\n  { id: \"hand\", label: \"Hand\", shortcut: \"H\", icon: ico(\"M8 12.5V6.8a1.4 1.4 0 0 1 2.8 0v4.7M10.8 11V5.4a1.4 1.4 0 0 1 2.8 0V11M13.6 11V6.4a1.4 1.4 0 0 1 2.8 0v6.1M16.4 9.5a1.4 1.4 0 0 1 2.8 0v4.2a6.3 6.3 0 0 1-6.3 6.3h-.6a5.6 5.6 0 0 1-4.4-2.2l-3-4a1.5 1.5 0 0 1 2.3-1.9L8 12.5\") },\n  { id: \"frame\", label: \"Frame\", shortcut: \"F\", icon: ico(\"M8 3.5v17M16 3.5v17M3.5 8h17M3.5 16h17\") },\n  { id: \"pen\", label: \"Pen\", shortcut: \"P\", icon: ico(\"M14.5 5.5l4 4M4 20l1.2-4.6L15.6 5a1.9 1.9 0 0 1 2.8 0l.6.6a1.9 1.9 0 0 1 0 2.8L8.6 18.8z\") },\n  { id: \"text\", label: \"Text\", shortcut: \"T\", icon: ico(\"M5 6.5V5h14v1.5M12 5v14M9.5 19h5\") },\n  { id: \"comment\", label: \"Comment\", shortcut: \"C\", icon: ico(\"M5 5.5h14c.8 0 1.5.7 1.5 1.5v8.5c0 .8-.7 1.5-1.5 1.5h-7.5L7 20.5V17H5c-.8 0-1.5-.7-1.5-1.5V7c0-.8.7-1.5 1.5-1.5z\") },\n];\n\nexport function ButtonToolbarGroup({\n  items = defaultItems,\n  value,\n  defaultValue,\n  onValueChange,\n  orientation = \"horizontal\",\n  tooltipSide,\n  shortcuts = true,\n  label = \"Tools\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: ButtonToolbarGroupProps) {\n  const [inner, setInner] = React.useState(defaultValue ?? items[0]?.id ?? \"\");\n  const [hover, setHover] = React.useState<number | null>(null);\n  const [focusIndex, setFocusIndex] = React.useState<number | null>(null);\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const selected = value ?? inner;\n  const index = Math.max(0, items.findIndex((i) => i.id === selected));\n  const roving = focusIndex ?? index;\n  const vertical = orientation === \"vertical\";\n  const side = tooltipSide ?? (vertical ? \"right\" : \"top\");\n\n  const select = React.useCallback(\n    (id: string) => {\n      if (value === undefined) setInner(id);\n      onValueChange?.(id);\n    },\n    [value, onValueChange],\n  );\n\n  React.useEffect(() => {\n    if (!shortcuts) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.metaKey || e.ctrlKey || e.altKey || e.repeat) return;\n      const t = e.target as HTMLElement | null;\n      if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;\n      const hit = items.find((i) => i.shortcut && i.shortcut.toLowerCase() === e.key.toLowerCase());\n      if (hit) select(hit.id);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [shortcuts, items, select]);\n\n  const offset = (i: number) => `calc(${i} * (var(--hb-xb10-s) + var(--hb-xb10-g)))`;\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const n = items.length;\n    const nextKey = vertical ? \"ArrowDown\" : \"ArrowRight\";\n    const prevKey = vertical ? \"ArrowUp\" : \"ArrowLeft\";\n    let to: number | null = null;\n    if (e.key === nextKey) to = (roving + 1) % n;\n    else if (e.key === prevKey) to = (roving - 1 + n) % n;\n    else if (e.key === \"Home\") to = 0;\n    else if (e.key === \"End\") to = n - 1;\n    if (to !== null) {\n      e.preventDefault();\n      setFocusIndex(to);\n      refs.current[to]?.focus();\n    }\n  };\n\n  const vars = {\n    \"--hb-xb10-c\": accent,\n    \"--hb-xb10-ix\": vertical ? \"0px\" : offset(index),\n    \"--hb-xb10-iy\": vertical ? offset(index) : \"0px\",\n    \"--hb-xb10-hx\": vertical ? \"0px\" : offset(hover ?? index),\n    \"--hb-xb10-hy\": vertical ? offset(hover ?? index) : \"0px\",\n  } as React.CSSProperties;\n\n  return (\n    <div\n      role=\"toolbar\"\n      aria-label={label}\n      aria-orientation={orientation}\n      className={`hb-xb10 ${className}`.trim()}\n      data-orientation={orientation}\n      data-hover={hover !== null && hover !== index ? \"true\" : \"false\"}\n      style={{ ...vars, ...style }}\n      onKeyDown={onKeyDown}\n      onPointerLeave={() => setHover(null)}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocusIndex(null);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-button-toolbar-group\" precedence=\"default\">{css}</style>\n      <span className=\"hb-xb10-hov\" aria-hidden=\"true\" />\n      <span className=\"hb-xb10-ind\" aria-hidden=\"true\" />\n      {items.map((item, i) => (\n        <button\n          key={item.id}\n          ref={(el) => {\n            refs.current[i] = el;\n          }}\n          type=\"button\"\n          aria-pressed={item.id === selected}\n          aria-label={item.shortcut ? `${item.label} (${item.shortcut})` : item.label}\n          aria-keyshortcuts={item.shortcut}\n          tabIndex={i === roving ? 0 : -1}\n          className=\"hb-xb10-btn\"\n          onPointerEnter={() => setHover(i)}\n          onFocus={() => setFocusIndex(i)}\n          onClick={() => select(item.id)}\n        >\n          {item.icon ?? ico(\"M12 5v14M5 12h14\")}\n          <span className=\"hb-xb10-tip\" data-side={side} aria-hidden=\"true\">\n            {item.label}\n            {item.shortcut && <kbd>{item.shortcut}</kbd>}\n          </span>\n        </button>\n      ))}\n    </div>\n  );\n}\n"
    }
  ]
}