CopyField
Shows a value the person will need somewhere else (an address, an ID, a command) with a button that copies it.
import { CopyField, CopyFieldSkeleton } from '@sypnia/ui/react'
In a form
Press «Copy».
Your app sends its requests here.
Code
import { CopyField, Field, FormGrid } from '@sypnia/ui/react';
// Press «Copy»: the button answers «Copied» and a screen reader says it.
export default function Basic() {
return (
<FormGrid>
<Field label="Project address" hint="Your app sends its requests here.">
<CopyField value="https://storefront.sypnia.app" />
</Field>
<Field label="Project ID">
<CopyField value="prj_8f2k1x9c4m7q" />
</Field>
</FormGrid>
);
} On its own
A command to copy, named for screen readers with label.
Install the client in your app:
Code
import { CopyField } from '@sypnia/ui/react';
// Without a Field around it, `label` gives it its name for screen readers.
export default function Standalone() {
return (
<div className="sy-stack">
<p className="sy-text--sm sy-text--soft">Install the client in your app:</p>
<CopyField label="Install command" value="npm install @sypnia/client" />
</div>
);
} A long value
It stays on one line; Copy takes all of it.
For tools that talk to the database directly.
Code
import { CopyField, Field } from '@sypnia/ui/react';
// A long value stays on one line and scrolls inside the field; Copy always takes all of it.
export default function LongValue() {
return (
<Field label="Connection string" hint="For tools that talk to the database directly.">
<CopyField value="postgresql://readonly@db.storefront.sypnia.app:5432/storefront?sslmode=require&application_name=metabase" />
</Field>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
Code
import { CopyField, CopyFieldSkeleton } from '@sypnia/ui/react';
// A key that is being fetched. The skeleton has the same box as the real one, so nothing moves when the data arrives.
export default function Skeleton() {
return (
<div className="sy-stack">
<CopyField label="Project ID" value="prj_8f2c1a9e4b" />
<CopyFieldSkeleton />
</div>
);
} When to use it
Use it when
- A value made by the system that the person pastes elsewhere: addresses, IDs, commands, connection strings.
- The value is long or easy to mistype.
Do not use it when
- The value is a secret: add
secret(see SecretField). - It is a block of code with several lines: that is CodeBlock.
- The person can change the value: use an Input.
For everyone
- The button answers «Copied» in words, and a live region says it to screen readers.
- The value is read only: it can be focused, and focusing it selects everything.
- Inside a Field the label names it. Alone, pass
label.
Props
| CopyField | Type | Default |
|---|---|---|
valuerequired | string | |
label | string | |
once | boolean | |
secret | boolean |