Copy Button
Copy to clipboard, with the one piece of feedback that matters.
Loading documentation…
CopyButton is a Button that writes a string to the
clipboard and then says so: the icon becomes a tick and stays that way long
enough to be believed. Without the hold, a copy button is indistinguishable
from a button that did nothing.
It takes every Button prop except icon and onClick — those two are what
the component is. A labelled button also swaps its own text for "Copied" while
the tick is up, and it falls back to the old execCommand trick when the
Clipboard API is unavailable, so it still works over plain HTTP.
Omit children for an icon-only button — it is square automatically and
announces itself as "Copy" to a screen reader. Pass a label when the button
sits on its own and the icon has no context to borrow from.
The usual home for a copy button is the end of a row holding an identifier — quiet enough to ignore, close enough to hit.
dpl_8f21c3d9CodeBlock renders its own copy control in the
title bar. Pass copy={false} there if you would rather place your own.
The text put on the clipboard.
The label beside the icon. Omit it for an icon-only button.
How long the tick stays, in milliseconds. It defaults to 1600.
Fires after a successful write — for analytics or a toast.
The accessible name when there is no visible label. It defaults to "Copy".
Every Button appearance prop. variant defaults to ghost, size to
sm, and shape to square whenever there is no label.