API
API
The browser module exports createCopyButton. The React package adds CopyButton.
| Name | Description |
|---|---|
createCopyButton(button, options) | Turns a button you already have into a copy button. Returns destroy. |
text, getText() | The text to copy, or a function that returns it, also as a promise. Pass one of the two. |
resetMs | How long the copied or failed state stays before the button returns to idle. 1600 by default. |
onCopy(text), onError(error) | Called after a copy succeeds or fails, for your own logging or toasts. |
data-state | Set on the button to "idle", "copied" or "error". Style the states from it. |
--re-copy-icon-size, --re-copy-gap, --re-copy-duration | The icon size, 16 px, the gap to the label, 6 px, and the icon swap time, 200 ms. |
CopyButton | The React button around the same controller. It takes text or getText, resetMs, onCopy and onError. |