Coder Social home page Coder Social logo

bogas04 / react-c2c Goto Github PK

View Code? Open in Web Editor NEW

This project forked from solodynamo/react-c2c

0.0 1.0 0.0 249 KB

Performant , lightweight and dependency free react copy 2 clipboard component.

Home Page: https://solodynamo.github.io/react-c2c/

License: MIT License

HTML 14.15% JavaScript 85.85%

react-c2c's Introduction


react-c2c


Performant and lightweight copy 2 clipboard component for react applications.

Featured in:

Highlights

  • Can be easily integrated.
  • Just ~ 1.4kb.
  • No dependencies.
  • Configurable for debugging(through logs).

Comparison

react-copy-to-clipboard is very nice but

Installation

npm install --save react-c2c
yarn add react-c2c

Demo

https://solodynamo.github.io/react-c2c/

https://codesandbox.io/s/j314vk3r73

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import {C2C} from 'react-c2c';

class App extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            value: '',
            copied: false,
        }
    }

    render() {
        return (
          <div>
            <input value={this.state.value}
              onChange={({target: {value}}) => this.setState({value, copied: false})} />

            <C2C text={this.state.value}
              onCopy={() => this.setState({copied: true})}>
              <button>Copy to clipboard with button</button>
            </C2C>

            {this.state.copied ? <span style={{color: 'blue'}}>Copied !</span> : null}
          </div>
        );
    }
}

const container = document.createElement('div');
document.body.appendChild(container);
ReactDOM.render(<App />, container);

props

text: PropTypes.string.isRequired

Text to be copied to clipboard.

onCopy: PropTypes.func

Optional callback, will be called when text is copied.

onCopy(text, result)

result (boolean): Returns true if copied successfully, else false.

options: PropTypes.shape({debug: bool})

Flag that enables logs for debugging.

children: PropTypes.node.isRequired

C2C is a simple wrapping component, so it requires a single child element to be present, which will be used to capture clicks.

<C2C text="Hi! ๐ŸŒŸ me">
  <button>Copy 2 Clipboard</button>
</C2C>

Support react-c2c

react-c2c is completely free and open-source. If you find it useful, you can show your support by ๐ŸŒŸ it or sharing it in your social network.

Contribute

Please do ๐Ÿ™‚

License

MIT ยฉ Solodynamo

react-c2c's People

Contributors

solodynamo avatar

Watchers

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