Skip to main content
Urbicon UI

CopyButton

A copy-to-clipboard button that confirms the copy: the icon becomes a check and the button shows the success colour for a moment. Icon-only by default; pass label for a labelled variant.

Playground

Variant
Tier
<CopyButton
  intent="neutral"
  label=""
  value="npm i @urbicon-ui/blocks"
  variant="ghost"
/>

01 Examples

Icon-only (default)

With no label the button is icon-only. Drop it beside a value the user needs to grab, like a command or a token.
npm i @urbicon-ui/blocks
<code>npm i @urbicon-ui/blocks</code>
<CopyButton value="npm i @urbicon-ui/blocks" />

With a label

Pass label for a labelled button. The visible text becomes the accessible name, and it swaps to copiedLabel (default “Copied”) on success.
<CopyButton value="npm i @urbicon-ui/blocks" label="Copy" variant="outlined" />

Variants

CopyButton forwards variant to the underlying Button, so the same values apply: ghost (default), outlined, filled and text.
{#each ['ghost', 'outlined', 'filled'] as variant}
  <CopyButton value="urbicon" label="Copy" {variant} />
{/each}

02 In context

Copy an install command

The most common home for CopyButton: paired with a command or key inside a Card, so the value and its copy affordance read as one unit.
npm i @urbicon-ui/blocks
<Card padding="lg">
  <div class="flex items-center justify-between gap-4">
    <code>npm i @urbicon-ui/blocks</code>
    <CopyButton value="npm i @urbicon-ui/blocks" />
  </div>
</Card>

onCopy callback

onCopy fires with the copied value after a successful write; use it to log analytics, show a toast, or update local state. onError fires on the failure path instead.
Copied 0 time(s)
<script>
  let copies = $state(0);
</script>

<CopyButton value="urbicon" label="Copy token" onCopy={() => copies++} />
<span>Copied {copies} time(s)</span>

03 Accessibility

Stable name in icon-only mode

In icon-only mode the accessible name stays fixed (Copy, or your own aria-label); the copied/failed outcome is announced by the live region below, not by renaming the button.

Label in Name in labelled mode

In labelled mode the visible text is the accessible name (WCAG 2.5.3, Label in Name); no aria-label overrides it.

The result is announced

A visually-hidden role="status" live region announces the result (Copied or Copy failed) the moment it happens, in both modes and without moving focus. An aria-label change alone is not reliably announced, so the icon-only default would otherwise be silent to a screen reader.

The icon is decorative

The copy/check icon is aria-hidden; sighted users read state from the icon, the intent colour, and (in labelled mode) the swapped label.

Failure has a path

The clipboard write can fail in an insecure (non-HTTPS) context or when permission is denied. That path calls onError and shows the failed state rather than throwing through the render.

04 API Reference

19 props
19 props 1 required
Prop
Type
Default
Description

05 Types

Local type definitions used by this component.

9 types
Name
Kind
Category
Used by
Description

06 Installation

Import

import { CopyButton } from '@urbicon-ui/blocks';