✨ Publier v1 is live — a polished docs platform built for the open web.
Skip to content

CopyButton

One-click clipboard copy button for code blocks or arbitrary text.

The CopyButton component copies text to the clipboard on click, showing a checkmark confirmation.

Usage

Copy text from a DOM element:

---
import { CopyButton } from '@publier/primitives';
---
<div id="my-code">publier dev</div>
<CopyButton selector="#my-code" />

Copy a string directly:

<CopyButton text="publier dev" />

Props

PropTypeDefaultDescription
selectorstringCSS selector for the element whose textContent to copy
textstringDirect text to copy (takes priority over selector)
floatingbooleanfalsePosition the button floating over content (top-right)

Behavior

  • Shows a clipboard icon by default
  • On click: copies text, shows a checkmark for 2 seconds
  • Gracefully handles clipboard API failures