Skip to content
SENVENLI UI

Copy button

Copies a value to the clipboard; the icon turns into a check and a status says it was copied.
Beside a value
import { CopyButton } from "@senvenli/react/action";

Examples

With a label

A visible label for a value people copy often, such as an install command.

Guidelines

When to use it

  • A value people paste elsewhere: an ID, an API key, a link, a command.

Use something else when

  • The value is a field of a record, which DescriptionList can copy on its own. Description list

Do and avoid

  • Icon-only, name what is copied: "Copy the invoice number".

Accessibility

Built in

  • Says "Copied" (or that it could not copy) in a polite status, again on every press.
  • The check shows for two seconds.

You provide

  • An aria-label naming the value when it is icon-only.

API reference

CopyButton

valueRequired
string | (() => string | Promise<string>)

The text to copy, or a function that returns it (or a promise of it) at the moment of the press.

children
React.ReactNode

Shown as the label; left out, the button is icon-only and named by aria-label (default "Copy").

aria-label
string

The name of an icon-only button: "Copy the invoice number". Default "Copy".

variant
ButtonVariantDefault "subtle"
size
ButtonSizeDefault "small"
radius
ComponentRadius
onCopy
(text: string) => void

Runs after a successful copy (to show a toast, log, …).