Beside a value
import { CopyButton } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
export default function Example() {
return (
<Stack direction="horizontal" space="space-100">
<Text isNumeric>INV-2026-0318</Text>
<CopyButton value="INV-2026-0318" aria-label="Copy the invoice number" />
</Stack>
);
}import { CopyButton } from "@senvenli/react/action";Examples
With a label
A visible label for a value people copy often, such as an install command.import { CopyButton } from "@senvenli/react/action";
export default function Example() {
return (
<CopyButton value="npm i @senvenli/react" variant="default" size="medium">
Copy install command
</CopyButton>
);
}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
| Prop | Type | Default | Description |
|---|---|---|---|
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 | string | – | The name of an icon-only button: "Copy the invoice number". Default "Copy". |
variant | ButtonVariant | "subtle" | |
size | ButtonSize | "small" | |
radius | ComponentRadius | – | |
onCopy | (text: string) => void | – | Runs after a successful copy (to show a toast, log, …). |
valueRequiredstring | (() => string | Promise<string>)The text to copy, or a function that returns it (or a promise of it) at the moment of the press.
childrenReact.ReactNodeShown as the label; left out, the button is icon-only and named by
aria-label(default "Copy").aria-labelstringThe name of an icon-only button: "Copy the invoice number". Default "Copy".
variantButtonVariantDefault"subtle"sizeButtonSizeDefault"small"radiusComponentRadiusonCopy(text: string) => voidRuns after a successful copy (to show a toast, log, …).