CopyButton
An icon Button that copies value to the clipboard and confirms with a short "Copied" toast beside it. Takes every Button prop but children.
Use for
- copying an id, key, secret or URL to the clipboard
- a copy icon next to a value
Practices
| Guidance | Practice |
|---|---|
| Do | Pass localized label and copiedLabel. |
| Do | Pass onCopyError to tell the user when the clipboard is blocked. Nothing shows otherwise. |
| Don’t | Call preventDefault in onClick unless you mean to skip the copy. |
API reference
CopyButton
A type="button" icon button. The toast carries cl-copy-button-toast and its title cl-copy-button-toast-title.
Slot: cl-button
| Prop | Type | Description |
|---|---|---|
value | string | The text to copy. |
label | string | Accessible name of the button.Default: 'Copy' |
copiedLabel | string | The toast text after a copy.Default: 'Copied' |
side | ToastSide | Side of the button the toast shows on.Default: 'top' |
resetAfter | number | How long the toast stays, in ms.Default: 2000 |
onCopy | (value: string) => void | Promise<void> | Replaces the clipboard write. Reject to show no toast. |
onCopyError | (error: unknown) => void | Called when the copy fails. |
color | 'primary' | 'neutral' | 'negative' | The Button color.Default: 'neutral' |
variant | 'filled' | 'outline' | 'ghost' | 'link' | The Button variant.Default: 'ghost' |
size | 'xs' | 'sm' | 'md' | 'lg' | The Button size.Default: 'xs' |
shape | 'default' | 'square' | 'circle' | The Button shape.Default: 'square' |
Examples
Copy an id
<CopyButton value={user.id} label={m.copyId} copiedLabel={m.copied} />