Vitral 0.2.18
Button

CopyButton

A button that copies text to the clipboard, answers with a tick for a moment, and tells a screen reader it worked.

Import

main.ts
import { CopyButton } from '@vitral/vue';

Basic

With no `label` it shows only its icon, named “Copy”. `value` may be a function, and it may wait.

pnpm add @vitral/vue
<script setup lang="ts">import { CopyButton } from '@vitral/vue'; const pageLink = () => window.location.href;</script> <template>    <div style="display: flex; flex-wrap: wrap; gap: 1rem; align-items: center">        <code>pnpm add @vitral/vue</code>        <CopyButton value="pnpm add @vitral/vue" />        <CopyButton value="pnpm add @vitral/vue" label="Copy command" copied-label="Copied" variant="outlined" />        <CopyButton :value="pageLink" label="Copy link" severity="primary" variant="filled" rounded />    </div></template>

Beside a field

<script setup lang="ts">import { CopyButton, InputGroup, InputGroupAddon, InputText } from '@vitral/vue'; const key = 'sk_live_51Hx9c2vT7qPz';</script> <template>    <InputGroup style="max-width: 24rem">        <InputText :model-value="key" readonly aria-label="API key" />        <InputGroupAddon><CopyButton :value="key" /></InputGroupAddon>    </InputGroup></template>

API

Read from packages/vue/src/components/CopyButton/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
value string | (() => string | Promise<string>)What is copied, or a function returning it (and it may wait).
label stringWithout one the button shows only its icon, named "Copy".
copiedLabel stringShown in place of `label` for a moment once copied.
timeout numberHow long the tick stays, in milliseconds. Defaults to 2000.
severity SeverityDefaults to `'secondary'`.
variant 'filled' | 'outlined' | 'text'Defaults to `'text'`.
size Size—
rounded boolean—
disabled boolean—

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
copy value: string—
error error: unknown—