Share Menu
ncdai/share-menuUnverifiedComponent
Share menu to copy a link or post to X, LinkedIn, and the native share sheet.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/srirae/iamsri/main/public/r/share-menu.jsonSource
1"use client"23import { toast } from "sonner"45import { Button } from "@/components/ui/button"6import {7 DropdownMenu,8 DropdownMenuContent,9 DropdownMenuItem,10 DropdownMenuTrigger,11} from "@/components/ui/dropdown-menu"12import { IconPlaceholder } from "@/registry/icons/icon-placeholder"1314export type ShareMenuProps = {15 /** Title passed to the native share sheet. */16 title: string17 /** URL to share. Relative URLs are resolved against the current origin. */18 url: string19}2021export function ShareMenu({ title, url }: ShareMenuProps) {22 const absoluteUrl = url.startsWith("http")23 ? url24 : typeof window !== "undefined"25 ? new URL(url, window.location.origin).toString()26 : url2728 const urlEncoded = encodeURIComponent(absoluteUrl)2930 return (31 <DropdownMenu>32 <DropdownMenuTrigger asChild>33 <Button variant="outline" size="icon-sm">34 <IconPlaceholder35 lucide="ShareIcon"36 tabler="IconShare2"37 hugeicons="Share03Icon"38 phosphor="ExportIcon"39 remixicon="RiShare2Line"40 />41 </Button>42 </DropdownMenuTrigger>4344 <DropdownMenuContent45 className="w-fit"46 align="start"47 alignOffset={-6}48 collisionPadding={16}49 onCloseAutoFocus={(e) => e.preventDefault()}50 >51 <DropdownMenuItem52 onClick={() => {53 copyText(absoluteUrl)54 toast.success("Link copied")55 }}56 >57 <IconPlaceholder58 lucide="LinkIcon"59 tabler="IconLink"60 hugeicons="Link01Icon"61 phosphor="LinkIcon"62 remixicon="RiLinkM"63 />64 Copy link65 </DropdownMenuItem>6667 <DropdownMenuItem asChild>68 <a69 href={`https://x.com/intent/tweet?url=${urlEncoded}`}70 target="_blank"71 rel="noopener"72 >73 <XIcon />74 Share on X75 </a>76 </DropdownMenuItem>7778 <DropdownMenuItem asChild>79 <a80 href={`https://www.linkedin.com/sharing/share-offsite?url=${urlEncoded}`}81 target="_blank"82 rel="noopener"83 >84 <LinkedInIcon />85 Share on LinkedIn86 </a>87 </DropdownMenuItem>8889 {typeof navigator !== "undefined" && "share" in navigator && (90 <DropdownMenuItem91 onClick={(e) => {92 e.preventDefault() // Prevent the menu from closing93// … truncated
What it pulls in
Other registry items
Files it writes
More from ncdai
All 48 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Apple Hello Effectapple-hello-effect | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Hindiapple-hello-effect-hindi | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Spanishapple-hello-effect-spanish | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Vietnameseapple-hello-effect-vietnamese | ncdai | Components | Unverified | 1 dep | |
| Brand Assets Menubrand-assets-menu | ncdai | Components | Unverified | 1 dep | |
| chevrons-up-down-iconchevrons-up-down-icon | ncdai | Components | Unverified | 1 dep | |
| Code Block Commandcode-block-command | ncdai | Components | Unverified | 4 deps · 2 files | |
| Consent Managerconsent-manager | ncdai | Components | Unverified | 1 dep |
