ui-kit0.0

Data

Copy button

Copy a value with instant confirmation.

API key

An icon-only copy button inside an input group. The icon swaps to a check with a small pop, a live region says “Copied”, and it reverts after 1.5 seconds.

Keep this key private. Rotate it from the dashboard if it is ever exposed.

When to use

  • Anything people paste elsewhere: API keys, ids, commands, share links, error details.
  • Beside the value, not instead of it: show the text so people can verify what they copied.

Labelled and icon-only

Add label for a text button; it keeps one width while “Copy” becomes “Copied”. Icon-only buttons need an aria-label. value may be a function, read at click time.

API

CopyButton

PropTypeDefaultDescription
valuestring | () => string—The text to copy.
labelReactNode—Visible text. Omit for icon-only.
copiedLabel / errorLabelReactNode'Copied' / 'Copy failed'Text for each state.
resetAfternumber1500Milliseconds before returning to idle.
onCopy / onCopyError(text) => void / () => void—Callbacks.
variant, size, ...propsButtonProps—Forwarded to Button (outline when labelled, ghost when icon-only; size sm).

useCopy({ resetAfter, onCopy, onError }) returns { copy, copied, error, status, reset } for custom triggers. copyText(text) is the helper underneath: it uses the Clipboard API and falls back to a hidden textarea.

Keyboard

KeyAction
Enter / SpaceCopies the value.

Accessibility

  • A native button. Its name stays “Copy”; a polite live region announces “Copied” or “Copy failed”.
  • Success and error are shown by icon and text, not colour alone.

Motion

  • The copy icon shrinks and blurs out as the check pops in (snappy spring). An error shakes the alert icon slightly.
  • Reduced motion: the icons swap without movement.