{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-menu",
  "title": "Share Menu",
  "author": "ncdai <dai@chanhdai.com>",
  "description": "Share menu to copy a link or post to X, LinkedIn, and the native share sheet.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "dropdown-menu",
    "toast"
  ],
  "files": [
    {
      "path": "src/registry/components/share-menu/share-menu.tsx",
      "content": "\"use client\"\n\nimport { EllipsisIcon, LinkIcon, ShareIcon } from \"lucide-react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\"\nimport { toast } from \"@/components/ui/toast\"\n\nexport type ShareMenuProps = {\n  /** Title passed to the native share sheet. */\n  title: string\n  /** URL to share. Relative URLs are resolved against the current origin. */\n  url: string\n}\n\nexport function ShareMenu({ title, url }: ShareMenuProps) {\n  const absoluteUrl = url.startsWith(\"http\")\n    ? url\n    : typeof window !== \"undefined\"\n      ? new URL(url, window.location.origin).toString()\n      : url\n\n  const urlEncoded = encodeURIComponent(absoluteUrl)\n\n  return (\n    <DropdownMenu>\n      <DropdownMenuTrigger render={<Button variant=\"outline\" size=\"icon-sm\" />}>\n        <ShareIcon />\n      </DropdownMenuTrigger>\n\n      <DropdownMenuContent\n        className=\"w-fit\"\n        align=\"start\"\n        alignOffset={-6}\n        collisionPadding={16}\n        finalFocus={false}\n      >\n        <DropdownMenuItem\n          onClick={() => {\n            copyText(absoluteUrl)\n            toast.add({ type: \"success\", title: \"Link copied\" })\n          }}\n        >\n          <LinkIcon />\n          Copy link\n        </DropdownMenuItem>\n\n        <DropdownMenuItem\n          render={\n            <a\n              href={`https://x.com/intent/tweet?url=${urlEncoded}`}\n              target=\"_blank\"\n              rel=\"noopener\"\n            />\n          }\n        >\n          <XIcon />\n          Share on X\n        </DropdownMenuItem>\n\n        <DropdownMenuItem\n          render={\n            <a\n              href={`https://www.linkedin.com/sharing/share-offsite?url=${urlEncoded}`}\n              target=\"_blank\"\n              rel=\"noopener\"\n            />\n          }\n        >\n          <LinkedInIcon />\n          Share on LinkedIn\n        </DropdownMenuItem>\n\n        {typeof navigator !== \"undefined\" && \"share\" in navigator && (\n          <DropdownMenuItem\n            closeOnClick={false}\n            onClick={() => {\n              navigator.share({ title, url: absoluteUrl }).catch(() => {})\n            }}\n          >\n            <EllipsisIcon />\n            Other app\n          </DropdownMenuItem>\n        )}\n      </DropdownMenuContent>\n    </DropdownMenu>\n  )\n}\n\nconst copyText = async (text: string) => {\n  try {\n    await navigator.clipboard.writeText(text)\n    return true\n  } catch {\n    return false\n  }\n}\n\ntype IconProps = React.ComponentProps<\"svg\">\n\nfunction XIcon(props: IconProps) {\n  return (\n    <svg viewBox=\"0 0 24 24\" aria-hidden {...props}>\n      <path\n        d=\"m22.991 23-8.533-12.612L22.42 1h-2.77l-6.422 7.575L8.105 1H1.123l8.225 12.158L1 23h2.77l6.81-8.03L16.015 23H23zM7.193 2.769l12.49 18.462h-2.76L4.43 2.769z\"\n        fill=\"currentColor\"\n      />\n    </svg>\n  )\n}\n\nfunction LinkedInIcon(props: IconProps) {\n  return (\n    <svg viewBox=\"0 0 24 24\" aria-hidden {...props}>\n      <path\n        d=\"M22.274 0H1.728C.692 0 0 .685 0 1.715v20.569C0 23.316.864 24 1.727 24h20.546C23.31 24 24 23.315 24 22.285V1.716C24.001.684 23.31 0 22.274 0M7.08 20.4H3.454V8.915h3.625zM5.352 7.371c-1.209 0-2.07-.856-2.07-2.056s.863-2.059 2.07-2.059c1.21 0 2.073.859 2.073 2.059S6.388 7.37 5.352 7.37M20.548 20.4h-3.626v-5.485c0-1.371 0-3.087-1.9-3.087-1.898 0-2.073 1.372-2.073 2.916V20.4H9.325V8.915h3.454v1.541c.69-1.2 2.073-1.885 3.453-1.885 3.627 0 4.316 2.4 4.316 5.485z\"\n        fill=\"currentColor\"\n      />\n    </svg>\n  )\n}\n",
      "type": "registry:component",
      "target": "@components/share-menu.tsx"
    }
  ],
  "docs": "https://chanhdai.com/components/share-menu",
  "categories": [
    "menus"
  ],
  "type": "registry:component"
}