Motion UIComponentsComponent

Copy button

A copy-to-clipboard button that confirms with a glyph swap and a self-drawing check.

npx shadcn@latest add @motion/copy-button

API reference

Components

<CopyButton />

A copy-to-clipboard button that writes value on click, confirms with a clipboard-to-check swap and an aria-live announcement, then reverts after resetMs. Owns its own confirm/reset state; observe copies via onCopy. Pick a shape with variant; time nothing yourself (the theme does).

value

string

The text written to the clipboard when the button is clicked.

variant?

CopyButtonVariant = "label"

The button shape. "label" (default) is a primary-fill pill with visible text; "icon" is a compact muted-ghost glyph-only button.

children?

ReactNode = "Copy"

The visible resting label, "label" variant only (ignored by "icon"). Default "Copy".

copiedText?

ReactNode = "Copied"

The visible confirmed label shown after a copy, "label" variant only. Default "Copied".

label?

string = "Copy to clipboard"

The button's accessible name (aria-label) while resting. Essential for the "icon" variant, which has no visible text. Default "Copy to clipboard".

copiedLabel?

string = "Copied to clipboard"

The accessible name after a copy, also announced via the aria-live region. Default "Copied to clipboard".

resetMs?

number = 2000

How long the confirmed state holds, in milliseconds, before it reverts to resting. Default 2000.

onCopy?

(value: string) => void

Fired at the copy beat, after the clipboard write is attempted, with the copied value. Use it to tick your own analytics or toast; the button needs nothing back.

disabled?

boolean

Disable the button (skips the copy and the swap).

className?

string

Merged onto the button element.

ref?

Ref<HTMLButtonElement>

Ref to the underlying <button>, React 19 ref-as-prop style, for consumers that need to focus or measure it.

Related examples