GooseUI

Components

Copy Field

New

A “label: value” row for details pages and admin panels. The value sits in a field with a CopyButton (variant="inline") at its end: the icon turns into a check mark after copying. CopyField only adds the label, truncation and masking, copying itself is done by CopyButton and useCopyToClipboard.

Browser Support

Async clipboard

Copies the field value.

Your browser:

Preview

Click the icon at the end of a field, or move to it with Tab and press Enter.

Customer
Name
Alex Morgan
Email
alex.morgan@example.com
Phone
+1 555 0142 778
Order
ORD-2048-7731

Installation

npx shadcn@latest add @gooseui/copy-field
pnpm dlx shadcn@latest add @gooseui/copy-field
yarn dlx shadcn@latest add @gooseui/copy-field
bunx --bun shadcn@latest add @gooseui/copy-field

Usage

import { CopyField } from "@/components/ui/copy-field"

export function CustomerCard() {
  return (
    <div className="space-y-1">
      <CopyField label="Email" value="alex.morgan@example.com" labelClassName="w-20" />
      <CopyField label="Order" value="ORD-2048-7731" mono labelClassName="w-20" />
    </div>
  )
}

Examples

Long values

By default a long value is cut to one line and the full text goes to the tooltip. With truncate={false} it wraps instead.

Address
221 Pine Street, Apartment 14, Springfield, 49201
Address
221 Pine Street, Apartment 14, Springfield, 49201
<CopyField label="Address" value={address} />
<CopyField label="Address" value={address} truncate={false} />

Masked value

displayValue changes what is shown, while the full value is still what gets copied.

API key
demo_key••••••••6wcy
<CopyField
  label="API key"
  value={apiKey}
  displayValue={`${apiKey.slice(0, 8)}••••••••${apiKey.slice(-4)}`}
  mono
/>

Props

PropTypeDefaultDescription
labelstring-Text before the value
valuestring-Value to show and copy
displayValueReactNode-What to show instead of value. Copying still uses value
monobooleanfalseMonospace font for IDs, keys and codes
truncatebooleantrueCut to one line with the full value in title
timeoutnumber2000How long the confirmation stays, in ms
labels{ copy?: string; copied?: string }{ copy: "Copy", copied: "Copied" }Accessible names of the copy button before and after copying
labelClassNamestring-Classes for the label, e.g. a fixed width to align rows
valueClassNamestring-Classes for the value
onCopy(value: string) => void-Called after a successful copy
onCopyError(error: Error) => void-Called when the browser refuses to copy
classNamestring-Additional CSS classes