CopyButton

Copies a value to the clipboard and confirms it with a check and a screen-reader announcement.

Status: beta. Category: Actions.

import { CopyButton } from '@glyphui/ui'

Exports: CopyButton, copyButtonStyles.

Notes

  • Without children it is icon-only and labelled "Copy"; pass aria-label to say what is copied.
  • If the browser blocks clipboard access, nothing changes, so keep the value visible and selectable.
  • Accepts Button variants and sizes; defaults to outline.

CopyButton props

PropTypeDefaultDescription
value (required)stringText written to the clipboard.
childrenReactNodeVisible label. Without it the button is icon-only, labelled "Copy".
copiedLabelstringAnnounced and shown after copying. Default "Copied".
fullWidthboolean
loadingbooleanShows a spinner, disables the button and sets aria-busy.
onCopy((value: string) => void)
size"sm" | "md" | "lg"
timeoutnumberHow long the copied state lasts, in ms. Default 1500.
variant"link" | "primary" | "danger" | "outline" | "secondary" | "ghost"

Example: Next to a value

import { CopyButton, Field, Input } from '@glyphui/ui'

export default function Example() {
  const key = 'gk_live_51Hx9Q2eZvKYlo2C8a7P'
  return (
    <Field
      label="Publishable key"
      description="Safe to use in your frontend."
      className="w-full max-w-md"
    >
      <div className="flex gap-2">
        <Input readOnly value={key} className="font-mono" />
        <CopyButton value={key} aria-label="Copy publishable key" />
      </div>
    </Field>
  )
}

Example: With a label

import { CopyButton } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <CopyButton value="npm install @glyphui/ui">Copy install command</CopyButton>
      <CopyButton value="https://glyphui.xyz/" variant="ghost" size="sm" copiedLabel="Link copied">
        Copy link
      </CopyButton>
    </div>
  )
}

Live page: https://glyphui.xyz/components/copy-button