This <CopyButton />
component allows you to copy text to the clipboard on click.
There are two main ways to use the <CopyButton />
component:
- Icon-only button
- Text + icon button
The main difference between the two is that the icon-only button is a standalone button, while the text + icon button is a button that wraps around the text you want to copy, letting you click either the text or the icon to copy the text.
import { CopyButton } from "@/components/CopyButton";
// Simple copy button with icon only
<CopyButton value="Copy this text" />
// With custom tooltip
<CopyButton
value="Copy this text"
label="Copy text to clipboard"
/>
// With custom tooltip position
<CopyButton
value="Copy this text"
tooltipPosition="bottom"
/>
import { CopyButton } from "@/components/CopyButton";
// Text with copy functionality
<CopyButton value="Copy this text">
<p className="text-lg">Clicking this text will copy "Copy this text"</p>
</CopyButton>
Prop | Type | Description |
---|---|---|
value |
string |
The text to copy to clipboard |
label |
string |
Tooltip text on hover |
children |
React.ReactNode |
Content to render with the copy icon (optional) |
tooltipPosition |
"top" | "right" | "bottom" | "left" |
Tooltip position (optional, defaults: top for icon-only, right for text + icon) |