Share buttons: a configurable set of networks (Telegram, WhatsApp, X, LinkedIn, Facebook, email) plus Copy link, which falls back to a legacy method on plain http. Two sizes of the row (sm, default, lg) and two looks: neutral buttons that take the brand colour on hover, or brand-coloured right away. The system share sheet is the first menu item wherever the browser supports it, and in the row it shows up on touch devices. Comes as a row of buttons or a dropdown menu.
Browser Support
Opens and closes the popup
Positions the popup near its trigger
Animates the initial appearance
Styles the open share menu
Animates the menu closing
Copies the link to the clipboard
Opens the system share menu
The links and the menu are server-rendered HTML: plain <a> tags and a native popover, so they work with JavaScript turned off. Only Copy link and the system share sheet need JavaScript. They live in a small client island that appears after the page loads, and the same island fills in the page URL and title when you did not pass url and title.
Installation
Usage
import { ShareButtons } from "@/components/ui/share-buttons"
export default function ArticleFooter() {
// Pass url and title so the links work before any JavaScript runs
return (
<ShareButtons
url="https://example.com/articles/hello"
title="Example article"
/>
)
}Examples
With labels
showLabels prints network names next to the glyphs. networks sets the list and order.
<ShareButtons networks={["telegram", "whatsapp", "x"]} showLabels size="sm" />Sizes
sm is 32px, default is 40px, lg is 48px. The icon grows with the button: 16, 20 and 24px.
<ShareButtons size="sm" />
<ShareButtons size="default" />
<ShareButtons size="lg" />Brand colours
By default the buttons are neutral and take the brand colour of the network on hover. variant="brand" colours them right away. Brand colours are an intentional exception to the shadcn tokens: they make the networks recognisable. Telegram and WhatsApp use a darker shade so white on top stays above 3:1.
<ShareButtons variant="brand" />Dropdown menu
layout="menu" packs everything into one button. After Copy link the menu stays open to show the confirmation.
<ShareButtons
layout="menu"
url="https://example.com/articles/hello"
title="Example article"
networks={["telegram", "whatsapp", "x", "linkedin", "facebook", "email"]}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| url | string | - | Link to share. Pass it to make the links work without JavaScript. Otherwise the page URL is filled in on click |
| title | string | - | Post title. Otherwise document.title is filled in on click |
| networks | ShareNetwork[] | telegram, whatsapp, x, linkedin, facebook, email | Networks and their order |
| copy | boolean | true | Show Copy link |
| nativeShare | boolean | true | Show the system share sheet: the first menu item where navigator.share accepts the data, in the row only on touch devices |
| layout | "row" | "menu" | "row" | A row of buttons or a dropdown menu |
| variant | "default" | "brand" | "default" | Row only: neutral buttons with brand colour on hover, or brand colours at once |
| showLabels | boolean | false | Row only: print network names |
| size | "sm" | "default" | "lg" | "default" | Button size: 32, 40 or 48px |
| align | "start" | "center" | "end" | "end" | Menu alignment relative to the button |
| labels | ShareButtonsLabels | - | Texts: share, copy, copied, copyFailed, native and shareOn(name) |
| onShare | (network) => void | - | Called with the network, "copy" or "native". Only when ShareButtons is rendered from a client component |
| className | string | - | Additional CSS classes |
Features
- Official marks: inline SVGs from simple-icons (CC0) on currentColor, no extra dependencies
- Copy fallback: Clipboard API in a secure context, execCommand on plain http
- Native share: in the menu it is the first item wherever navigator.canShare allows (Safari on Mac too); in the row only on touch screens. Closing the sheet is not an error
- Little JavaScript: the links and the menu are plain HTML; the client island holds only copying and navigator.share and is hidden until it loads
- Keyboard: Tab reaches the button, Enter opens the menu, Tab moves through the items, Escape closes it and returns focus