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
| Prop | Type | Default | Description |
|---|---|---|---|
selector | string | — | CSS selector for the element whose textContent to copy |
text | string | — | Direct text to copy (takes priority over selector) |
floating | boolean | false | Position 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