# CopyButton

> Button preset wired to the clipboard, morphing its icon and label to a success or failure state for a moment after each copy attempt.

- Package: `fancy-ui-vue` (Vue 3.5+ + Tailwind CSS v4)
- Category: Actions
- Tags: copy, clipboard, button, success
- Dependencies: button, status-morph
- Types: `CopyButtonProps`
- Docs: https://fancy-ui.rama.app/docs/components/copy-button
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/vue/src/components/copy-button

## Import

```vue
<script setup lang="ts">
import { CopyButton } from 'fancy-ui-vue';
</script>
```

Setup (once per project): `npm install fancy-ui-vue`, then put these lines in your main CSS file (the stylesheet imports go right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-vue/tailwind.css";
@import "fancy-ui-vue/styles.css";
```

Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in a Vue template; when one differs from the Svelte name, the Svelte name follows in parentheses. Snippets become named slots (`#default` is the default snippet), a prop the Vue port declares as a model is a `v-model:<name>` (except `ref`, exposed via `defineExpose({ ref })`: put a template ref on the component and read `.ref`) and callbacks are listeners (`onclick` is `@click`). Every component sets `inheritAttrs: false`: `class` is a declared prop, merged where the Svelte component applies it (not always the root element), and only when the props table below lists it; other attributes do not fall through unless the package README lists the component as forwarding native attributes. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/vue#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` (required) | `string` | — | The text written to the clipboard on activation |
| `label` | `string` | `"Copy"` | Idle label |
| `copiedLabel` | `string` | `"Copied"` | Label shown for resetMs after a successful copy |
| `errorLabel` | `string` | `"Copy failed"` | Label and announcement shown after a failed copy |
| `resetMs` | `number` | `2000` | How long the copied state holds before reverting, in milliseconds |
| `variant` | `ButtonVariant` | `"outline"` | Passed straight through to the underlying Button |
| `size` | `ButtonSize` | `"md"` | Passed straight through to the underlying Button |
| `disabled` | `boolean` | `false` | Disables the button and blocks the copy |
| `iconOnly` | `boolean` | `false` | Drops the visible label, moving it to aria-label instead |
| `@copy` (Svelte `onCopy`) | `(value: string, ok: boolean) => void` | — | Called with the value and whether the write actually succeeded |
| `@click` (Svelte `onclick`) | `(event: MouseEvent) => void` | — | Click handler, called right after the copy starts; never called while disabled |
| `class` | `string` | — | Additional CSS classes |
| `ref` | `HTMLButtonElement \| HTMLAnchorElement \| null` | `null` | Bindable element reference, matching Button's own ref type |
| `sound` | `boolean` | `false` | Plays the copy cue on a successful copy and error on a failed one, once the user has enabled sound |

## Slots

| Slot | Description |
| --- | --- |
| `#default` (Svelte `children`) | Overrides the default icon + label content |

## Example

```vue
<script setup lang="ts">
import { CopyButton } from "fancy-ui-vue";
</script>

<template>
	<CopyButton sound value="npm install fancy-ui-vue" />
</template>
```
