Giter Site home page Giter Site logo

jotform / react-zeroclipboard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brigand/react-zeroclipboard

0.0 27.0 1.0 1001 KB

react component that abstracts zeroclipboard

Home Page: brigand.github.io/react-zeroclipboard

JavaScript 71.87% HTML 28.13%

react-zeroclipboard's Introduction

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

Install

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

npm install --save react-zeroclipboard@1

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

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

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.