Copy element text content or input values to the clipboard.
Перейти к файлу
Armağan a4a20027ac
Merge pull request #77 from github/dependabot/npm_and_yarn/npm_and_yarn-82ad408bf4
Bump the npm_and_yarn group with 2 updates
2024-10-11 15:57:21 +10:00
.devcontainer Add a .devcontainer 2022-02-28 17:04:01 +00:00
.github/workflows upgrade CI to node 18 LTS 2023-06-08 15:17:31 +01:00
examples [example] add announcement of text being copied 2023-10-23 16:53:45 +01:00
src Update src/clipboard-copy-element.ts 2023-09-28 10:00:43 -07:00
test Fix test; start browser with clipboar-read perm 2023-09-28 10:34:37 -07:00
.eslintrc.json upgrade to new web component standards 2023-06-08 15:13:50 +01:00
.gitignore <clipboard-copy> 2018-02-27 15:20:01 -07:00
CODEOWNERS move AOR to primer 2022-09-23 18:20:13 +01:00
LICENSE <clipboard-copy> 2018-02-27 15:20:01 -07:00
README.md Update link to polyfill 2020-10-31 16:20:29 +01:00
custom-elements.json upgrade to new web component standards 2023-06-08 15:13:50 +01:00
package-lock.json Bump the npm_and_yarn group with 2 updates 2024-10-10 15:54:47 +00:00
package.json Bump the npm_and_yarn group with 7 updates 2024-09-15 22:00:01 +00:00
tsconfig.json upgrade to new web component standards 2023-06-08 15:13:50 +01:00
web-test-runner.config.js Fix test; start browser with clipboar-read perm 2023-09-28 10:34:37 -07:00

README.md

<clipboard-copy> element

Copy element text content or input values to the clipboard.

Installation

$ npm install --save @github/clipboard-copy-element

Usage

Script

Import as ES modules:

import '@github/clipboard-copy-element'

With a script tag:

<script type="module" src="./node_modules/@github/clipboard-copy-element/dist/index.js">

Markup

<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 clipboard-copy event is dispatched from the <clipboard-copy> element:

document.addEventListener('clipboard-copy', function(event) {
  const button = event.target
  button.classList.add('highlight')
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.