{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-buttons",
  "title": "Share Buttons",
  "description": "Share buttons for X, LinkedIn, Facebook, Reddit, WhatsApp and email with a copy-link button that turns into a tick: round icons with hover labels, labelled pills, or a single Share button that fans out into the row, plus the device's own share sheet where it exists.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/share-buttons/share-buttons.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type ShareNetwork = \"x\" | \"linkedin\" | \"facebook\" | \"reddit\" | \"whatsapp\" | \"email\" | \"copy\" | \"native\";\n\nexport interface ShareButtonsProps {\n  url?: string;\n  title?: string;\n  /** Extra text for networks that take it (X, WhatsApp, email body). */\n  text?: string;\n  networks?: ShareNetwork[];\n  /** icons: round buttons with a hover label. pills: icon and label. expand: one Share button that opens into the row. */\n  variant?: \"icons\" | \"pills\" | \"expand\";\n  onShare?: (network: ShareNetwork) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.6)\", bg: \"rgba(255,255,255,0.05)\", border: \"rgba(255,255,255,0.12)\", hover: \"rgba(255,255,255,0.1)\", tip: \"#F5F4F1\", tipText: \"#0A0A0A\", solid: \"#F5F4F1\", solidText: \"#0A0A0A\", ok: \"#3FBF7F\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.6)\", bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.12)\", hover: \"rgba(10,10,10,0.05)\", tip: \"#0A0A0A\", tipText: \"#FFFFFF\", solid: \"#0A0A0A\", solidText: \"#FFFFFF\", ok: \"#1F9D5C\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\n// Simple monochrome marks (not the official logos), drawn on a 24px grid.\nconst GLYPHS: Record<ShareNetwork, React.ReactNode> = {\n  x: <path d=\"M4.5 4.5h4.2l10.8 15h-4.2ZM19 4.5l-5.6 6.3M10.6 13.2 5 19.5\" strokeWidth=\"1.6\" />,\n  linkedin: (\n    <>\n      <rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"3\" />\n      <path d=\"M8.5 10.5V16M8.5 8h.01M12 16v-3.2a2 2 0 0 1 4 0V16M12 10.5V16\" />\n    </>\n  ),\n  facebook: <path d=\"M14 21v-8h2.7l.4-3H14V8.2c0-.9.3-1.5 1.6-1.5h1.6V4.1A20 20 0 0 0 14.9 4C12.6 4 11 5.4 11 8v2H8.5v3H11v8\" />,\n  reddit: (\n    <>\n      <ellipse cx=\"12\" cy=\"14\" rx=\"7.5\" ry=\"5.5\" />\n      <path d=\"M12 8.5 13.2 4l3.3.8M9 13.5h.01M15 13.5h.01M9.5 16.3c1.5.9 3.5.9 5 0\" />\n      <circle cx=\"17.5\" cy=\"4.8\" r=\"1.2\" />\n    </>\n  ),\n  whatsapp: <path d=\"M4 20l1.2-3.8A8 8 0 1 1 8 19Zm5-11.5c-.3 2.8 3.2 6.3 6 6l1-1.4-2-1-1 .9c-1-.5-2-1.5-2.5-2.5l.9-1-1-2Z\" />,\n  email: (\n    <>\n      <rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2.5\" />\n      <path d=\"m3.5 7.5 7.4 5.2a2 2 0 0 0 2.2 0l7.4-5.2\" />\n    </>\n  ),\n  copy: <path d=\"M10 13a4.5 4.5 0 0 0 6.4.4l2.8-2.8a4.5 4.5 0 0 0-6.4-6.4l-1.2 1.2M14 11a4.5 4.5 0 0 0-6.4-.4l-2.8 2.8a4.5 4.5 0 0 0 6.4 6.4l1.1-1.1\" />,\n  native: <path d=\"M12 3v12M7.5 7.5 12 3l4.5 4.5M5 13v5.5A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5V13\" />,\n};\n\nconst LABELS: Record<ShareNetwork, string> = { x: \"X\", linkedin: \"LinkedIn\", facebook: \"Facebook\", reddit: \"Reddit\", whatsapp: \"WhatsApp\", email: \"Email\", copy: \"Copy link\", native: \"More\" };\n\nfunction shareUrl(n: ShareNetwork, url: string, title: string, text: string) {\n  const u = encodeURIComponent(url);\n  const t = encodeURIComponent(title);\n  const body = encodeURIComponent(`${text ? `${text}\\n\\n` : \"\"}${url}`);\n  switch (n) {\n    case \"x\":\n      return `https://twitter.com/intent/tweet?url=${u}&text=${encodeURIComponent(text || title)}`;\n    case \"linkedin\":\n      return `https://www.linkedin.com/sharing/share-offsite/?url=${u}`;\n    case \"facebook\":\n      return `https://www.facebook.com/sharer/sharer.php?u=${u}`;\n    case \"reddit\":\n      return `https://www.reddit.com/submit?url=${u}&title=${t}`;\n    case \"whatsapp\":\n      return `https://wa.me/?text=${encodeURIComponent(`${text || title} ${url}`)}`;\n    case \"email\":\n      return `mailto:?subject=${t}&body=${body}`;\n    default:\n      return null;\n  }\n}\n\nfunction Icon({ n, done }: { n: ShareNetwork; done?: boolean }) {\n  return (\n    <svg width=\"17\" height=\"17\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      {done ? <path d=\"m5 12.5 4.5 4.5L19 7.5\" strokeWidth=\"2.2\" /> : GLYPHS[n]}\n    </svg>\n  );\n}\n\nexport function ShareButtons({ url = \"https://reactframe.com/elements\", title = \"ReactFrame · Elements\", text = \"Animated React elements you can copy in seconds.\", networks = [\"x\", \"linkedin\", \"facebook\", \"reddit\", \"whatsapp\", \"email\", \"copy\"], variant = \"icons\", onShare, theme = \"dark\", className }: ShareButtonsProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [copied, setCopied] = React.useState(false);\n  const [tip, setTip] = React.useState<ShareNetwork | null>(null);\n  const [open, setOpen] = React.useState(variant !== \"expand\");\n  const canNative = React.useSyncExternalStore(\n    () => () => {},\n    () => typeof navigator.share === \"function\",\n    () => false,\n  );\n  const list = networks.filter((n) => n !== \"native\" || canNative);\n\n  const act = async (n: ShareNetwork) => {\n    onShare?.(n);\n    if (n === \"copy\") {\n      try {\n        await navigator.clipboard.writeText(url);\n      } catch {\n        // Clipboard blocked; the tick still confirms the action was received.\n      }\n      setCopied(true);\n      window.setTimeout(() => setCopied(false), 1600);\n    } else if (n === \"native\") {\n      try {\n        await navigator.share({ url, title, text });\n      } catch {\n        // Cancelled.\n      }\n    }\n  };\n\n  const pills = variant === \"pills\";\n  const item = (n: ShareNetwork, i: number) => {\n    const href = shareUrl(n, url, title, text);\n    const done = n === \"copy\" && copied;\n    const label = done ? \"Copied\" : LABELS[n];\n    const common = {\n      \"aria-label\": n === \"copy\" ? (done ? \"Link copied\" : \"Copy link\") : `Share on ${LABELS[n]}`,\n      onMouseEnter: () => setTip(n),\n      onMouseLeave: () => setTip(null),\n      onFocus: () => setTip(n),\n      onBlur: () => setTip(null),\n      className: cn(\"relative flex cursor-pointer items-center justify-center no-underline outline-none focus-visible:ring-2\", pills ? \"rounded-full\" : \"rounded-full\"),\n      style: { gap: 7, height: 40, minWidth: 40, padding: pills ? \"0 14px 0 12px\" : 0, background: done ? p.ok : p.bg, border: `1px solid ${done ? p.ok : p.border}`, color: done ? \"#0A0A0A\" : p.text, fontSize: 13, fontWeight: 600, transition: \"background 0.2s ease, border-color 0.2s ease, color 0.2s ease\", [\"--tw-ring-color\" as string]: p.focus } as React.CSSProperties,\n    };\n    const inner = (\n      <>\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          <motion.span key={done ? \"done\" : \"icon\"} className=\"flex\" initial={reduce ? false : { scale: 0.5, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.5, opacity: 0 }} transition={{ type: \"spring\", stiffness: 600, damping: 30 }}>\n            <Icon n={n} done={done} />\n          </motion.span>\n        </AnimatePresence>\n        {pills && <span>{label}</span>}\n        <AnimatePresence>\n          {!pills && (tip === n || done) && (\n            <motion.span key=\"tip\" role=\"tooltip\" className=\"pointer-events-none absolute bottom-full left-1/2 mb-2 rounded-md text-[11.5px] font-semibold whitespace-nowrap\" style={{ padding: \"4px 8px\", background: p.tip, color: p.tipText, x: \"-50%\" }} initial={{ opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 4 }} transition={{ duration: 0.14 }}>\n              {label}\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </>\n    );\n    const motionProps = {\n      initial: variant === \"expand\" && !reduce ? { opacity: 0, x: -10, scale: 0.8 } : false,\n      animate: { opacity: 1, x: 0, scale: 1 },\n      exit: { opacity: 0, x: -10, scale: 0.8 },\n      transition: { type: \"spring\" as const, stiffness: 500, damping: 30, delay: variant === \"expand\" && !reduce ? i * 0.04 : 0 },\n      whileHover: reduce ? undefined : { y: -2 },\n      whileTap: { scale: 0.92 },\n    };\n    return href ? (\n      <motion.a key={n} href={href} target={n === \"email\" ? undefined : \"_blank\"} rel=\"noopener noreferrer\" onClick={() => onShare?.(n)} {...common} {...motionProps}>\n        {inner}\n      </motion.a>\n    ) : (\n      <motion.button key={n} type=\"button\" onClick={() => act(n)} {...common} {...motionProps}>\n        {inner}\n      </motion.button>\n    );\n  };\n\n  return (\n    <div className={cn(\"flex flex-wrap items-center\", className)} style={{ gap: 8, fontFamily: \"Inter, sans-serif\" }} role=\"group\" aria-label=\"Share\">\n      {variant === \"expand\" && (\n        <motion.button\n          type=\"button\"\n          onClick={() => setOpen((o) => !o)}\n          aria-expanded={open}\n          className=\"flex cursor-pointer items-center rounded-full border-none text-[13.5px] font-semibold outline-none focus-visible:ring-2\"\n          style={{ gap: 8, height: 40, padding: \"0 16px 0 13px\", background: p.solid, color: p.solidText, [\"--tw-ring-color\" as string]: p.focus }}\n          whileTap={{ scale: 0.95 }}\n        >\n          <motion.span className=\"flex\" animate={{ rotate: open ? 45 : 0 }} transition={{ type: \"spring\", stiffness: 500, damping: 28 }}>\n            {open ? (\n              <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"M12 5v14M5 12h14\" />\n              </svg>\n            ) : (\n              <Icon n=\"native\" />\n            )}\n          </motion.span>\n          {open ? \"Close\" : \"Share\"}\n        </motion.button>\n      )}\n      <AnimatePresence initial={false}>{open && list.map((n, i) => item(n, i))}</AnimatePresence>\n    </div>\n  );\n}\n\nexport default ShareButtons;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}