{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-floating-rail",
  "type": "registry:component",
  "title": "Share Floating Rail",
  "description": "A round share trigger that fans a vertical rail of icon buttons out with a staggered spring. Each button shows a tooltip on hover or focus.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "share",
    "floating",
    "rail",
    "fab",
    "tooltip",
    "stagger"
  ],
  "docs": "https://hyperblur.dev/effects/share-floating-rail",
  "files": [
    {
      "path": "registry/hyperblur/share-floating-rail.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/share-floating-rail.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ShareRailIcon = \"mail\" | \"message\" | \"send\" | \"code\" | \"link\" | \"share\" | \"copy\";\n\nexport interface ShareRailItem {\n  id: string;\n  label: string;\n  icon?: ShareRailIcon;\n  href?: string;\n  onSelect?: () => void;\n}\n\nexport interface ShareFloatingRailProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"children\"> {\n  items?: ShareRailItem[];\n  url?: string;\n  title?: string;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  direction?: \"up\" | \"down\";\n  tooltipSide?: \"left\" | \"right\";\n  size?: number;\n  accent?: string;\n  label?: string;\n  onShare?: (id: string) => void;\n}\n\nconst css = `\n.hb-qba {\n  --hb-qba-a: #2f7bff;\n  position: relative;\n  display: inline-block;\n  width: var(--hb-qba-s);\n  height: var(--hb-qba-s);\n  box-sizing: border-box;\n  font-family: inherit;\n}\n.hb-qba *, .hb-qba *::before, .hb-qba *::after { box-sizing: border-box; }\n.hb-qba-trigger {\n  position: relative;\n  z-index: 2;\n  display: block;\n  width: 100%;\n  height: 100%;\n  margin: 0;\n  padding: 0;\n  border: 1px solid #2e2e2e;\n  border-radius: 50%;\n  background: #ededed;\n  color: #0a0a0a;\n  cursor: pointer;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);\n  transition: background-color 0.25s ease, color 0.25s ease, transform 0.12s ease;\n}\n.hb-qba-trigger:hover { background: #ffffff; }\n.hb-qba-trigger:active { transform: scale(0.93); }\n.hb-qba-trigger:focus-visible { outline: 2px solid var(--hb-qba-a); outline-offset: 3px; }\n.hb-qba-trigger[aria-expanded=\"true\"] { background: #171717; color: #ededed; border-color: #3a3a3a; }\n.hb-qba-glyph {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: calc(var(--hb-qba-s) * 0.46);\n  height: calc(var(--hb-qba-s) * 0.46);\n  margin: calc(var(--hb-qba-s) * -0.23) 0 0 calc(var(--hb-qba-s) * -0.23);\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 1.9;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  transition: opacity 0.25s ease, transform 0.4s cubic-bezier(0.3, 1.4, 0.5, 1);\n}\n.hb-qba-trigger[aria-expanded=\"true\"] .hb-qba-share { opacity: 0; transform: rotate(90deg) scale(0.4); }\n.hb-qba-trigger[aria-expanded=\"false\"] .hb-qba-x { opacity: 0; transform: rotate(-90deg) scale(0.4); }\n.hb-qba-rail { position: absolute; inset: 0; z-index: 1; }\n.hb-qba-slot {\n  position: absolute;\n  left: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: var(--hb-qba-s);\n  height: var(--hb-qba-s);\n  opacity: 0;\n  pointer-events: none;\n  transform: translate(0, 0) scale(0.3);\n  transition: transform 0.28s cubic-bezier(0.4, 0, 0.8, 0.6) calc(var(--hb-qba-r) * 40ms), opacity 0.2s ease calc(var(--hb-qba-r) * 40ms);\n}\n.hb-qba[data-d=\"up\"] .hb-qba-slot { bottom: 0; }\n.hb-qba[data-d=\"down\"] .hb-qba-slot { top: 0; }\n.hb-qba[data-open=\"true\"] .hb-qba-slot {\n  opacity: 1;\n  pointer-events: auto;\n  transform: translate(var(--hb-qba-x), calc(var(--hb-qba-i) * var(--hb-qba-p) * var(--hb-qba-dir))) scale(1);\n  transition: transform 0.55s cubic-bezier(0.3, 1.45, 0.5, 1) calc(var(--hb-qba-i) * 55ms), opacity 0.25s ease calc(var(--hb-qba-i) * 55ms);\n}\n.hb-qba[data-d=\"up\"] { --hb-qba-dir: -1; }\n.hb-qba[data-d=\"down\"] { --hb-qba-dir: 1; }\n.hb-qba-item {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: calc(var(--hb-qba-s) * 0.86);\n  height: calc(var(--hb-qba-s) * 0.86);\n  margin: 0;\n  padding: 0;\n  border: 1px solid #2a2a2a;\n  border-radius: 50%;\n  background: #171717;\n  color: #cfcfcf;\n  text-decoration: none;\n  cursor: pointer;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);\n  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.18s cubic-bezier(0.3, 1.5, 0.5, 1);\n}\n.hb-qba-item:hover, .hb-qba-item:focus-visible {\n  border-color: color-mix(in srgb, var(--hb-qba-a) 60%, #2a2a2a);\n  background: color-mix(in srgb, var(--hb-qba-a) 16%, #171717);\n  color: #ffffff;\n  transform: scale(1.12);\n}\n.hb-qba-item:active { transform: scale(0.94); }\n.hb-qba-item:focus-visible { outline: 2px solid var(--hb-qba-a); outline-offset: 2px; }\n.hb-qba-item[data-done=\"true\"] { border-color: #7ee787; color: #7ee787; }\n.hb-qba-ico {\n  display: block;\n  width: calc(var(--hb-qba-s) * 0.4);\n  height: calc(var(--hb-qba-s) * 0.4);\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 1.9;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qba-tip {\n  position: absolute;\n  top: 50%;\n  padding: 5px 9px;\n  border: 1px solid #2a2a2a;\n  border-radius: 999px;\n  background: #171717;\n  color: #ededed;\n  font-size: 11px;\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  pointer-events: none;\n  opacity: 0;\n  transition: opacity 0.15s ease, transform 0.2s cubic-bezier(0.3, 1.4, 0.5, 1);\n}\n.hb-qba[data-t=\"left\"] .hb-qba-tip { right: calc(100% + 8px); transform: translate(6px, -50%); }\n.hb-qba[data-t=\"right\"] .hb-qba-tip { left: calc(100% + 8px); transform: translate(-6px, -50%); }\n.hb-qba-slot:hover .hb-qba-tip, .hb-qba-slot:focus-within .hb-qba-tip, .hb-qba-tip[data-show=\"true\"] { opacity: 1; }\n.hb-qba[data-t=\"left\"] .hb-qba-slot:hover .hb-qba-tip,\n.hb-qba[data-t=\"left\"] .hb-qba-slot:focus-within .hb-qba-tip,\n.hb-qba[data-t=\"left\"] .hb-qba-tip[data-show=\"true\"] { transform: translate(0, -50%); }\n.hb-qba[data-t=\"right\"] .hb-qba-slot:hover .hb-qba-tip,\n.hb-qba[data-t=\"right\"] .hb-qba-slot:focus-within .hb-qba-tip,\n.hb-qba[data-t=\"right\"] .hb-qba-tip[data-show=\"true\"] { transform: translate(0, -50%); }\n.hb-qba-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-qba-trigger, .hb-qba-glyph, .hb-qba-item, .hb-qba-tip { transition: none; }\n  .hb-qba-slot, .hb-qba[data-open=\"true\"] .hb-qba-slot { transition: none; }\n}\n`;\n\nconst noop = () => () => {};\n\nfunction Glyph({ name, className = \"hb-qba-ico\" }: { name: ShareRailIcon | \"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 defaultItems: ShareRailItem[] = [\n  { id: \"copy\", label: \"Copy link\", icon: \"copy\" },\n  { id: \"email\", label: \"Email\", icon: \"mail\" },\n  { id: \"message\", label: \"Message\", icon: \"message\" },\n  { id: \"native\", label: \"More\", icon: \"send\" },\n];\n\nexport function ShareFloatingRail({\n  items = defaultItems,\n  url = \"\",\n  title = \"\",\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  direction = \"up\",\n  tooltipSide = \"left\",\n  size = 44,\n  accent = \"#2f7bff\",\n  label = \"Share\",\n  onShare,\n  className = \"\",\n  style,\n  ...rest\n}: ShareFloatingRailProps) {\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 railRef = 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      railRef.current?.querySelector<HTMLElement>(\"a, button\")?.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 onKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (!isOpen) return;\n    const outward = direction === \"up\" ? \"ArrowUp\" : \"ArrowDown\";\n    const inward = direction === \"up\" ? \"ArrowDown\" : \"ArrowUp\";\n    if (e.key !== outward && e.key !== inward) return;\n    const list = [\n      triggerRef.current,\n      ...Array.from(railRef.current?.querySelectorAll<HTMLElement>(\"a, button\") ?? []),\n    ].filter((n): n is HTMLElement => n !== null);\n    const at = list.indexOf(document.activeElement as HTMLElement);\n    if (at < 0) return;\n    e.preventDefault();\n    const next = e.key === outward ? Math.min(list.length - 1, at + 1) : Math.max(0, at - 1);\n    list[next]?.focus();\n  }\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 run(item: ShareRailItem) {\n    onShare?.(item.id);\n    if (item.onSelect) {\n      item.onSelect();\n      return;\n    }\n    if (item.id === \"copy\") {\n      await copyText(shareUrl);\n      flash(item.id);\n      return;\n    }\n    if (item.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        setOpen(false);\n      } else {\n        await copyText(shareUrl);\n        flash(item.id);\n      }\n    }\n  }\n\n  function hrefFor(item: ShareRailItem) {\n    if (item.href) return item.href;\n    if (item.id === \"email\") {\n      return `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(shareUrl)}`;\n    }\n    if (item.id === \"message\") {\n      return `sms:?&body=${encodeURIComponent([title, shareUrl].filter(Boolean).join(\" \"))}`;\n    }\n    return undefined;\n  }\n\n  const pitch = size + 8;\n  const sign = tooltipSide === \"left\" ? 1 : -1;\n  const vars = {\n    \"--hb-qba-a\": accent,\n    \"--hb-qba-s\": `${size}px`,\n    \"--hb-qba-p\": `${pitch}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-qba ${className}`}\n      style={vars}\n      data-open={isOpen ? \"true\" : \"false\"}\n      data-d={direction}\n      data-t={tooltipSide}\n      onKeyDown={onKeyDown}\n      {...rest}\n    >\n      <style href=\"hb-share-floating-rail\" precedence=\"default\">{css}</style>\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        className=\"hb-qba-trigger\"\n        aria-expanded={isOpen}\n        aria-label={isOpen ? `Close ${label.toLowerCase()} options` : label}\n        onClick={(e) => {\n          viaKey.current = e.detail === 0;\n          setOpen(!isOpen);\n        }}\n      >\n        <svg className=\"hb-qba-glyph hb-qba-share\" viewBox=\"0 0 24 24\" aria-hidden=\"true\">\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        </svg>\n        <svg className=\"hb-qba-glyph hb-qba-x\" viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n          <path d=\"M6.5 6.5l11 11M17.5 6.5l-11 11\" />\n        </svg>\n      </button>\n      <div ref={railRef} className=\"hb-qba-rail\" role=\"group\" aria-label={`${label} options`} inert={!isOpen}>\n        {items.map((item, index) => {\n          const href = hrefFor(item);\n          const copied = done === item.id;\n          const slot = {\n            \"--hb-qba-i\": index + 1,\n            \"--hb-qba-r\": items.length - index,\n            \"--hb-qba-x\": `${(Math.sin(((index + 1) / (items.length + 1)) * Math.PI) * 7 * sign).toFixed(2)}px`,\n          } as React.CSSProperties;\n          const inner = (\n            <>\n              <Glyph name={copied ? \"tick\" : (item.icon ?? \"send\")} />\n              <span className=\"hb-qba-sr\">{item.label}</span>\n            </>\n          );\n          return (\n            <span key={item.id} className=\"hb-qba-slot\" style={slot}>\n              {href && !item.onSelect ? (\n                <a\n                  className=\"hb-qba-item\"\n                  href={href}\n                  target={href.startsWith(\"http\") ? \"_blank\" : undefined}\n                  rel={href.startsWith(\"http\") ? \"noopener noreferrer\" : undefined}\n                  onClick={() => {\n                    onShare?.(item.id);\n                    setOpen(false);\n                  }}\n                >\n                  {inner}\n                </a>\n              ) : (\n                <button type=\"button\" className=\"hb-qba-item\" data-done={copied ? \"true\" : \"false\"} onClick={() => run(item)}>\n                  {inner}\n                </button>\n              )}\n              <span className=\"hb-qba-tip\" data-show={copied ? \"true\" : \"false\"} aria-hidden=\"true\">\n                {copied ? \"Copied\" : item.label}\n              </span>\n            </span>\n          );\n        })}\n      </div>\n      <span className=\"hb-qba-sr\" role=\"status\" aria-live=\"polite\">\n        {done ? \"Copied to clipboard\" : \"\"}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}