Actions

CopyButton

Button that writes plain text plus optional rich HTML/image clipboard representations and flips to a confirmation state after success.

import { CopyButton } from '@lostgradient/cinder';
actionclipboard
01

Overview

Reference usage

Button that copies a given text value to the clipboard with visual feedback.

Usage

svelte
<script lang="ts">
  import { CopyButton } from '@lostgradient/cinder';
</script>

<div style="display: flex; align-items: center; gap: 0.5rem;">
  <code
    style="padding: 0.25rem 0.5rem; background-color: var(--cinder-surface-inset); color: var(--cinder-text-default); border-radius: 4px;"
    >bun run validate</code
  >
  <CopyButton value="bun run validate" label="Copy validation command" />
</div>

By default the button is a borderless Copy icon, matched to the surrounding text and turning to a same-sized check once the copy lands; label names it and shows as its tooltip (inside a page's own Tooltip, the page's tooltip is the only one). Its coarse-pointer hit area remains larger than its painted glyph. textVisible adds the words "Copy" and "Copied" after the icon, and children writes other words; the icon always leads them. Both states are laid out together, so the button keeps one width and nothing beside it moves. A successful copy is announced once through a polite live region, copiedLabel ("Copied" by default), while the button keeps its name.

Live preview

Basic copy button

npx cinder install

02

When to use

Use when
  • Offering one-click copy of a token, snippet, share link, or code sample.
  • Pairing with code-block so readers can grab the rendered source.
  • Copying a value in running text with the inline appearance.
Avoid when
  • Triggering a generic non-clipboard action — use button instead.
  • Copying long-form rich content that needs format preservation — handle clipboard logic directly.
03

Examples

Basic copy button

Click to copy. The button enters a confirmation state for a brief moment.

04

Props

Props for copy-button
Name
Type
Default
Description
value required text Text to copy to the clipboard.
html text Optional HTML representation written alongside text/plain through ClipboardItem.
image text Optional image blob or URL written alongside text and HTML when supported.
confirmDuration number 1500 Duration in ms to show the confirmation state. Default 1500.
label text Accessible label for the idle state. Defaults to "Copy to clipboard".
copiedLabel text Accessible label for the copied state — what aria-live="polite" announces when the copy succeeds. Defaults to "Copied". Override this when label is customized so the live-region announcement reflects what just happened (e.g. label="Copy code" + copiedLabel="Code copied").
textVisible boolean false Shows the words "Copy", and "Copied" after a copy, after the icon. By default the button is the Copy icon alone (a Check after a copy), named by label, which also shows as a tooltip. The button keeps one width in both states.
appearance 'default' | 'inline' 'default' Use the borderless, text-sized face for a copy control that follows a value.
children snippet The words of the text face at rest, after the Copy icon. Passing them shows the text face.
confirmation snippet The words of the text face once copied, after the Check icon. Defaults to "Copied".
onError () => void Called when the clipboard write fails (permission denied, insecure context, or the legacy execCommand fallback also failing).