Copy Button
A button component that copies text to clipboard with visual feedback.Overview
CopyButton is an IconButton wired to the clipboard: pass the text to copy and it handles the click, swaps the copy icon for a check, and announces "Copied" to screen readers. The check icon reverts after resetTimeout (default 1000ms); set resetIcon={false} to keep it. Drop it next to code snippets, API keys, and IDs. If you need copy behavior with your own UI, use the useCopyToClipboard hook from @raystack/apsara/hooks instead.
Anatomy
Import and assemble the component:
1import { CopyButton } from "@raystack/apsara";23<CopyButton />
API Reference
The CopyButton component extends IconButton props and accepts the following additional props
Prop
Type
All IconButton props are supported
Slots
Every rendered part carries a stable data-slot attribute for styling and testing:
| Slot | Element |
|---|---|
copy-button | The root <button> element |
copy-button-icons | Wrapper that swaps between the copy and check icons |
copy-button-copy-icon | The copy icon |
copy-button-check-icon | The check icon shown after copying |
copy-button-status | Visually hidden live region announcing "Copied" |
Examples
Size
Like IconButton, CopyButton supports sizes 1 through 4. Default is 2.
1<Flex gap={5} align="center">2 <CopyButton text="Copy me!" size={1} />3 <CopyButton text="Copy me!" size={2} />4 <CopyButton text="Copy me!" size={3} />5 <CopyButton text="Copy me!" size={4} />6</Flex>
States
CopyButton inherits all IconButton states. A disabled button ignores clicks and never triggers a copy.
1<Flex gap={5} align="end">2 <CopyButton text="Copy me!" size={4} />3 <CopyButton text="Copy me!" size={4} disabled />4</Flex>
Accessibility
- Uses
buttonrole with appropriatearia-label - Announces copy confirmation to screen readers via
aria-liveregion - Supports keyboard activation with Enter and Space keys