Copy Button
pnpm add @mielui/svelte CopyInstallation
npx @mielui/svelte add copy-buttonyarn dlx @mielui/svelte add copy-buttonbunx @mielui/svelte add copy-buttonUsage
Pass the text to copy. The button shows a copy icon with a tooltip, or a visible label when you give it children and a text size.
<script lang="ts">
import { CopyButton } from '@mielui/svelte/components/copy-button';
</script>
<CopyButton text="pnpm add @mielui/svelte" />
<CopyButton text="sk_live_example" labels={{ copy: 'Copy API key' }} variant="outline" size="md">
Copy key
</CopyButton>onclick runs before copying; call preventDefault() to cancel. oncopy runs after a successful clipboard write and receives the copied text. Clipboard access needs a secure context, so keep the source text visible for people to select by hand when it is blocked.
Examples
Copy confirmation
A status line under the command updates after a successful copy.
pnpm add @mielui/svelte Copy install commandCopy the command to your clipboard.
In a field
pnpm dlx @mielui/svelte add copy-button CopyVariants
Copied feedback
labels.copy is the tooltip and accessible name at rest, Copy by default. After a copy, the button holds its copied state and shows labels.copied, Copied by default. Every key in labels is optional and English is the fallback. duration is how long the copied state lasts in milliseconds, 2000 by default.
API reference
CopyButton
Copies text to the clipboard.
labelsCopyButtonLabelsOverrides the built-in text and accessible names. Every key is optional and English is the fallback.
textRequiredstringThe string written to the clipboard on click.
durationnumberHow long (ms) to hold the copied state before reverting.
Default
2000variantButtonVariantButton variant (defaults to
ghost).Default
'ghost'size"sm" | "md" | "lg" | "icon"Button size (defaults to
icon). Pass a text size when rendering children.Default
'icon'classstringClasses added to the element.
childrenSnippet<[]>Optional visible label rendered after the icon.
oncopy((text: string) => void)Fired after the text is successfully written to the clipboard.
pnpm dlx @mielui/svelte add copy-button