{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "share-menu", "title": "Share Menu", "author": "ncdai ", "description": "Share menu to copy a link or post to X, LinkedIn, and the native share sheet.", "registryDependencies": [ "button", "dropdown-menu", "sonner" ], "files": [ { "path": "src/registry/components/share-menu/share-menu.tsx", "content": "\"use client\"\r\n\r\nimport { toast } from \"sonner\"\r\n\r\nimport { Button } from \"@/components/ui/button\"\r\nimport {\r\n DropdownMenu,\r\n DropdownMenuContent,\r\n DropdownMenuItem,\r\n DropdownMenuTrigger,\r\n} from \"@/components/ui/dropdown-menu\"\r\nimport { IconPlaceholder } from \"@/registry/icons/icon-placeholder\"\r\n\r\nexport type ShareMenuProps = {\r\n /** Title passed to the native share sheet. */\r\n title: string\r\n /** URL to share. Relative URLs are resolved against the current origin. */\r\n url: string\r\n}\r\n\r\nexport function ShareMenu({ title, url }: ShareMenuProps) {\r\n const absoluteUrl = url.startsWith(\"http\")\r\n ? url\r\n : typeof window !== \"undefined\"\r\n ? new URL(url, window.location.origin).toString()\r\n : url\r\n\r\n const urlEncoded = encodeURIComponent(absoluteUrl)\r\n\r\n return (\r\n \r\n \r\n \r\n \r\n\r\n e.preventDefault()}\r\n >\r\n {\r\n copyText(absoluteUrl)\r\n toast.success(\"Link copied\")\r\n }}\r\n >\r\n \r\n Copy link\r\n \r\n\r\n \r\n \r\n \r\n Share on X\r\n \r\n \r\n\r\n \r\n \r\n \r\n Share on LinkedIn\r\n \r\n \r\n\r\n {typeof navigator !== \"undefined\" && \"share\" in navigator && (\r\n {\r\n e.preventDefault() // Prevent the menu from closing\r\n navigator.share({ title, url: absoluteUrl }).catch(() => {})\r\n }}\r\n >\r\n \r\n Other app\r\n \r\n )}\r\n \r\n \r\n )\r\n}\r\n\r\nconst copyText = async (text: string) => {\r\n try {\r\n await navigator.clipboard.writeText(text)\r\n return true\r\n } catch {\r\n return false\r\n }\r\n}\r\n\r\ntype IconProps = React.ComponentProps<\"svg\">\r\n\r\nfunction XIcon(props: IconProps) {\r\n return (\r\n \r\n \r\n \r\n )\r\n}\r\n\r\nfunction LinkedInIcon(props: IconProps) {\r\n return (\r\n \r\n \r\n \r\n )\r\n}\r\n", "type": "registry:component", "target": "@components/share-menu.tsx" } ], "docs": "https://chanhdai.com/components/share-menu", "categories": [ "menus" ], "type": "registry:component" }