Skip to content
Primitives

CopyButton

Copies a string and confirms it in place.

import
import { CopyButton } from '@joshicodes/cock';

Copy

Behaviour

  • Uses the asynchronous clipboard API, which browsers only allow from a real click on a secure origin. If the write is refused the button simply does not change.

API

Read out of the component sources at build time, so it matches the version you installed. Every component also takes class, merged through tailwind-merge so your utility wins.

Props of CopyButton

PropTypeDefault
value required

The text that ends up on the clipboard.

string—
label
string'Copy'
copiedLabel
string'Copied'
iconOnly

Icon only; the label becomes the accessible name.

booleanfalse
variant
ButtonVariant'outline'
size
ButtonSize—
class
string—

Events of CopyButton

EventTypeDefault
oncopy
(value: string) => void—

See also

cock. Yes, it stands for core component kit. We checked twice.