sudodoki / copy-button

Web component to copy target text/dom-node value to clipboard
http://sudodoki.github.io/copy-button/example
19 stars 15 forks source link

<copy-button></copy-button>

A web-component that is not relying on Flash to copy stuff into the clipboard. Experience may vary, based on browser support, with downgrading to using prompt.

Installation

NPM

npm i --save copy-button after which you're good to use copy-button &

CDN

You can also use it from wzrd.in CDN and drop <script src='https://wzrd.in/standalone/copy-button@latest'></script> into your html

Usage

After having script ran, you're good to use <copy-button></copy-button> in your markup.

Inner content

If you're not specifying inner content, it would default to 'Click to copy to clipboard', otherwise provided content would be inserted into the button. Can use icons here, etc. See example

target-text

If you specify target-text attribute on button, provided value will be copied to clipboard. Example

target-element

If you specify target-element attribute on button, value or text of provided DOM node will be copied to clipboard (it will be retrieved using document.getElementById if value will be specified as #specifiedID or document.querySelectorAll in other cases). See examples

Under the hood

Built on top of document.registerElement polyfill & copy-to-clipboard