{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-sheet",
  "type": "registry:component",
  "title": "Share Sheet",
  "description": "A bottom sheet with a scrim, a drag handle, a channel grid and a copy link row. It lives in its own frame, closes on drag down, scrim click or Escape.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "share",
    "sheet",
    "bottom sheet",
    "drag",
    "mobile",
    "modal"
  ],
  "docs": "https://hyperblur.dev/effects/share-sheet",
  "files": [
    {
      "path": "registry/hyperblur/share-sheet.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/share-sheet.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ShareSheetIcon = \"mail\" | \"message\" | \"send\" | \"code\" | \"link\" | \"share\";\n\nexport interface ShareSheetChannel {\n  id: string;\n  label: string;\n  icon?: ShareSheetIcon;\n  href?: string;\n  onSelect?: () => void;\n}\n\nexport interface ShareSheetApi {\n  open: boolean;\n  setOpen: (open: boolean) => void;\n}\n\nexport interface ShareSheetProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"children\"> {\n  children?: React.ReactNode | ((api: ShareSheetApi) => React.ReactNode);\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  url?: string;\n  title?: string;\n  heading?: string;\n  channels?: ShareSheetChannel[];\n  height?: number | string;\n  accent?: string;\n  onShare?: (id: string) => void;\n}\n\nconst css = `\n.hb-qb9 {\n  --hb-qb9-a: #2f7bff;\n  position: relative;\n  width: 100%;\n  overflow: hidden;\n  isolation: isolate;\n  border-radius: inherit;\n  box-sizing: border-box;\n  font-family: inherit;\n}\n.hb-qb9 *, .hb-qb9 *::before, .hb-qb9 *::after { box-sizing: border-box; }\n.hb-qb9-page { position: relative; width: 100%; height: 100%; }\n.hb-qb9-scrim {\n  position: absolute;\n  inset: 0;\n  z-index: 1;\n  background: rgba(0, 0, 0, 0.58);\n  opacity: 0;\n  pointer-events: none;\n  transition: opacity 0.35s ease;\n}\n.hb-qb9-scrim[data-open=\"true\"] { opacity: 1; pointer-events: auto; }\n.hb-qb9-sheet {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  z-index: 2;\n  max-height: calc(100% - 8px);\n  overflow: auto;\n  padding: 0 14px 14px;\n  border-top: 1px solid #2a2a2a;\n  border-radius: 18px 18px 0 0;\n  background: #121212;\n  color: #ededed;\n  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.5);\n  outline: none;\n  transform: translateY(102%);\n  visibility: hidden;\n  transition: transform 0.42s cubic-bezier(0.2, 0.9, 0.25, 1), visibility 0s linear 0.42s;\n}\n.hb-qb9-sheet[data-open=\"true\"] {\n  transform: translateY(0);\n  visibility: visible;\n  transition: transform 0.42s cubic-bezier(0.2, 0.9, 0.25, 1), visibility 0s;\n}\n.hb-qb9-sheet[data-drag=\"true\"] { transition: none; }\n.hb-qb9-head {\n  position: relative;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 16px 0 8px;\n  cursor: grab;\n  touch-action: none;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-qb9-head:active { cursor: grabbing; }\n.hb-qb9-bar {\n  position: absolute;\n  left: 50%;\n  top: 6px;\n  width: 36px;\n  height: 4px;\n  margin-left: -18px;\n  border-radius: 4px;\n  background: #3a3a3a;\n  transition: background-color 0.2s ease, width 0.2s ease, margin-left 0.2s ease;\n}\n.hb-qb9-head:hover .hb-qb9-bar { background: #555555; width: 44px; margin-left: -22px; }\n.hb-qb9-title { margin: 0; font-size: 13px; font-weight: 600; line-height: 1; letter-spacing: 0.01em; }\n.hb-qb9-x {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 24px;\n  height: 24px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: #222222;\n  color: #a1a1a1;\n  cursor: pointer;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: background-color 0.2s ease, color 0.2s ease;\n}\n.hb-qb9-x:hover { background: #2e2e2e; color: #ededed; }\n.hb-qb9-x:focus-visible { outline: 2px solid var(--hb-qb9-a); outline-offset: 2px; }\n.hb-qb9-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-qb9-grid {\n  display: grid;\n  grid-template-columns: repeat(4, minmax(0, 1fr));\n  gap: 6px;\n}\n.hb-qb9-ch {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 6px;\n  min-width: 0;\n  margin: 0;\n  padding: 3px 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-qb9-ch:hover, .hb-qb9-ch:focus-visible { color: #ededed; }\n.hb-qb9-ch:focus-visible { outline: 2px solid var(--hb-qb9-a); outline-offset: 1px; }\n.hb-qb9-chi {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 40px;\n  height: 40px;\n  border: 1px solid #262626;\n  border-radius: 50%;\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-qb9-ch:hover .hb-qb9-chi, .hb-qb9-ch:focus-visible .hb-qb9-chi {\n  border-color: color-mix(in srgb, var(--hb-qb9-a) 55%, #262626);\n  background: color-mix(in srgb, var(--hb-qb9-a) 14%, #1a1a1a);\n  transform: translateY(-2px);\n}\n.hb-qb9-ch:active .hb-qb9-chi { transform: scale(0.94); }\n.hb-qb9-chl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-qb9-field {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  margin-top: 10px;\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-qb9-field:focus-within { border-color: color-mix(in srgb, var(--hb-qb9-a) 60%, #262626); }\n.hb-qb9-lead { display: inline-flex; color: #6f6f6f; }\n.hb-qb9-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-qb9-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-qb9-copy:hover { background: #ffffff; }\n.hb-qb9-copy:active { transform: scale(0.95); }\n.hb-qb9-copy:focus-visible { outline: 2px solid var(--hb-qb9-a); outline-offset: 2px; }\n.hb-qb9-copy[data-done=\"true\"] { background: #7ee787; color: #06280d; }\n.hb-qb9-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-qb9-draw 0.35s ease-out forwards;\n}\n@keyframes hb-qb9-draw { to { stroke-dashoffset: 0; } }\n.hb-qb9-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-qb9-scrim, .hb-qb9-sheet, .hb-qb9-sheet[data-open=\"true\"], .hb-qb9-chi, .hb-qb9-copy, .hb-qb9-bar { transition: none; }\n  .hb-qb9-tick { animation: none; stroke-dashoffset: 0; }\n}\n`;\n\nconst noop = () => () => {};\n\nfunction Glyph({ name, className = \"hb-qb9-ico\" }: { name: ShareSheetIcon | \"copy\" | \"tick\" | \"close\"; 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    case \"close\":\n      body = <path d=\"M7 7l10 10M17 7L7 17\" />;\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: ShareSheetChannel[] = [\n  { id: \"message\", label: \"Messages\", icon: \"message\" },\n  { id: \"email\", label: \"Email\", icon: \"mail\" },\n  { id: \"embed\", label: \"Embed\", icon: \"code\" },\n  { id: \"native\", label: \"More\", icon: \"share\" },\n];\n\nexport function ShareSheet({\n  children,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  url = \"\",\n  title = \"\",\n  heading = \"Share\",\n  channels = defaultChannels,\n  height = 320,\n  accent = \"#2f7bff\",\n  onShare,\n  className = \"\",\n  style,\n  ...rest\n}: ShareSheetProps) {\n  const openControlled = open !== undefined;\n  const [innerOpen, setInnerOpen] = React.useState(defaultOpen);\n  const isOpen = openControlled ? open : innerOpen;\n  const [drag, setDrag] = React.useState(0);\n  const [dragging, setDragging] = React.useState(false);\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 sheetRef = React.useRef<HTMLDivElement>(null);\n  const opener = React.useRef<HTMLElement | null>(null);\n  const timer = React.useRef<number | undefined>(undefined);\n  const gesture = React.useRef({ y: 0, t: 0, dy: 0, id: -1 });\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (!openControlled) setInnerOpen(next);\n      onOpenChange?.(next);\n    },\n    [openControlled, onOpenChange],\n  );\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const sheet = sheetRef.current;\n    const active = document.activeElement;\n    if (isOpen) {\n      if (root && active && active !== document.body && root.contains(active)) {\n        opener.current = active as HTMLElement;\n        sheet?.focus({ preventScroll: true });\n      }\n    } else if (opener.current) {\n      if (active === document.body || sheet?.contains(active)) {\n        opener.current.focus({ preventScroll: true });\n      }\n      opener.current = null;\n    }\n  }, [isOpen]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    function key(e: KeyboardEvent) {\n      if (e.key === \"Escape\") setOpen(false);\n    }\n    document.addEventListener(\"keydown\", key);\n    return () => document.removeEventListener(\"keydown\", key);\n  }, [isOpen, setOpen]);\n\n  function down(e: React.PointerEvent<HTMLDivElement>) {\n    if ((e.target as HTMLElement).closest(\"button\")) return;\n    if (e.pointerType === \"mouse\" && e.button !== 0) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    gesture.current = { y: e.clientY, t: e.timeStamp, dy: 0, id: e.pointerId };\n    setDragging(true);\n  }\n\n  function move(e: React.PointerEvent<HTMLDivElement>) {\n    if (gesture.current.id !== e.pointerId) return;\n    const dy = Math.max(0, e.clientY - gesture.current.y);\n    gesture.current.dy = dy;\n    setDrag(dy);\n  }\n\n  function up(e: React.PointerEvent<HTMLDivElement>) {\n    if (gesture.current.id !== e.pointerId) return;\n    const { dy, t } = gesture.current;\n    const speed = dy / Math.max(1, e.timeStamp - t);\n    gesture.current.id = -1;\n    setDragging(false);\n    setDrag(0);\n    if (dy > 70 || (dy > 18 && speed > 0.6)) setOpen(false);\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 copyLink() {\n    await copyText(shareUrl);\n    flash(\"link\");\n    onShare?.(\"copy\");\n  }\n\n  async function run(channel: ShareSheetChannel) {\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: ShareSheetChannel) {\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-qb9-a\": accent, height, ...style } as React.CSSProperties;\n  const api: ShareSheetApi = { open: isOpen, setOpen };\n  const sheetStyle: React.CSSProperties | undefined =\n    isOpen && drag > 0 ? { transform: `translateY(${drag.toFixed(1)}px)` } : undefined;\n\n  return (\n    <div ref={rootRef} className={`hb-qb9 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-share-sheet\" precedence=\"default\">{css}</style>\n      <div className=\"hb-qb9-page\">{typeof children === \"function\" ? children(api) : children}</div>\n      <div className=\"hb-qb9-scrim\" data-open={isOpen ? \"true\" : \"false\"} aria-hidden=\"true\" onClick={() => setOpen(false)} />\n      <div\n        ref={sheetRef}\n        role=\"dialog\"\n        aria-label={heading}\n        tabIndex={-1}\n        className=\"hb-qb9-sheet\"\n        data-open={isOpen ? \"true\" : \"false\"}\n        data-drag={dragging ? \"true\" : \"false\"}\n        style={sheetStyle}\n        inert={!isOpen}\n      >\n        <div className=\"hb-qb9-head\" onPointerDown={down} onPointerMove={move} onPointerUp={up} onPointerCancel={up}>\n          <span className=\"hb-qb9-bar\" aria-hidden=\"true\" />\n          <h2 className=\"hb-qb9-title\">{heading}</h2>\n          <button type=\"button\" className=\"hb-qb9-x\" aria-label=\"Close\" onClick={() => setOpen(false)}>\n            <Glyph name=\"close\" className=\"hb-qb9-ico\" />\n          </button>\n        </div>\n        <div className=\"hb-qb9-grid\" role=\"group\" aria-label=\"Share channels\">\n          {channels.map((channel) => {\n            const href = hrefFor(channel);\n            const inner = (\n              <>\n                <span className=\"hb-qb9-chi\">\n                  <Glyph name={done === channel.id ? \"tick\" : (channel.icon ?? \"send\")} />\n                </span>\n                <span className=\"hb-qb9-chl\">{done === channel.id ? \"Copied\" : channel.label}</span>\n              </>\n            );\n            return href && !channel.onSelect ? (\n              <a\n                key={channel.id}\n                className=\"hb-qb9-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-qb9-ch\" onClick={() => run(channel)}>\n                {inner}\n              </button>\n            );\n          })}\n        </div>\n        <div className=\"hb-qb9-field\">\n          <span className=\"hb-qb9-lead\">\n            <Glyph name=\"link\" />\n          </span>\n          <input\n            className=\"hb-qb9-input\"\n            readOnly\n            value={shareUrl}\n            aria-label=\"Link\"\n            onFocus={(e) => e.currentTarget.select()}\n          />\n          <button type=\"button\" className=\"hb-qb9-copy\" data-done={done === \"link\" ? \"true\" : \"false\"} onClick={copyLink}>\n            {done === \"link\" ? <Glyph name=\"tick\" className=\"hb-qb9-tick\" /> : <Glyph name=\"copy\" />}\n            {done === \"link\" ? \"Copied\" : \"Copy\"}\n          </button>\n        </div>\n      </div>\n      <span className=\"hb-qb9-sr\" role=\"status\" aria-live=\"polite\">\n        {done ? \"Copied to clipboard\" : \"\"}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}