CopyButton
Copy to clipboard button component
CopyButton
A button component that copies text to the clipboard when clicked, providing visual feedback on success.
Usage
The CopyButton is primarily used internally by the ProsePre component to provide copy functionality for code blocks. It can also be used standalone:
::copy-button{value="npm install docs-please"}
::
How It Works
- User clicks the copy button
- The
valueprop content is copied to the clipboard - The icon changes from a copy icon to a check icon
- After a brief delay, the icon returns to the copy state
In Code Blocks
CopyButton is automatically included in all fenced code blocks. When you write:
const hello = 'world'
A copy button appears in the top-right corner of the code block.
Props
Styling
The button displays:
- Copy icon (clipboard) in default state
- Check icon when content has been copied
- Positioned absolutely (typically top-right of parent)
- Subtle hover effect