{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-popover",
  "type": "registry:component",
  "title": "Share Popover",
  "description": "A share button that opens an anchored popover with a link field, a copy button that confirms and four generic channels. Escape and outside click close it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "share",
    "popover",
    "copy link",
    "clipboard",
    "menu",
    "channels"
  ],
  "docs": "https://hyperblur.dev/effects/share-popover",
  "files": [
    {
      "path": "registry/hyperblur/share-popover.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/share-popover.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type SharePopoverIcon = \"mail\" | \"message\" | \"send\" | \"code\" | \"link\" | \"share\";\n\nexport interface SharePopoverChannel {\n  id: string;\n  label: string;\n  icon?: SharePopoverIcon;\n  href?: string;\n  onSelect?: () => void;\n}\n\nexport interface SharePopoverProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"children\"> {\n  url?: string;\n  title?: string;\n  channels?: SharePopoverChannel[];\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  placement?: \"bottom\" | \"top\";\n  align?: \"start\" | \"end\";\n  triggerLabel?: string;\n  accent?: string;\n  onShare?: (id: string) => void;\n}\n\nconst css = `\n.hb-qb8 {\n  --hb-qb8-a: #2f7bff;\n  position: relative;\n  display: inline-block;\n  box-sizing: border-box;\n  font-family: inherit;\n}\n.hb-qb8 *, .hb-qb8 *::before, .hb-qb8 *::after { box-sizing: border-box; }\n.hb-qb8-trigger {\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  height: 36px;\n  margin: 0;\n  padding: 0 14px 0 11px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #171717;\n  color: #ededed;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  cursor: pointer;\n  user-select: none;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.12s ease;\n}\n.hb-qb8-trigger:hover { border-color: #3a3a3a; background: #1c1c1c; }\n.hb-qb8-trigger:active { transform: scale(0.96); }\n.hb-qb8-trigger[aria-expanded=\"true\"] {\n  border-color: color-mix(in srgb, var(--hb-qb8-a) 55%, #262626);\n  background: color-mix(in srgb, var(--hb-qb8-a) 10%, #171717);\n}\n.hb-qb8-trigger:focus-visible { outline: 2px solid var(--hb-qb8-a); outline-offset: 2px; }\n.hb-qb8-ico {\n  display: block;\n  width: 16px;\n  height: 16px;\n  flex: none;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 1.8;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qb8-panel {\n  position: absolute;\n  z-index: 20;\n  width: 304px;\n  max-width: calc(100vw - 24px);\n  padding: 12px;\n  border: 1px solid #262626;\n  border-radius: 16px;\n  background: #121212;\n  color: #ededed;\n  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;\n  outline: none;\n  animation: hb-qb8-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);\n}\n.hb-qb8-panel[data-p=\"bottom\"] { top: calc(100% + 8px); }\n.hb-qb8-panel[data-p=\"top\"] { bottom: calc(100% + 8px); }\n.hb-qb8-panel[data-al=\"start\"] { left: 0; }\n.hb-qb8-panel[data-al=\"end\"] { right: 0; }\n.hb-qb8-panel[data-p=\"bottom\"][data-al=\"start\"] { transform-origin: 18px 0; }\n.hb-qb8-panel[data-p=\"bottom\"][data-al=\"end\"] { transform-origin: calc(100% - 18px) 0; }\n.hb-qb8-panel[data-p=\"top\"][data-al=\"start\"] { transform-origin: 18px 100%; }\n.hb-qb8-panel[data-p=\"top\"][data-al=\"end\"] { transform-origin: calc(100% - 18px) 100%; }\n@keyframes hb-qb8-in {\n  from { opacity: 0; transform: translateY(-6px) scale(0.96); }\n  to { opacity: 1; transform: translateY(0) scale(1); }\n}\n.hb-qb8-panel[data-p=\"top\"] { animation-name: hb-qb8-in-up; }\n@keyframes hb-qb8-in-up {\n  from { opacity: 0; transform: translateY(6px) scale(0.96); }\n  to { opacity: 1; transform: translateY(0) scale(1); }\n}\n.hb-qb8-field {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  padding: 3px 3px 3px 10px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #0a0a0a;\n  transition: border-color 0.2s ease;\n}\n.hb-qb8-field:focus-within { border-color: color-mix(in srgb, var(--hb-qb8-a) 60%, #262626); }\n.hb-qb8-lead { display: inline-flex; color: #6f6f6f; }\n.hb-qb8-input {\n  flex: 1;\n  min-width: 0;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  outline: none;\n  background: transparent;\n  color: #cfcfcf;\n  font: inherit;\n  font-size: 12px;\n  text-overflow: ellipsis;\n}\n.hb-qb8-copy {\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  height: 28px;\n  margin: 0;\n  padding: 0 11px;\n  border: 0;\n  border-radius: 9px;\n  background: #ededed;\n  color: #0a0a0a;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  cursor: pointer;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: background-color 0.2s ease, color 0.2s ease, transform 0.12s ease;\n}\n.hb-qb8-copy:hover { background: #ffffff; }\n.hb-qb8-copy:active { transform: scale(0.95); }\n.hb-qb8-copy:focus-visible { outline: 2px solid var(--hb-qb8-a); outline-offset: 2px; }\n.hb-qb8-copy[data-done=\"true\"] { background: #7ee787; color: #06280d; }\n.hb-qb8-tick {\n  display: block;\n  width: 12px;\n  height: 12px;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 2.6;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  stroke-dasharray: 20;\n  stroke-dashoffset: 20;\n  animation: hb-qb8-draw 0.35s ease-out forwards;\n}\n@keyframes hb-qb8-draw { to { stroke-dashoffset: 0; } }\n.hb-qb8-grid {\n  display: grid;\n  grid-template-columns: repeat(4, minmax(0, 1fr));\n  gap: 6px;\n  margin-top: 10px;\n}\n.hb-qb8-ch {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 6px;\n  min-width: 0;\n  margin: 0;\n  padding: 4px 0 2px;\n  border: 0;\n  border-radius: 12px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  font-size: 11px;\n  font-weight: 500;\n  line-height: 1;\n  text-decoration: none;\n  cursor: pointer;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: color 0.2s ease;\n}\n.hb-qb8-ch:hover, .hb-qb8-ch:focus-visible { color: #ededed; }\n.hb-qb8-ch:focus-visible { outline: 2px solid var(--hb-qb8-a); outline-offset: 1px; }\n.hb-qb8-chi {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 38px;\n  height: 38px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #1a1a1a;\n  color: #ededed;\n  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.18s cubic-bezier(0.3, 1.5, 0.5, 1);\n}\n.hb-qb8-ch:hover .hb-qb8-chi, .hb-qb8-ch:focus-visible .hb-qb8-chi {\n  border-color: color-mix(in srgb, var(--hb-qb8-a) 55%, #262626);\n  background: color-mix(in srgb, var(--hb-qb8-a) 14%, #1a1a1a);\n  transform: translateY(-2px);\n}\n.hb-qb8-ch:active .hb-qb8-chi { transform: scale(0.94); }\n.hb-qb8-chl {\n  max-width: 100%;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n}\n.hb-qb8-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qb8-trigger, .hb-qb8-copy, .hb-qb8-chi, .hb-qb8-field, .hb-qb8-ch { transition: none; }\n  .hb-qb8-panel { animation: none; }\n  .hb-qb8-tick { animation: none; stroke-dashoffset: 0; }\n}\n`;\n\nconst noop = () => () => {};\n\nfunction Glyph({ name, className = \"hb-qb8-ico\" }: { name: SharePopoverIcon | \"copy\" | \"tick\"; className?: string }) {\n  let body: React.ReactNode;\n  switch (name) {\n    case \"mail\":\n      body = (\n        <>\n          <rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2.5\" />\n          <path d=\"M3.5 7.5l8.5 6 8.5-6\" />\n        </>\n      );\n      break;\n    case \"message\":\n      body = <path d=\"M5 4.5h14a1.5 1.5 0 011.5 1.5v9a1.5 1.5 0 01-1.5 1.5h-7.5L7 20.5V16.5H5A1.5 1.5 0 013.5 15V6A1.5 1.5 0 015 4.5z\" />;\n      break;\n    case \"send\":\n      body = <path d=\"M20.5 3.5L10 14M20.5 3.5L14 20.5l-4-6.5-6.5-4z\" />;\n      break;\n    case \"code\":\n      body = <path d=\"M8 8l-4 4 4 4M16 8l4 4-4 4M13.6 6l-3.2 12\" />;\n      break;\n    case \"link\":\n      body = (\n        <>\n          <path d=\"M10 14a4 4 0 005.7 0l3-3a4 4 0 00-5.7-5.7l-1 1\" />\n          <path d=\"M14 10a4 4 0 00-5.7 0l-3 3a4 4 0 005.7 5.7l1-1\" />\n        </>\n      );\n      break;\n    case \"copy\":\n      body = (\n        <>\n          <rect x=\"8\" y=\"8\" width=\"12\" height=\"12\" rx=\"2\" />\n          <path d=\"M16 8V6a2 2 0 00-2-2H6a2 2 0 00-2 2v8a2 2 0 002 2h2\" />\n        </>\n      );\n      break;\n    case \"tick\":\n      body = <path d=\"M5 12.5l4.5 4.5L19 7.5\" />;\n      break;\n    default:\n      body = (\n        <>\n          <circle cx=\"6\" cy=\"12\" r=\"2.5\" />\n          <circle cx=\"17.5\" cy=\"6\" r=\"2.5\" />\n          <circle cx=\"17.5\" cy=\"18\" r=\"2.5\" />\n          <path d=\"M8.3 10.8l7-3.6M8.3 13.2l7 3.6\" />\n        </>\n      );\n  }\n  return (\n    <svg className={className} viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n      {body}\n    </svg>\n  );\n}\n\nasync function copyText(value: string) {\n  try {\n    await navigator.clipboard.writeText(value);\n  } catch {\n    const area = document.createElement(\"textarea\");\n    area.value = value;\n    area.setAttribute(\"readonly\", \"\");\n    area.style.position = \"fixed\";\n    area.style.opacity = \"0\";\n    document.body.appendChild(area);\n    area.select();\n    document.execCommand(\"copy\");\n    area.remove();\n  }\n}\n\nconst defaultChannels: SharePopoverChannel[] = [\n  { id: \"email\", label: \"Email\", icon: \"mail\" },\n  { id: \"message\", label: \"Message\", icon: \"message\" },\n  { id: \"embed\", label: \"Embed\", icon: \"code\" },\n  { id: \"native\", label: \"More\", icon: \"share\" },\n];\n\nexport function SharePopover({\n  url = \"\",\n  title = \"\",\n  channels = defaultChannels,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  placement = \"bottom\",\n  align = \"start\",\n  triggerLabel = \"Share\",\n  accent = \"#2f7bff\",\n  onShare,\n  className = \"\",\n  style,\n  ...rest\n}: SharePopoverProps) {\n  const openControlled = open !== undefined;\n  const [innerOpen, setInnerOpen] = React.useState(defaultOpen);\n  const isOpen = openControlled ? open : innerOpen;\n  const [done, setDone] = React.useState<string | null>(null);\n\n  const here = React.useSyncExternalStore(\n    noop,\n    () => window.location.href,\n    () => \"\",\n  );\n  const shareUrl = url || here;\n\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const timer = React.useRef<number | undefined>(undefined);\n  const viaKey = React.useRef(false);\n\n  function setOpen(next: boolean) {\n    if (!openControlled) setInnerOpen(next);\n    onOpenChange?.(next);\n  }\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  React.useEffect(() => {\n    if (isOpen && viaKey.current) {\n      panelRef.current?.focus({ preventScroll: true });\n    }\n    viaKey.current = false;\n  }, [isOpen]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    function down(e: PointerEvent) {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) {\n        if (!openControlled) setInnerOpen(false);\n        onOpenChange?.(false);\n      }\n    }\n    function key(e: KeyboardEvent) {\n      if (e.key === \"Escape\") {\n        if (!openControlled) setInnerOpen(false);\n        onOpenChange?.(false);\n        if (rootRef.current?.contains(document.activeElement)) triggerRef.current?.focus();\n      }\n    }\n    document.addEventListener(\"pointerdown\", down);\n    document.addEventListener(\"keydown\", key);\n    return () => {\n      document.removeEventListener(\"pointerdown\", down);\n      document.removeEventListener(\"keydown\", key);\n    };\n  }, [isOpen, openControlled, onOpenChange]);\n\n  function flash(id: string) {\n    setDone(id);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setDone(null), 1600);\n  }\n\n  async function copyLink() {\n    await copyText(shareUrl);\n    flash(\"link\");\n    onShare?.(\"copy\");\n  }\n\n  async function run(channel: SharePopoverChannel) {\n    onShare?.(channel.id);\n    if (channel.onSelect) {\n      channel.onSelect();\n      return;\n    }\n    if (channel.id === \"embed\") {\n      await copyText(`<iframe src=\"${shareUrl}\" width=\"560\" height=\"315\" frameborder=\"0\"></iframe>`);\n      flash(channel.id);\n      return;\n    }\n    if (channel.id === \"native\") {\n      if (typeof navigator.share === \"function\") {\n        try {\n          await navigator.share({ title: title || undefined, url: shareUrl });\n        } catch {\n          return;\n        }\n      } else {\n        await copyText(shareUrl);\n        flash(channel.id);\n      }\n    }\n  }\n\n  function hrefFor(channel: SharePopoverChannel) {\n    if (channel.href) return channel.href;\n    if (channel.id === \"email\") {\n      return `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(shareUrl)}`;\n    }\n    if (channel.id === \"message\") {\n      return `sms:?&body=${encodeURIComponent([title, shareUrl].filter(Boolean).join(\" \"))}`;\n    }\n    return undefined;\n  }\n\n  const vars = { \"--hb-qb8-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-qb8 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-share-popover\" precedence=\"default\">{css}</style>\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        className=\"hb-qb8-trigger\"\n        aria-haspopup=\"dialog\"\n        aria-expanded={isOpen}\n        onClick={(e) => {\n          viaKey.current = e.detail === 0;\n          setOpen(!isOpen);\n        }}\n      >\n        <Glyph name=\"share\" />\n        {triggerLabel}\n      </button>\n      {isOpen && (\n        <div\n          ref={panelRef}\n          role=\"dialog\"\n          aria-label=\"Share\"\n          tabIndex={-1}\n          className=\"hb-qb8-panel\"\n          data-p={placement}\n          data-al={align}\n        >\n          <div className=\"hb-qb8-field\">\n            <span className=\"hb-qb8-lead\">\n              <Glyph name=\"link\" />\n            </span>\n            <input\n              className=\"hb-qb8-input\"\n              readOnly\n              value={shareUrl}\n              aria-label=\"Link\"\n              onFocus={(e) => e.currentTarget.select()}\n            />\n            <button type=\"button\" className=\"hb-qb8-copy\" data-done={done === \"link\" ? \"true\" : \"false\"} onClick={copyLink}>\n              {done === \"link\" ? <Glyph name=\"tick\" className=\"hb-qb8-tick\" /> : <Glyph name=\"copy\" className=\"hb-qb8-ico\" />}\n              {done === \"link\" ? \"Copied\" : \"Copy\"}\n            </button>\n          </div>\n          <div className=\"hb-qb8-grid\" role=\"group\" aria-label=\"Share channels\">\n            {channels.map((channel) => {\n              const href = hrefFor(channel);\n              const inner = (\n                <>\n                  <span className=\"hb-qb8-chi\">\n                    <Glyph name={done === channel.id ? \"tick\" : (channel.icon ?? \"send\")} />\n                  </span>\n                  <span className=\"hb-qb8-chl\">{done === channel.id ? \"Copied\" : channel.label}</span>\n                </>\n              );\n              return href && !channel.onSelect ? (\n                <a\n                  key={channel.id}\n                  className=\"hb-qb8-ch\"\n                  href={href}\n                  target={href.startsWith(\"http\") ? \"_blank\" : undefined}\n                  rel={href.startsWith(\"http\") ? \"noopener noreferrer\" : undefined}\n                  onClick={() => onShare?.(channel.id)}\n                >\n                  {inner}\n                </a>\n              ) : (\n                <button key={channel.id} type=\"button\" className=\"hb-qb8-ch\" onClick={() => run(channel)}>\n                  {inner}\n                </button>\n              );\n            })}\n          </div>\n        </div>\n      )}\n      <span className=\"hb-qb8-sr\" role=\"status\" aria-live=\"polite\">\n        {done ? \"Copied to clipboard\" : \"\"}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}