Actions Core Stable
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
Available for Svelte 5, React, and Vue 3.
Preview
svelte
<script lang="ts">
import { CopyButton } from 'fancy-ui-svelte';
</script>
<CopyButton value="pnpm add fancy-ui-svelte" />Installation
pnpm add fancy-ui-svelte
import { CopyButton } from "fancy-ui-svelte";
Usage
svelte
<script lang="ts">
import { CopyButton } from 'fancy-ui-svelte';
</script>
<CopyButton value="pnpm add fancy-ui-svelte" />Examples
Basic Usage
An outline button that copies a value on click.
svelte
<script lang="ts">
import { CopyButton } from "$lib/fancy-ui/copy-button";
</script>
<CopyButton sound value="npm install fancy-ui-svelte" />Icon Only
Drops the visible label into aria-label for a toolbar.
svelte
<script lang="ts">
import { CopyButton } from "$lib/fancy-ui/copy-button";
</script>
<CopyButton sound value="npm install fancy-ui-svelte" iconOnly label="Copy install command" />Custom Labels
Overrides the idle and copied label text.
svelte
<script lang="ts">
import { CopyButton } from "$lib/fancy-ui/copy-button";
</script>
<CopyButton
sound
value="https://example.com/invite/9k2f"
label="Copy link"
copiedLabel="Link copied"
/>Variants
Four Button variants used as the idle skin.
svelte
<script lang="ts">
import { CopyButton } from "$lib/fancy-ui/copy-button";
import type { ButtonVariant } from "$lib/fancy-ui/button";
const variants: ButtonVariant[] = ["outline", "ghost", "secondary", "accent"];
</script>
<div class="flex flex-wrap items-center gap-3">
{#each variants as variant}
<CopyButton sound value="npm install fancy-ui-svelte" {variant} />
{/each}
</div>Interactive Playground
svelte
<script lang="ts">
import { CopyButton } from "$lib/fancy-ui/copy-button";
import type { ButtonSize, ButtonVariant } from "$lib/fancy-ui/button";
import PropsPlayground from "$lib/components/PropsPlayground.svelte";
</script>
<PropsPlayground
component="CopyButton"
slug="copy-button"
required={["value"]}
constraints={[
"`value` is required: it is the text written to the clipboard.",
"Clipboard access needs a secure context (https or localhost).",
]}
controls={[
{ key: "value", type: "text", label: "Value to copy", maxLength: 80 },
{ key: "label", type: "text", label: "Label", maxLength: 24 },
{
key: "variant",
type: "select",
label: "Variant",
options: ["primary", "secondary", "outline", "ghost", "accent", "destructive"].map((v) => ({
value: v,
label: v,
})),
},
{
key: "size",
type: "select",
label: "Size",
options: ["sm", "md", "lg"].map((v) => ({ value: v, label: v })),
},
{ key: "iconOnly", type: "boolean", label: "Icon only" },
{ key: "disabled", type: "boolean", label: "Disabled" },
]}
initialValues={{
value: "npm install fancy-ui-svelte",
label: "Copy",
variant: "outline",
size: "md",
iconOnly: false,
disabled: false,
}}
>
{#snippet preview(values)}
<CopyButton
value={values.value as string}
label={values.label as string}
variant={values.variant as ButtonVariant}
size={values.size as ButtonSize}
iconOnly={values.iconOnly as boolean}
disabled={values.disabled as boolean}
/>
{/snippet}
</PropsPlayground>Props
| Prop | Type | Default | Description |
|---|---|---|---|
value * | 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 |
onCopy | (value: string, ok: boolean) => void | - | Called with the value and whether the write actually succeeded |
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 |
|---|---|
children | Overrides the default icon + label content |
Links
Related components
Button
The foundational push-button: six variants, three sizes, a loading state, and a polymorphic href/anchor mode
Actions Core
ButtonGroup
Joins a row of adjacent actions into one seamless control — one border, one divider, no doubled edges
Actions Core
FollowButton
A follow toggle that shows the result at once, then commits when the server agrees or rolls back and says so, with the width held steady across every label
Actions Core