A svelte action to copy text to clipboard. It uses the `navigator.clipboard` api, with a fallback to the legacy method.
npm install svelte-copyA svelte action to copy text to clipboard. It uses the navigator.clipboard api, with a fallback to the legacy method.
``sh`
npm install svelte-copy -D
This library only works with Svelte 5, checkout svelte-copy@1 for Svelte 3/4 support.
The simplest use is to just pass the text you want to copy:
`svelte
`
You can expand that with an options object:
`svelte
use:copy={{
text,
events: ['click'],
onCopy({ text, event }) {
alert(Text copied: "${text}". Triggered by "${event}");`
},
onError({ error, event }) {
alert(error.message)
}
}}
>
Copy
- The on:svelte-copy event is now a onCopy param to the action options.on:svelte-copy:error
- The event is now a onError param to the action options.events
- The option now only accepts string[], rather than string | string[]`
- Svelte 5 is now required