Copy element text content or input values to the clipboard.
$ npm install --save clipboard-copy-element
import 'clipboard-copy-element'
<clipboard-copy for="blob-path" class="btn btn-sm BtnGroup-item">
Copy path
</clipboard-copy>
<div id="blob-path">src/index.js</div>
<clipboard-copy value="src/index.js">Copy</clipboard-copy>
<clipboard-copy for="blob-path">Copy</clipboard-copy>
<div id="blob-path">src/index.js</div>
<clipboard-copy for="blob-path">Copy</clipboard-copy>
<input id="blob-path" value="src/index.js">
After copying to the clipboard, a copy event is dispatched that can be used to notify the user with confirmation, like a tooltip or button highlight.
document.addEventListener('copy', function(event) {
const button = document.activeElement
button.classList.add('highlight')
})
- Chrome
- Firefox
- Safari 9+
- Internet Explorer 11
- Microsoft Edge
npm install
npm test
Distributed under the MIT license. See LICENSE for details.