Components
Back to catalog
Component detail entry
General
@vean/ui
SClipboard

Clipboard

Clipboard belongs to the General category. Start with demos and usage, then use the API tables to finish integration and styling decisions.

Use the quick jump panel to reach overview, usage, demos, and API first, then continue through the full page.

Quick jump

Related components

If you are composing interactions in the same family, these components usually pair well together.

Clipboard

Overview

SClipboard is a clipboard action component built on SButton that copies a plain-text value to the system clipboard with accessible button semantics and copied-state feedback.

Use it to copy short text values (install commands, invite codes, short links, IDs) or to provide a one-click copy entry next to code blocks, table rows, or cards. It is not for rich text, images, or large formatted content — the component only handles string.

Built on SButton, it inherits the same color/size/variant/shape theme tokens and as/asChild polymorphism, and is commonly paired with display components like kbd or code as a side copy entry.

Usage

Features

  • 📋 Copies a required text value on click
  • 🧩 Ships with built-in icon/text content that can be overridden via leading/default/trailing slots
  • 🌐 Defaults copyText/copiedText to localized clipboard.copy/clipboard.copied messages from ConfigProvider
  • ✅ Exposes ready, copied, and unsupported states
  • 🎨 Reuses SButton’s 8 variants, 8 colors, 6 sizes, and 4 shapes
  • 🔌 Inherits SButton’s as/asChild polymorphism and class override
  • 🛡️ Falls back to execCommand('copy') when the async Clipboard API is unavailable (disable with legacy)
  • ♿ Keeps button semantics, disabled behavior, and data-state in the Aria layer
  • 🎯 TypeScript-safe with fully typed ClipboardSlotProps

Demos

Basic

Custom Styling

Icon Only

API

Aria Layer

1

Clipboard

18 Props3 Emits3 Slots
Props
PropTypeDefaultDescription
class
ClassValue
—
Additional class names applied to the root element.
color
ThemeColor
—
Theme color of the component.
size
ThemeSize
—
Visual size of the component.
variant
ClipboardVariant
—
Visual variant of the component.
shape
ClipboardShape
—
Shape of the component.
fitContent
boolean
—
Whether the component should fit its content width.
value
string
—
The text value to copy.
copiedDuration
number
2000
The duration in milliseconds to keep the copied state.
legacy
boolean
true
Whether to enable the legacy `execCommand` fallback.
copyIcon
IconValue
'lucide:copy'
The icon to display before copying.
copiedIcon
IconValue
'lucide:check'
The icon to display after copying.
copyText
string
—
The text to display before copying. Defaults to the localized `clipboard.copy` message from `ConfigProvider`.
copiedText
string
—
The text to display after copying. Defaults to the localized `clipboard.copied` message from `ConfigProvider`.
onlyIcon
boolean
false
Whether to only render the icon without any text.
type
ButtonType
'button'
The type of the button element. Can be one of 'button', 'submit', or 'reset'.
disabled
boolean
—
Whether the component is disabled.
asChild
boolean
—
Change the default rendered element for the one passed as a child, merging their props and behavior.
as
AsTag | Component
'div'
The element or component this component should render as. Can be overwrite by `asChild`
Emits
Emit NameParametersDescription
click
PointerEvent
Emitted when click occurs.
copied
string
Emitted when copied occurs.
copyError
unknown
Emitted when copy error occurs.
Slots
Slot NameParametersDescription
leading
ClipboardSlotProps
—
default
ClipboardSlotProps
—
trailing
ClipboardSlotProps
—

Notes

Architecture and benchmark differences

VeanUI splits the clipboard into an Aria layer (@vean/aria/clipboard) that owns copy state, button semantics, and slot props, and a styled layer (@vean/ui) that reuses the button variant recipe. This mirrors the headless/styled split used by shadcn/ui copy patterns and differs from single-package libraries such as Ant Design, Element Plus, MUI, Mantine, and Naive UI.

AspectVeanUIAnt Design / Element Plus / MUI / Mantine / Naive UI
ArchitectureAria + styled split on top of Buttonsingle-package CopyButton / Typography.Paragraph copyable
StylingUnoCSS utilities via shared buttonVariants recipeCSS-in-JS / SCSS / CSS vars
Customizationclass, as / asChild, leading / default / trailing slotsicon, text, format, component overrides
Fallbacklegacy prop enables a self-implemented execCommand('copy') fallback in shared.tslibrary-specific fallback behavior
Feedbackdata-state, slot props, copied / copyError eventstooltip, message, or inline text swap

Cautions

  • Secure context: The async Clipboard API (navigator.clipboard.writeText) is only available in secure contexts (HTTPS or localhost). In non-secure contexts the API is unavailable; the component falls back to the legacy execCommand('copy') (when legacy=true, the default) or enters the unsupported state (when legacy=false).
  • Legacy fallback deprecation: document.execCommand('copy') is deprecated. legacy defaults to true for maximum compatibility; set legacy={false} to rely solely on the async API.
  • SSR / hydration: isClipboardWriteSupported() returns false on the server (no navigator). With the default legacy=true, SSR renders ready and hydrates consistently. With legacy=false, SSR renders unsupported and may hydrate to ready on a supporting client — wrap in <ClientOnly> if this hydration difference matters.
  • Timer cleanup: The copied state auto-resets after copiedDuration (default 2000ms) via useTimeoutFn, which is cleaned up on unmount — no manual timer management needed.

FAQ

How do I customize the copied-state UI? Use the leading, default, or trailing slots. Each slot receives ClipboardSlotProps with copied, disabled, icon, supported, state, text, and a copy() helper.

How do I build an icon-only copy button? Clear the default slot and pass an explicit aria-label (or copy-text plus visible text in another slot). See the icon-only playground demo.

What happens when the Clipboard API is unavailable? When neither the async Clipboard API nor the legacy fallback can run, the component exposes data-state="unsupported" and disables interaction. Set legacy={false} if you want to opt out of the execCommand('copy') fallback.

How do I handle copy failures? Listen for the copyError event. The component keeps data-state="ready" on failure so users can retry without entering a false copied state.

How do I localize the built-in copy text? The default copyText/copiedText resolve to the clipboard.copy/clipboard.copied messages of the locale selected by ConfigProvider (falling back to en). Pass explicit copy-text/copied-text props, or a messages override on ConfigProvider, to customize them.

Can I copy programmatically? Yes. Call the copy() function from slot props, or trigger the button and listen for the copied event.

Changelog

Version history is grouped by release so you can quickly see what changed for this component across published versions.

v0.18.0

2026-05-05

Compare release

Optimization

update click event type from MouseEvent to PointerEvent for consistency

Scope: clipboardAuthors: soybeanfeView commitca2b0

v0.15.0

2026-04-26

Compare release

Style

adjust SClipboard component structure in examples for better readability

Scope: clipboardAuthors: soybeanfeView commita36d2

Style

adjust SClipboard component structure in examples for better readability

Scope: clipboardAuthors: soybeanfeView commita36d2