Copy Button
One-click copy-to-clipboard button with confirmation.
<arc-copy-button> Overview
>
CopyButton provides a single-click interaction for copying a text value to the system clipboard. It renders as a compact button with a clipboard icon and a "Copy" label. When clicked, it calls the Clipboard API to write the `value` property to the clipboard, then transitions to a green checkmark "Copied!" confirmation state for two seconds before reverting to its default appearance. This gives users immediate visual feedback that the copy succeeded.
The component is commonly paired with code blocks, API keys, URLs, and other text that users frequently need to paste elsewhere. Because it uses the async Clipboard API (`navigator.clipboard.writeText`), it requires a secure context (HTTPS or localhost). If the clipboard write fails — for example in a non-secure iframe — the error is caught silently and the button remains in its default state.
CopyButton dispatches an `arc-copy` event on successful copy, carrying the copied value in the event detail. This lets parent components react to the copy — for example, showing a toast notification or logging the event. The button supports a `disabled` attribute that reduces opacity and prevents interaction, and all states (default, hover, focus, copied) are styled through ARC design tokens for consistent theming.Guidelines
When to use
- Place CopyButton adjacent to the content it copies — next to a code snippet, URL, or API key
- Set the value property to the exact string the user expects to paste, not a formatted or truncated version
- Use the arc-copy event to trigger a toast or analytics event confirming the copy action
- Ensure the page is served over HTTPS so the Clipboard API is available
- Use the disabled attribute when the value is not yet available (e.g. while loading)
When not to use
- Do not use CopyButton for general-purpose actions — it is specifically designed for clipboard copy
- Do not set the value to empty string and expect the button to be useful; always provide meaningful content
- Do not override the 2-second confirmation timeout — it is calibrated for comfortable visual feedback
- Do not nest CopyButton inside another button or interactive element, as this creates invalid HTML nesting
- Do not rely solely on the confirmation state for feedback; pair with a toast for users who look away
Features
- One-click copy to clipboard using the async Clipboard API
- Visual confirmation state with green checkmark icon and "Copied!" label for 2 seconds
- `arc-copy` custom event fired on successful copy with the value in the detail payload
- Disabled state with reduced opacity and pointer-events: none
- Focus-visible ring via var(`--focus-glow`) for keyboard accessibility
- Hover state with elevated border and background color shift
- Graceful fallback when the Clipboard API is unavailable (non-secure contexts)
- Compact inline-flex layout that fits naturally next to code blocks and input fields
Preview
npm install @arclux/arc-ui
Usage
This component requires JavaScript. No pure HTML/CSS version is available — use the Web Component directly or a framework wrapper.
<arc-copy-button value="npm install @arclux/arc-ui"></arc-copy-button> import { CopyButton } from '@arclux/arc-ui-react';
export default function Example() {
return (
<CopyButton value="npm install @arclux/arc-ui" />
);
} <script setup>
import { CopyButton } from '@arclux/arc-ui-vue';
</script>
<template>
<CopyButton value="npm install @arclux/arc-ui" />
</template> <script>
import { CopyButton } from '@arclux/arc-ui-svelte';
</script>
<CopyButton value="npm install @arclux/arc-ui" /> import { Component } from '@angular/core';
import { CopyButton } from '@arclux/arc-ui-angular';
@Component({
imports: [CopyButton],
template: `
<arc-copy-button value="npm install @arclux/arc-ui"></arc-copy-button>
`,
})
export class MyComponent {} import { CopyButton } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<CopyButton value="npm install @arclux/arc-ui" />
);
} import { CopyButton } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<CopyButton value="npm install @arclux/arc-ui" />
);
} API
-
valuestring'' - The text string to copy to the clipboard when the button is clicked.
-
disabledbooleanfalse - Disables the button, preventing clicks and reducing visual opacity.
Events
-
arc-copydetail: { value: string } - Fired when text is successfully copied to the clipboard. `event.detail.value` contains the copied string.
See Also
- Code Block Syntax-highlighted code display with optional filename and copy button.
- Icon Button Compact button that renders an icon with optional text label, supporting ghost, secondary, and primary variants.
- Tooltip Contextual hint that appears on hover or focus, providing supplementary information without cluttering the UI. Supports four placement positions and a configurable show delay.