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> <script>
let slot let slot
function copy_code() { let copied = false
navigator.clipboard.writeText(slot?.innerText) async function copy_code() {
await navigator.clipboard.writeText(slot?.innerText)
copied = true
} }
</script> </script>
<pre> <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> <span bind:this={slot}><slot></slot></span>
</pre> </pre>