Giter Site home page Giter Site logo

github / clipboard-copy-element Goto Github PK

View Code? Open in Web Editor NEW
444.0 258.0 256.0 1.01 MB

Copy element text content or input values to the clipboard.

Home Page: https://github.github.io/clipboard-copy-element/examples/

License: MIT License

JavaScript 56.32% TypeScript 36.25% Dockerfile 7.44%
web-components custom-elements

clipboard-copy-element's Introduction

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

Hyperlink href

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

clipboard-copy-element's People

Contributors

broccolinisoup avatar camertron avatar colebemis avatar danielguillan avatar dependabot[bot] avatar dgraham avatar gambala avatar jfuchs avatar jonrohan avatar jorgecasar avatar keithamus avatar koddsson avatar manuelpuyol avatar mislav avatar muan avatar siddharthkp avatar simurai avatar sonicdoe avatar srt32 avatar theinterned avatar xvezda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clipboard-copy-element's Issues

Distribute on a CDN

I use a WordPress blog and would like to add this to my site. I imagined it would be as simple as adding a script tag from a CDN and using the element. After all, that's the point of a web component.

Distributing the dist on a CDN would be a good idea for such use cases where you don't have a module bundler or want to avoid an npm installation for just one package.

CustomEvent does not have what gets copied in `details`

It'd be great if the element also provided the text it copies, in the event.details.

Currently, if you use multiple clipboard-copy elements on a page, with various ways to define what to copy (i.e. for="..." or value="..."), and you want to get what is copied using clipboard-copy custom event, you'd have to write your event handler to handle all aforementioned cases.

Passing value in details simplifies the code for event-listeners.

Copy and paste is not getting rid of $ symbol that has been given in the snippet

Copy and paste is not getting rid of $ symbol that has been given in the snippet

Please look at the attachment to get the better understand of the issue I am talking about.
Actual : When I clicked on the copy button it copied the whole command including $ symbol
Expected : The $ symbol should be vomited when clicked on copy button

Screenshot 2021-04-21 at 2 22 21 PM

Feature Request - Not Copying the "$" or "#" in the beginning

Is there a way to copy element text content or input values to the clipboard, without the leading dollar sign "$" but still keep it displayed in the README preview?

For example, in README.md, copying the first command copies the "$" in the beginning, i.e. $ npm install --save @github/clipboard-copy-element. However, that can cause some issues:

$ $ npm install --save @github/clipboard-copy-element
-bash: $: command not found

One solution is to have the command not include the "$". But its inclusion is conventional for "run as non-root" as opposed to prepending the command with "#" which indicates running the command as root.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.