svelte-copyable
v0.5.3
Published
An easy to use Svelte action to copy text.
Downloads
9
Readme
Svelte Copyable
An easy to use Svelte action to copy text.
Using the Action
<script>
import { copyable } from "svelte-copyable";
const couponCode = "ABC";
</script>
<div use:copyable={couponCode}>
Copy coupon code
</div>
Using the Action with a Callback Event
<script>
import { copyable } from "svelte-copyable";
const couponCode = "ABC";
let showCopiedAlert = false;
function toggleCopiedAlert() {
if (showCopiedAlert) return;
showCopiedAlert = !showCopiedAlert;
setTimeout(() => {
showCopiedAlert = false;
}, 1000);
}
</script>
<div>
<div use:copyable={couponCode} on:textCopied={() => toggleCopiedAlert()}>
Copy coupon code
</div>
{#if showCopiedAlert}
<p>Copied</p>
{/if}
</div>