Copy Button

Copy text to the clipboard with animated status feedback.

Installation

pnpm dlx shadcn-svelte@latest add http://sveltekit-prerender/r/copy-button.json

Usage

usage.svelte

Props

CopyButton

Button that copies text and displays animated status feedback.

NameTypeDefaultDescription
textstring | (() => string)requiredText to copy, or a function that returns it.
childrenSnippetundefinedOptional label rendered beside the status icon.
idleIconSnippetundefinedCustom icon shown before the copy action. Defaults to CopyIcon.
doneIconSnippetundefinedCustom icon shown after a successful copy. Defaults to CheckIcon.
errorIconSnippetundefinedCustom icon shown when copying fails. Defaults to CircleXIcon.
onCopySuccess(text: string) => voidundefinedCalled with the copied text after a successful copy.
onCopyError(error: Error) => voidundefinedCalled when the copy operation fails.
onclick(event: MouseEvent) => voidundefinedCalled after the copy action starts.
variantButtonVariant'default'Visual style inherited from the Button component.
sizeButtonSize'icon'Button size.
classstringundefinedAdditional classes applied to the button.
aria-labelstring'Copy'Accessible label for the button.