Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Actions

CopyButton

Copies arbitrary text or the content of another element with accessible success and failure feedback.

FrameworksAstro · React · Elements

Registry commandlumen add CopyButton

InteractionEnhanced runtime

01

See it and copy it

Framework example

Choose Astro, React, or Elements to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.

AstroCode target · live preview uses Astro

Join the Lumen workspace at https://lumen.santi020k.com

View CopyButton code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.
astro
---
import { CopyButton } from '@santi020k/lumen-astro'
---

<div class="grid gap-3">
  <p id="share-message">Join the Lumen workspace at https://lumen.santi020k.com</p>
  <div class="flex flex-wrap gap-2">
    <CopyButton target="#share-message">Copy message</CopyButton>
    <CopyButton value="https://lumen.santi020k.com" variant="default" size="sm" toast>
      Copy link
      <span slot="copied">Link copied</span>
      <span slot="error">Copy failed</span>
    </CopyButton>
  </div>
</div>
Edit CopyButton in browser
02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add CopyButton
lumen add CopyButton

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
valuestring-Copies the supplied arbitrary text without requiring code semantics.
targetCSS selector-Copies text content or a form control value from the referenced element.
label, copiedLabel, errorLabelstringlocalized defaultsSets the accessible idle, success, and failure feedback.
resetAfternumber2000Sets how long the copied or error state remains active in milliseconds.
toastbooleanfalseAlso dispatches a Lumen Toast notification for copy success or failure.
variantButton variant"outline"Uses the same default, destructive, ghost, link, outline, and secondary treatments as Button.
size"default" | "sm" | "lg" | "icon""default"Uses the shared Button sizing and touch-target contract.
copiedContent, errorContentReactNodelocalized labelsCustomizes visible React feedback while label props remain the accessible announcement.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:copy-successCopyButton{ value: string }Fires after arbitrary text is written to the clipboard.
ui:copy-errorCopyButton{ error: unknown }Fires when the Clipboard API is unavailable or rejects the write.

Web docsFull catalog