Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Share Buttons

ProNew

Share buttons for a page with labels, supplied counts and an extensible More menu for consumer-owned HTTP(S) share intents. Use inline, grid or floating placement.

Installation

pnpm dlx shadcn@latest add @viewport/share-buttons

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
urlstring

The address to share. Defaults to the page the buttons are on.

—
titlestring

Headline sent along with the link. Defaults to the page title.

—
textstring

Longer text for networks that take a description, and the body of the email.

""
imagestring

Image address, used by Pinterest.

""
targetsShareTarget[]

The buttons to show, in order. `native` only appears where the browser has a share sheet.

["facebook", "x", "linkedin", "whatsapp", "copy"]
moreShareTarget[]

Extra targets tucked behind a "More" button.

—
customMoreCustomShareTarget[]

Additional networks in More, with consumer-supplied share intent URLs; no service connector is installed.

—
layout"inline" | "grid" | "floating"

`inline` wraps in a row, `grid` fills two equal columns, `floating` pins a column to the edge of the page.

"inline"
variant"brand" | "mono" | "outline"

`brand` fills each button with the network's color, `mono` uses the text color, `outline` draws a ring with a colored mark.

"brand"
shape"square" | "rounded" | "pill""rounded"
size"sm" | "md" | "lg"

Button height: 28, 36 or 44 pixels.

"md"
labels"none" | "name" | "action"

`name` writes "Facebook", `action` writes "Share on Facebook", `none` leaves the icon alone. Floating buttons reveal their label on hover and focus.

layout === "floating" ? "none" : "name"
countsPartial<Record<ShareTarget, number>>

Share counts per target, shown inside each button.

—
countLayout"inline" | "above" | "hidden"

Keep counts inside buttons, place them above (Facebook box-count style), or omit them visually. Supply counts yourself.

"inline"
totalboolean | number

Shows the sum of `counts`, or the number you pass, ahead of the buttons.

—
side"left" | "right"

Which edge a floating column sticks to.

"left"
position"fixed" | "absolute"

`fixed` pins a floating column to the viewport; `absolute` pins it to the nearest positioned ancestor.

"fixed"
onShare(target: ShareTarget, url: string) => void

Called after a button is used, with the target and the address shared.

—
onCustomShare(id: string, url: string) => void—
classNamestring—

Accessibility

  • Built-in networks and safe consumer-supplied More targets are real links; invalid custom URLs show as unavailable rather than navigating.
  • Every button has a name such as "Share on Facebook" even when only the icon shows, and visible counts are read as "1.3K shares".
  • Copying announces "Link copied to clipboard" or the failure through a polite live region, and the button shows a tick for two seconds.
  • The More button opens a scrollable popover that takes focus, closes on Escape and returns focus to the button.
  • Floating labels appear on keyboard focus as well as hover; lift and slide are dropped under `prefers-reduced-motion`.