npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-zeroclipboard

v4.0.1

Published

react component for zeroclipboard

Downloads

2,467

Readme

react-zeroclipboard

This is a wrapper around ZeroClipboard for use with React. ZeroClipboard has a difficult to work with api which is being abstracted from you. This library...

  • asynchronusly loads zeroclipboard from cdnjs
  • handles mounting/unmounting of components
  • figures out which element was clicked
  • allows you to declare text/html/rtf, or pass a function which returns it dynamically

Warning!

zero-clipboard uses flash which is being phased out across many browsers, and is sometimes buggy in the browsers that do support it. There have been reports of the plugin randomly not working, despite no significant changes to the plugin, and keeping the same zero-clipboard version.

If you're interested in solving this, your help is very much appreciated, and this section will be replaced with a big "thank you" for your work. Until then, using this plugin isn't recommended.

Install

This is only available through npm, it should work with browserify or webpack. It's compatible with react 0.13 and up.

npm install --save react-zeroclipboard

Or for react 0.11 and 0.12

npm install --save [email protected]

Also install react if you haven't already (of course).

Usage

Here's a simple example:

render: function(){
   return (
      <div>
         <p>Click the button to copy some text</p>
            <ReactZeroClipboard text="Hello, world!">
               <button>Copy</button>
            </ReactZeroClipboard>
      </div>
   )
}

The full api offers more flexibility. If you provide e.g. html and text, they'll both be set and the application you're pasting into decides which one to use. Methods have higher priority than the literal strings, if for some reason you pass both.

<ReactZeroClipboard 
   text="text to copy"
   html="<b>html to copy</b>"
   richText="{\\rtf1\\ansi\n{\\b rich text to copy}}"
   getText={(Void -> String)}
   getHtml={(Void -> String)}
   getRichText={(Void -> String)}

   onCopy={(Event -> Void)}
   onAfterCopy={(Event -> Void)}
   onErrorCopy={(Error -> Void)}

   onReady={(Event -> Void)}

   // optional
   swfPath="http://user_defined_cdn_path/ZeroClipboard.swf"
/>

Here's an example where we copy the current url to the clipboard, both in plain text and a html anchor

If the user pastes this in their address bar they get the url, and if they paste it in gmail they get a nice link.

render: function(){
   return (
      <div>
         <p>Copy a link to this page</p>
            <ReactZeroClipboard 
               getText={function(){ return location.href; }}
               getHtml={function(){ return '<a href="' + location.href + '">My Page</a>'; }}>
                  <button>Copy</button>
            </ReactZeroClipboard>
      </div>
   )
}

I'm getting weird ZeroClipboard errors

Usually this is caused by flash weirdness and/or cdnjs where we pull ZeroClipboard from. You can work around this by hosting ZeroClipboard and the swf yourself. Make sure the page and the two assets are either both http, or both https. There's a copy of the swf in the assets directory of this repo.

To access it with webpack, configure a loader for swf files:

{
  test: /\.swf$/g,
  loader: 'file-loader'
}

And then import the swf from this package.

<ReactZeroClipboard swfPath={ require('react-zeroclipboard/assets/ZeroClipboard.swf') }>