API

API

The browser module exports createCopyButton. The React package adds CopyButton.

NameDescription
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.
resetMsHow 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-stateSet on the button to "idle", "copied" or "error". Style the states from it.
--re-copy-icon-size, --re-copy-gap, --re-copy-durationThe icon size, 16 px, the gap to the label, 6 px, and the icon swap time, 200 ms.
CopyButtonThe React button around the same controller. It takes text or getText, resetMs, onCopy and onError.