clipboard-copy-element

Copy element text content or input values to the clipboard.

Github stars Tracking Chart

<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.

Main metrics

Overview
Name With Ownergithub/clipboard-copy-element
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2018-02-27 22:21:36
Pushed At2025-04-14 20:34:52
Last Commit At
Release Count24
Last Release Namev1.3.0 (Posted on )
First Release Namev0.1.0 (Posted on 2018-03-01 18:05:50)
用户参与
Stargazers Count474
Watchers Count312
Fork Count264
Commits Count239
Has Issues Enabled
Issues Count11
Issue Open Count1
Pull Requests Count64
Pull Requests Open Count1
Pull Requests Close Count6
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private