Copy element text content or input values to the clipboard.
Перейти к файлу
Kristján Oddsson 1fb6dc23c4
add babel-preset-github
2019-02-25 09:33:33 +00:00
examples Add example demo page 2018-05-18 10:07:08 -06:00
src Update Flow to include Clipboard interface 2019-01-07 13:33:34 -07:00
test Support copying href of target anchor element 2018-08-11 02:40:49 +02:00
.eslintrc.json <clipboard-copy> 2018-02-27 15:20:01 -07:00
.flowconfig <clipboard-copy> 2018-02-27 15:20:01 -07:00
.gitignore <clipboard-copy> 2018-02-27 15:20:01 -07:00
.travis.yml Add Travis configuration 2018-04-17 14:11:36 -06:00
LICENSE <clipboard-copy> 2018-02-27 15:20:01 -07:00
README.md Link to web component support 2018-08-21 14:57:46 -06:00
package-lock.json add babel-preset-github 2019-02-25 09:33:33 +00:00
package.json add babel-preset-github 2019-02-25 09:33:33 +00:00
prettier.config.js <clipboard-copy> 2018-02-27 15:20:01 -07:00
rollup.config.js Update rollup and babel plugins 2019-01-07 13:55:45 -07:00

README.md

<clipboard-copy> element

Copy element text content or input values to the clipboard.

Installation

$ npm install --save clipboard-copy-element

Usage

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>

Data sources

Attribute

<clipboard-copy value="src/index.js">Copy</clipboard-copy>

Element content

<clipboard-copy for="blob-path">Copy</clipboard-copy>
<div id="blob-path">src/index.js</div>

Form input

<clipboard-copy for="blob-path">Copy</clipboard-copy>
<input id="blob-path" value="src/index.js">
<clipboard-copy for="blob-path">Copy full URL</clipboard-copy>
<a id="blob-path" href="/path/to#my-blob">Link text will not be copied</a>

Events

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')
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Internet Explorer 11
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.