Copy Button
A button that copies text to the clipboard, with a check on success.
Usage
CopyButton writes value to the clipboard on click, then swaps its copy icon for an animated check for a couple of seconds. It's built on Button, so it takes every Button prop (variant, size, disabled, …) - it just defaults to a ghost icon-sm icon button.
value is flexible: a string, a function returning a string (or a promise of one - handy for computing the text lazily), or a ref to an element, in which case its value (inputs/textareas) or textContent is copied. That makes it a natural fit in the corner of a code block or input.
Examples
Variants
CopyButton forwards variant (and any Button prop) straight through.
Sizes
Size comes from Button: use the square icon-sm / icon-md / icon-lg for an icon-only button (the default is icon-sm), or sm / md / lg when you add a text label.
With a label
Pass children to show text beside the icon. A string label automatically swaps to copiedLabel on success, mirroring the check animation.
Copy from an element
Give value a ref instead of a string to copy another element's content - here a code snippet. The button copies the element's textContent (or the value of an input/textarea).
RTL
Every Appica UI component supports right-to-left layouts out of the box. Set the dir attribute on a container (commonly your <html> element) so CSS logical properties resolve correctly, and wrap your tree in DirectionProvider so direction-aware behavior (roving focus, popup placement, and the like) follows the same direction.
The icon and label swap sides to follow the resolved direction. For setup details and caveats, see the RTL guide.
API reference
CopyButton
Extends Button - every Button prop applies. The props below are the copy-specific additions and defaults.
CopyButton falls back to a hidden-textarea + execCommand('copy') when the async Clipboard API is unavailable, and exposes data-copied while in the copied state for styling.
Accessibility
- Renders a real
<button>with an accessible name fromlabel(andcopiedLabelonce copied), so an icon-only button is still announced. - The copied state is conveyed by the accessible-name change, not color alone.
disabled(a Button prop) blocks the copy and exposesdata-disabledfor styling.- The icon cross-fade and check-draw animations honor
prefers-reduced-motion.