{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-share-expand",
  "type": "registry:component",
  "title": "Button Share Expand",
  "description": "A Share pill that unfolds sideways into a row of action buttons, each springing in with a tooltip while the icon turns into a close cross. Actions confirm with a check and Escape folds it back.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "share",
    "expand",
    "actions",
    "toolbar",
    "pill"
  ],
  "docs": "https://hyperblur.dev/effects/button-share-expand",
  "files": [
    {
      "path": "registry/hyperblur/button-share-expand.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-share-expand.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ButtonShareExpandIcon = \"link\" | \"mail\" | \"message\" | \"embed\" | \"download\" | \"qr\";\n\nexport interface ButtonShareExpandAction {\n  id: string;\n  label: string;\n  icon?: ButtonShareExpandIcon | React.ReactNode;\n}\n\nexport interface ButtonShareExpandProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"color\" | \"onChange\"> {\n  label?: string;\n  actions?: ButtonShareExpandAction[];\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  onAction?: (id: string) => void;\n  copyText?: string;\n  accent?: string;\n}\n\nconst defaultActions: ButtonShareExpandAction[] = [\n  { id: \"link\", label: \"Copy link\", icon: \"link\" },\n  { id: \"mail\", label: \"Send by email\", icon: \"mail\" },\n  { id: \"message\", label: \"Send as message\", icon: \"message\" },\n  { id: \"embed\", label: \"Copy embed code\", icon: \"embed\" },\n];\n\nconst css = `\n.hb-xa8 {\n  --hb-xa8-c: #2f7bff;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  box-sizing: border-box;\n  padding: 4px;\n  font-size: 14px;\n  line-height: 1;\n  color: #ededed;\n  background: linear-gradient(180deg, #191919, #111);\n  border-radius: 999px;\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px #262626, 0 12px 30px -18px rgba(0, 0, 0, 0.9);\n  transition: box-shadow 0.3s ease;\n}\n.hb-xa8 *, .hb-xa8 *::before, .hb-xa8 *::after { box-sizing: border-box; }\n.hb-xa8[data-open=\"true\"] { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px #333, 0 16px 34px -18px color-mix(in srgb, var(--hb-xa8-c) 40%, transparent); }\n.hb-xa8-main {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.5em;\n  height: 2.6em;\n  margin: 0;\n  padding: 0 1.1em 0 0.85em;\n  font: inherit;\n  font-weight: 600;\n  color: #0a0a0a;\n  background: linear-gradient(180deg, #fff, #dcdcdc);\n  border: 0;\n  border-radius: 999px;\n  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.12), 0 2px 6px -2px rgba(0, 0, 0, 0.6);\n  cursor: pointer;\n  white-space: nowrap;\n  -webkit-tap-highlight-color: transparent;\n  transition: padding 0.45s cubic-bezier(0.7, 0, 0.2, 1), background 0.3s ease, color 0.3s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-xa8-main:active { transform: scale(0.96); }\n.hb-xa8-main:focus-visible, .hb-xa8-act:focus-visible { outline: 2px solid var(--hb-xa8-c); outline-offset: 2px; }\n.hb-xa8[data-open=\"true\"] .hb-xa8-main { padding: 0 0.8em; color: #ededed; background: #262626; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06); }\n.hb-xa8-glyph { position: relative; width: 1.1em; height: 1.1em; flex: none; }\n.hb-xa8-glyph svg {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;\n}\n.hb-xa8-glyph svg + svg { opacity: 0; transform: rotate(-90deg) scale(0.5); }\n.hb-xa8[data-open=\"true\"] .hb-xa8-glyph svg { opacity: 0; transform: rotate(90deg) scale(0.5); }\n.hb-xa8[data-open=\"true\"] .hb-xa8-glyph svg + svg { opacity: 1; transform: none; }\n.hb-xa8-text {\n  display: inline-block;\n  overflow: hidden;\n  max-width: 8em;\n  transition: max-width 0.45s cubic-bezier(0.7, 0, 0.2, 1), opacity 0.25s ease;\n}\n.hb-xa8[data-open=\"true\"] .hb-xa8-text { max-width: 0; opacity: 0; }\n.hb-xa8-tray {\n  display: grid;\n  grid-template-columns: 0fr;\n  transition: grid-template-columns 0.5s cubic-bezier(0.7, 0, 0.2, 1);\n}\n.hb-xa8[data-open=\"true\"] .hb-xa8-tray { grid-template-columns: 1fr; }\n.hb-xa8-inner { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; padding: 0 0 0 4px; }\n.hb-xa8[data-open=\"true\"] .hb-xa8-inner { animation: hb-xa8-ov 0.5s steps(1, end) forwards; }\n.hb-xa8-act {\n  position: relative;\n  display: grid;\n  place-items: center;\n  width: 2.6em;\n  height: 2.6em;\n  flex: none;\n  margin: 0;\n  padding: 0;\n  color: #d4d4d4;\n  background: transparent;\n  border: 0;\n  border-radius: 50%;\n  cursor: pointer;\n  opacity: 0;\n  transform: scale(0.4) translateX(-8px);\n  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease, background 0.2s ease, color 0.2s ease;\n  transition-delay: 0s;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-xa8[data-open=\"true\"] .hb-xa8-act { opacity: 1; transform: none; transition-delay: calc(0.12s + var(--hb-xa8-i) * 0.05s), calc(0.12s + var(--hb-xa8-i) * 0.05s), 0s, 0s; }\n.hb-xa8-act:hover { color: #fff; background: #222; }\n.hb-xa8-act svg { width: 1.15em; height: 1.15em; }\n.hb-xa8-act[data-done=\"true\"] { color: #0a0a0a; background: var(--hb-xa8-c); }\n.hb-xa8-act[data-done=\"true\"] svg { animation: hb-xa8-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xa8-tip {\n  position: absolute;\n  bottom: calc(100% + 8px);\n  left: 50%;\n  padding: 0.45em 0.65em;\n  font-size: 11px;\n  font-weight: 500;\n  white-space: nowrap;\n  color: #ededed;\n  background: #1f1f1f;\n  border-radius: 6px;\n  box-shadow: inset 0 0 0 1px #2e2e2e, 0 6px 16px -6px rgba(0, 0, 0, 0.8);\n  opacity: 0;\n  pointer-events: none;\n  transform: translate(-50%, 4px);\n  transition: opacity 0.18s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-xa8-act:hover .hb-xa8-tip, .hb-xa8-act:focus-visible .hb-xa8-tip, .hb-xa8-act[data-done=\"true\"] .hb-xa8-tip { opacity: 1; transform: translate(-50%, 0); }\n@keyframes hb-xa8-ov { from { overflow: hidden; } to { overflow: visible; } }\n@keyframes hb-xa8-pop { 0% { transform: scale(0.4); } 100% { transform: scale(1); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xa8, .hb-xa8-main, .hb-xa8-glyph svg, .hb-xa8-text, .hb-xa8-tray, .hb-xa8-act, .hb-xa8-tip { transition: none; }\n  .hb-xa8[data-open=\"true\"] .hb-xa8-act { transition: none; }\n  .hb-xa8-act[data-done=\"true\"] svg { animation: none; }\n  .hb-xa8[data-open=\"true\"] .hb-xa8-inner { animation: none; overflow: visible; }\n}\n`;\n\nconst paths: Record<ButtonShareExpandIcon, React.ReactNode> = {\n  link: (\n    <>\n      <path d=\"M8.5 11.5l3-3\" />\n      <path d=\"M9.6 6.2l1.2-1.2a3 3 0 0 1 4.2 4.2l-1.2 1.2\" />\n      <path d=\"M10.4 13.8l-1.2 1.2a3 3 0 0 1-4.2-4.2l1.2-1.2\" />\n    </>\n  ),\n  mail: (\n    <>\n      <rect x=\"3\" y=\"5\" width=\"14\" height=\"10.5\" rx=\"2\" />\n      <path d=\"M3.6 6.2l6.4 4.6 6.4-4.6\" />\n    </>\n  ),\n  message: <path d=\"M4 5.5A2 2 0 0 1 6 3.5h8a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H9l-3.5 3v-3H6a2 2 0 0 1-2-2v-6Z\" />,\n  embed: (\n    <>\n      <path d=\"M7 6.5L3.5 10 7 13.5\" />\n      <path d=\"M13 6.5l3.5 3.5-3.5 3.5\" />\n      <path d=\"M11 5l-2 10\" />\n    </>\n  ),\n  download: (\n    <>\n      <path d=\"M10 3.5v9\" />\n      <path d=\"M6.5 9l3.5 3.5L13.5 9\" />\n      <path d=\"M4 15.5h12\" />\n    </>\n  ),\n  qr: (\n    <>\n      <rect x=\"3.5\" y=\"3.5\" width=\"5\" height=\"5\" rx=\"1\" />\n      <rect x=\"11.5\" y=\"3.5\" width=\"5\" height=\"5\" rx=\"1\" />\n      <rect x=\"3.5\" y=\"11.5\" width=\"5\" height=\"5\" rx=\"1\" />\n      <path d=\"M11.5 11.5h2v2M16.5 11.5v5h-5\" />\n    </>\n  ),\n};\n\nfunction Glyph({ name }: { name: ButtonShareExpandIcon }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      {paths[name]}\n    </svg>\n  );\n}\n\nconst check = (\n  <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"M4.5 10.5l3.5 3.5 7.5-8\" />\n  </svg>\n);\n\nfunction isIconName(v: unknown): v is ButtonShareExpandIcon {\n  return typeof v === \"string\" && v in paths;\n}\n\nexport function ButtonShareExpand({\n  label = \"Share\",\n  actions = defaultActions,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  onAction,\n  copyText,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: ButtonShareExpandProps) {\n  const [inner, setInner] = React.useState(defaultOpen);\n  const isOpen = open ?? inner;\n  const [done, setDone] = React.useState<string | null>(null);\n  const mainRef = React.useRef<HTMLButtonElement>(null);\n  const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  const trayId = React.useId();\n\n  React.useEffect(() => () => clearTimeout(timer.current), []);\n\n  function setOpen(next: boolean) {\n    if (open === undefined) setInner(next);\n    onOpenChange?.(next);\n  }\n\n  function fire(a: ButtonShareExpandAction) {\n    if (copyText && (a.id === \"link\" || a.id === \"embed\")) {\n      navigator.clipboard?.writeText(copyText).catch(() => {});\n    }\n    setDone(a.id);\n    clearTimeout(timer.current);\n    timer.current = setTimeout(() => setDone(null), 1400);\n    onAction?.(a.id);\n  }\n\n  const vars = { \"--hb-xa8-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-button-share-expand\" precedence=\"default\">{css}</style>\n      <div\n        role=\"group\"\n        aria-label={label}\n        className={`hb-xa8 ${className}`}\n        style={vars}\n        data-open={isOpen || undefined}\n        onKeyDown={(e) => {\n          if (e.key === \"Escape\" && isOpen) {\n            e.stopPropagation();\n            setOpen(false);\n            mainRef.current?.focus();\n          }\n          onKeyDown?.(e);\n        }}\n        {...rest}\n      >\n        <button\n          ref={mainRef}\n          type=\"button\"\n          className=\"hb-xa8-main\"\n          aria-expanded={isOpen}\n          aria-controls={trayId}\n          aria-label={isOpen ? `Close ${label.toLowerCase()} options` : label}\n          onClick={() => setOpen(!isOpen)}\n        >\n          <span className=\"hb-xa8-glyph\" aria-hidden=\"true\">\n            <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n              <path d=\"M10 12.5V3.5\" />\n              <path d=\"M6.5 7L10 3.5 13.5 7\" />\n              <path d=\"M6 10H5a1.5 1.5 0 0 0-1.5 1.5v4A1.5 1.5 0 0 0 5 17h10a1.5 1.5 0 0 0 1.5-1.5v-4A1.5 1.5 0 0 0 15 10h-1\" />\n            </svg>\n            <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\">\n              <path d=\"M5.5 5.5l9 9M14.5 5.5l-9 9\" />\n            </svg>\n          </span>\n          <span className=\"hb-xa8-text\">{label}</span>\n        </button>\n        <div className=\"hb-xa8-tray\" id={trayId}>\n          <div className=\"hb-xa8-inner\">\n            {actions.map((a, i) => {\n              const ok = done === a.id;\n              const icon = isIconName(a.icon) ? <Glyph name={a.icon} /> : a.icon ?? <Glyph name=\"link\" />;\n              return (\n                <button\n                  type=\"button\"\n                  key={a.id}\n                  className=\"hb-xa8-act\"\n                  style={{ \"--hb-xa8-i\": i } as React.CSSProperties}\n                  data-done={ok || undefined}\n                  tabIndex={isOpen ? 0 : -1}\n                  aria-hidden={isOpen ? undefined : true}\n                  aria-label={a.label}\n                  onClick={() => fire(a)}\n                >\n                  {ok ? check : icon}\n                  <span className=\"hb-xa8-tip\" aria-hidden=\"true\">\n                    {ok ? (a.id === \"link\" || a.id === \"embed\" ? \"Copied\" : \"Done\") : a.label}\n                  </span>\n                </button>\n              );\n            })}\n          </div>\n        </div>\n        <span aria-live=\"polite\" style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clip: \"rect(0 0 0 0)\" }}>\n          {done ? `${actions.find((a) => a.id === done)?.label ?? \"\"} done` : \"\"}\n        </span>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}