CopyButton

Copies a piece of text, and says that it did.

Import it from rei-kit: import { CopyButton } from 'rei-kit'

Open CopyButton in the live documentation, where every prop below is a control you can change, in four materials and ten palettes.

Usage

<script setup lang="ts">
import { CopyButton } from 'rei-kit'
</script>

<template>
  <CopyButton
    text="pnpm add rei-kit"
    copy-label="Copy the command"
    copied-label="Copied"
    error-label="Could not copy"
    with-text
  />
</template>

Props

Props
PropTypeRequired or defaultWhat it is for
textstringyesWhat lands on the clipboard.
copyLabelstringyesThe button's name at rest, e.g. "Copy the key".
copiedLabelstringyesIts name for the two seconds after, e.g. "Copied".
errorLabelstringundefinedSaid when the browser refuses. Unset, a refusal only leaves it unchanged.
withTextbooleanfalseShow the label beside the icon, rather than only to assistive tech.
variant'default' | 'unstyled''default'`unstyled` keeps the copying and drops the surface and the icon. The announcement is the part that is laborious and the part that is dropped: a copy button that says nothing leaves somebody who cannot see the tick pressing it twice. Three places on this kit's own site wrote their own copy button to get a different shape — a pill in a code block's bar, a whole install command — and all three lost the announcement on the way. That is the gap this closes: the behaviour without the paint, the same answer `BaseButton` and `BaseInput` give. Unstyled brings no focus ring either, so give it one.

About rei-kit

rei-kit is an accessible Vue 3 and Tailwind CSS 4 component library: 106 components, themed by role rather than by colour on three independent axes — ten WCAG-checked palettes, four materials and light or dark, each switched with one attribute. Typed, tested, SSR-safe, no runtime dependencies, MIT.

pnpm add rei-kit · npm · GitHub