CopyButton
Copies a value: a connection string, an ID, a command. For a moment it shows a check and says «Copied», and a screen reader hears what was copied.
import { CopyButton } from '@sypnia/ui/react'
Beside a field and beside an ID
Press a button: the icon becomes a check for a moment.
proj_7f3a9cCode
import { CopyButton, InputGroup, Input } from '@sypnia/ui/react';
// Press either button: the icon becomes a check for a moment and a screen reader hears what was copied.
export default function Values() {
const url = 'postgres://shop.eu.sypnia.app:5432/shop';
return (
<div className="sy-stack">
<InputGroup end={<CopyButton value={url} label="connection string" iconOnly />}>
<Input machine readOnly value={url} aria-label="Connection string" />
</InputGroup>
<div className="sy-row"><code className="sy-machine">proj_7f3a9c</code><CopyButton value="proj_7f3a9c" label="project ID" /></div>
</div>
);
} When to use it
Use it when
- Next to any value people paste somewhere else.
- Name what is copied with
labelwhen it shows only an icon.
Do not use it when
- Secrets shown once: use SecretField, which also warns that it will not be shown again.
- Long text the person needs to read first: show it, then offer the button.
For everyone
- Its name says what it copies: «Copy connection string».
- The result is said in a status message, not only shown with an icon.
Props
| CopyButton | Type | Default |
|---|---|---|
valuerequiredThe text to copy, or a function that returns it at the moment of copying. | string | (() => string) | |
iconOnly | boolean | |
labelWhat is copied, used in the button's name: «connection string». | string | |
size | "sm" | "md" | "lg" | sm |
variant | "secondary" | "quiet" | quiet |