# CopyButton

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

Status: beta. Category: Actions.

```ts
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

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` (required) | `string` |  | Text written to the clipboard. |
| `children` | `ReactNode` |  | Visible label. Without it the button is icon-only, labelled "Copy". |
| `copiedLabel` | `string` |  | Announced and shown after copying. Default "Copied". |
| `fullWidth` | `boolean` |  |  |
| `loading` | `boolean` |  | Shows a spinner, disables the button and sets `aria-busy`. |
| `onCopy` | `((value: string) => void)` |  |  |
| `size` | `"sm" \| "md" \| "lg"` |  |  |
| `timeout` | `number` |  | How long the copied state lasts, in ms. Default 1500. |
| `variant` | `"link" \| "primary" \| "danger" \| "outline" \| "secondary" \| "ghost"` |  |  |

## Example: Next to a value

```tsx
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

```tsx
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
