GooseUI

Components

Share Buttons

New

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

Popover

Opens and closes the popup

Your browser:
Anchor positioning

Positions the popup near its trigger

Your browser:
@starting-style

Animates the initial appearance

Your browser:
:has()

Styles the open share menu

Your browser:
transition-behavior

Animates the menu closing

Your browser:
Async clipboard

Copies the link to the clipboard

Your browser:
navigator.share()

Opens the system share menu

Your browser:

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.

Preview

The link of this page is shared. Try Copy link.

Installation

npx shadcn@latest add @gooseui/share-buttons
pnpm dlx shadcn@latest add @gooseui/share-buttons
yarn dlx shadcn@latest add @gooseui/share-buttons
bunx --bun shadcn@latest add @gooseui/share-buttons

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

PropTypeDefaultDescription
urlstring-Link to share. Pass it to make the links work without JavaScript. Otherwise the page URL is filled in on click
titlestring-Post title. Otherwise document.title is filled in on click
networksShareNetwork[]telegram, whatsapp, x, linkedin, facebook, emailNetworks and their order
copybooleantrueShow Copy link
nativeSharebooleantrueShow 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
showLabelsbooleanfalseRow 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
labelsShareButtonsLabels-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
classNamestring-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