Icon-only copy button
Useful when the surrounding layout already shows the full value.
<CwCopy value={device.serialNumber} />Click-to-copy button with visual feedback and a screen-reader announcement. Pass any string as value. If the browser blocks clipboard access the button reports the failure instead of
pretending it worked (customise the text with labels.failedFeedback).
Just the copy button — hover to see the clipboard icon, click to copy.
Hello, CropWatch! Pass children to display the value alongside the button.
cw_demo_4f9a2c71e0b8d35a <CwCopy value="cw_demo_4f9a2c71e0b8">
<code>cw_demo_4f9a2c71e0b8</code>
</CwCopy>Hello, CropWatch! Hello, CropWatch! Hello, CropWatch! eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkNyb3BXYXRjaCJ9 The onCopy prop fires after a successful copy.
Last event: copied 0 times
CwCopy handles the clipboard action and temporary copied feedback. You choose the string to copy, and optionally render visible content next to the button.
| API | Type | Details |
|---|---|---|
value Required | string | Text written to the clipboard. |
size Default: | 'sm' | 'md' | 'lg' | Size preset for the copy affordance. |
feedbackDuration Default: | number | How long the copied feedback state stays visible. |
children | Snippet | Optional visible content rendered before the copy button. |
onCopy | (value: string) => void | Runs after a successful copy operation. |
labels.failedFeedback Default: | string | Message shown when copying fails. |
Each snippet is a complete, working example you can paste into a Svelte 5 component.
Useful when the surrounding layout already shows the full value.
<CwCopy value={device.serialNumber} />Use this when the user should see exactly what will be copied.
<script lang="ts">
let copiedCount = $state(0);
</script>
<CwCopy
value="sk-proj-abc123def456ghi789"
size="lg"
feedbackDuration={2500}
onCopy={() => (copiedCount += 1)}
>
<code>sk-proj-abc123def456ghi789</code>
</CwCopy>