Giter Site home page Giter Site logo

annuhdo / react-clipboard.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nihey/react-clipboard.js

1.0 2.0 0.0 74 KB

React wrapper for clipboard.js (flashless clipboard)

Home Page: https://www.npmjs.com/package/react-clipboard.js

JavaScript 100.00%

react-clipboard.js's Introduction

React-Clipboard

React wrapper for clipboard.js

Build Status Dependency Status

Installation

$ npm i --save react-clipboard.js

Usage

You can use clipboard.js original data-* attributes:

import React, { Component } from 'react';
import ClipboardButton from 'react-clipboard.js';

class MyView extends Component {
  render() {
    return (
      <ClipboardButton data-clipboard-text="I'll be copied">
        copy to clipboard
      </ClipboardButton>
    );
  }
}

React.render(<MyView/>, document.getElementById('app'));
  • If you want to provide any constructor option as in new Clipboard('#id', options), you may use option-* attributes

  • callbacks will be connected via on* attributes (such as onSuccess)

import React, { Component } from 'react';
import ClipboardButton from 'react-clipboard.js';

class MyView extends Component {
  constructor() {
    super();

    this.onSuccess = this.onSuccess.bind(this);
    this.getText = this.getText.bind(this);
  }

  onSuccess() {
    console.info('successfully coppied');
  }

  getText() {
    return 'I\'ll be copied';
  }

  render() {
    // Providing option-text as this.getText works the same way as providing:
    //
    // var clipboard = new Clipboard('#anything', {
    //   text: this.getText,
    // });
    //
    // onSuccess works as a 'success' callback:
    //
    // clipboard.on('success', this.onSuccess);
    return (
      <ClipboardButton option-text={this.getText} onSuccess={this.onSuccess}>
        copy to clipboard
      </ClipboardButton>
    );
  }
}

React.render(<MyView/>, document.getElementById('app'));

Custom HTML tags may be used as well:

import React, { Component } from 'react';
import ClipboardButton from 'react-clipboard.js';

class MyView extends Component {
  render() {
    // Clipboard is now rendered as an '<a>'
    return (
      <Clipboard component="a" button-href="#" data-clipboard-text="I'll be copied">
        copy to clipboard
      </Clipboard>
    );
  }
}

Default html properties may be passed with the button-* pattern:

import React, { Component } from 'react';
import ClipboardButton from 'react-clipboard.js';

class MyView extends Component {
  render() {
    return (
      <ClipboardButton data-clipboard-text="I'll be copied" button-title="I'm a tooltip">
        copy to clipboard
      </ClipboardButton>
    );
  }
}

React.render(<MyView/>, document.getElementById('react-body'));

License

This code is released under CC0 (Public Domain)

react-clipboard.js's People

Contributors

bondz avatar hashwin avatar kmalakoff avatar marcinlichwala-tomtom avatar nene avatar nihey avatar ppvg avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.