Show feedback when code is copied

This commit is contained in:
Sofía Aritz 2023-08-01 19:02:48 +02:00
parent 5d81440577
commit 8563199bfa

View file

@ -1,12 +1,14 @@
<script>
let slot
function copy_code() {
navigator.clipboard.writeText(slot?.innerText)
let copied = false
async function copy_code() {
await navigator.clipboard.writeText(slot?.innerText)
copied = true
}
</script>
<pre>
<button on:click={copy_code}>Copy code</button>
<button on:click={copy_code}>Copy code</button> {#if copied}<span style="display: inline">Copied!</span>{/if}
<span bind:this={slot}><slot></slot></span>
</pre>