Share Button

A share trigger button that fans out into a row of round action buttons, including an optional copy-link action with success feedback and custom share actions. Actions spring out from behind the trigger with a staggered animation and offer tooltips and full keyboard support.

Share Button
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme an agent is reading the install docs
See how it was built

Installation

pnpm dlx shadcn@latest add @spectrumui/share-button

Requires @spectrumui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { ShareButton } from "@/components/spectrumui/share-button"export function Example() {  return <ShareButton copyValue="https://ui.spectrumhq.in" />}
  • Adding a share menu next to articles, posts, or product pages where several share destinations should be grouped behind one compact control
  • Offering a one-click copy-link action alongside custom share targets such as social networks or email
  • Building a compact floating toolbar that expands to reveal secondary actions with playful spring motion
  • Needing a share control that respects keyboard navigation and prefers-reduced-motion settings

Examples

Copy link only

Renders the trigger with only the built-in copy-link action, using the URL to copy.

copy-link-only.tsx
import { ShareButton } from "@/components/spectrumui/share-button"export function CopyOnlyShare() {  return <ShareButton copyValue="https://ui.spectrumhq.in/docs" label="Share this page" />}

Custom share actions

Adds custom actions after the copy action and fans them out to the right.

custom-share-actions.tsx
import { Mail, Twitter } from "lucide-react"import { ShareButton } from "@/components/spectrumui/share-button"export function SocialShare() {  const shareOnX = () => window.open("https://x.com/intent/post?url=" + encodeURIComponent("https://ui.spectrumhq.in"), "_blank")  const shareByMail = () => (window.location.href = "mailto:?subject=Spectrum UI")  return (    <ShareButton      copyValue="https://ui.spectrumhq.in"      actions={[        { icon: <Twitter size={15} />, label: "Share on X", onSelect: shareOnX },        { icon: <Mail size={15} />, label: "Share by email", onSelect: shareByMail },      ]}    />  )}

Left-facing large variant

Uses the large size and fans actions to the left, keeping the menu open after a selection.

left-facing-large-variant.tsx
import { Share2 } from "lucide-react"import { ShareButton } from "@/components/spectrumui/share-button"export function LeftShare() {  return (    <ShareButton      size="lg"      direction="left"      closeOnSelect={false}      copyValue="https://ui.spectrumhq.in"      actions={[        { icon: <Share2 size={17} />, label: "Share more", onSelect: () => console.log("more") },      ]}    />  )}

API reference

PropTypeDefaultDescription
actionsShareAction[][]Custom actions fanned out after the built-in copy action. Each has icon (React.ReactNode), label (string, used as tooltip and accessible name), and onSelect (() => void).
copyValuestring—URL or text copied by the built-in copy-link first action; when omitted the copy action is hidden.
direction"left" | "right""right"Side the actions fan out toward.
size"sm" | "md" | "lg""md"Visual size of the trigger; actions are one step smaller.
labelstring"Share"Accessible name of the trigger and the menu.
closeOnSelectbooleantrueCollapses the row about 150ms after a custom action is selected.
classNamestring—Additional classes merged onto the root span element.

Accessibility

  • The trigger is a button with aria-expanded and aria-haspopup="menu" and an aria-label from the label prop.
  • The actions container has role="menu" and each action is a button with role="menuitem" and an aria-label.
  • On open, focus moves to the first action; Tab and Shift+Tab cycle actions and ArrowLeft/ArrowRight follow the visual order.
  • Escape closes the menu from anywhere inside the component and returns focus to the trigger.
  • Clicking outside closes the menu via a pointerdown listener that exists only while open.
  • With prefers-reduced-motion, transforms and stagger are removed and only a short opacity fade is used.
  • Tooltips are aria-hidden visual hints; the accessible name comes from aria-label.
  • The share icon is an inline SVG marked aria-hidden, so the collapsed trigger has no icon dependency.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Share Button" component (spectrumui/share-button) from its shadcn registry.1. Install it with: npx shadcn@latest add @spectrumui/share-button2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: actions, copyValue, direction, size, label, closeOnSelect, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ShareButton } from "@/components/spectrumui/share-button"export function Example() {  return <ShareButton copyValue="https://ui.spectrumhq.in" />}```

Files & dependencies

  • app/registry/share-button/share-button.tsx→ components/spectrumui/share-button.tsx
dependenciesframer-motionlucide-react

Looks similar, elsewhere