Tinyrack

CopyButton

A reusable copy action with Clipboard API fallback and accessible status announcements.

Contract

The control reports idle, copied, or unavailable through data-copy-status. The latest copy attempt wins, and its result resets to idle after two seconds by default.

Install

pnpm add @tinyrack/ui

Scroll inside the code area to read long lines.

Styles

@import '@tinyrack/ui/components/copy-button.css';

Scroll inside the code area to read long lines.

Imports

import { TRCopyButton } from '@tinyrack/ui/components/copy-button';

Scroll inside the code area to read long lines.

Playground

Usage

Examples

Inherited Button combinations permalink

Appearance, variant, uiSize, and labels compose across Button styles. Idle and copied labels share a stable footprint; the longer unavailable label appears only on failure.

API

PropTypeDefaultDescription
valuestringrequiredText passed to the Clipboard API or the offscreen selection fallback.
idleLabelstring"Copy"Visible and accessible label before copying.
copiedLabelstring"Copied"Success label and polite announcement.
unavailableLabelstring"Copy unavailable"Failure label and polite announcement when both copy strategies fail.
onStatusChange(status) => voidReceives copied or unavailable, then idle after reset. Stale and unmounted attempts do not emit.
resetDelaynumber2000Milliseconds before a completed result resets to idle.

All TRButton props except children are inherited, including refs, native events, disabled, loading, loadingLabel, appearance, variant, and uiSize. Calling preventDefault() in onClick cancels the copy attempt.