copy-component
A Vanilla web component to wrap copy-able text/html elements and add their inner text to the clipboard.
- Zero dependencies
- Browser support: Modern, requires support for Web Component APIs (v1).
Usage:
import "copy-component";
Wrap html elements for example some pre formatted code:
<copy-component>
<pre><code class="language-js">
console.log("some code")
</code></pre>
<button slot="button">Copy</button>
</copy-component>
Programmatic API
Because this is a web component it can expose properties on the html element that can be accessed by javascript.
Say you have the following html without a copy button, you could trigger copying via code.
<copy-component>
<pre><code class="language-js">
console.log("some code")
</code></pre>
</copy-component>
like so:
await document.querySelector("copy-component").copy();
Load from CDN:
<script type="module">
import copyComponent from "https://cdn.skypack.dev/copy-component";
</script>
Use within a static site generator:
TODO