Giter Site home page Giter Site logo

zlatanpham / copy-to-clipboard-react Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 218 KB

React component helps ease the work of copying to clipboard using render prop.

HTML 9.11% JavaScript 52.60% CSS 1.24% TypeScript 37.05%
react clipboard-copy render-props react-hooks

copy-to-clipboard-react's Introduction

copy-to-clipboard-react

React component helps ease the work of copying to clipboard using render prop.

JavaScript Style Guide

Install

npm install --save @uxui/copy-to-clipboard-react

Render Prop Usage

It uses render prop, you render whatever you want to based on the state of CopyToClipboard.

import * as React from 'react';
import CopyToClipboard from 'copy-to-clipboard-react';

class CopyToClipboard extends React.Component {
  render() {
    return (
      <CopyToClipboard>
        {({ copied, copy, turnOffCopied }) => (
          // JSX goes here
        )}
      </CopyToClipboard>
    );
  }
}

Live demo can be found here.

Children Function

  • copy: (content: string) => void: copy any thing passed to param content to clipboard.
  • copied: boolean: a state will get truthy after copy() gets called.
  • turnOffCopied: () => void: simply set copied to false.

Props

  • callback: (content?: string) => void: callback after copy() get called.

Hook Usage

Hook is supported as React 16.8.x came out.

import React from 'react';
import './App.css';

import { useCopyToClipboard } from '@uxui/copy-to-clipboard-react';

const YourFunctionalComponent = () => {
  const { copied, copy, turnOffCopied } = useCopyToClipboard();

  return (
    // JSX goes here
  );
};

License

MIT © zlatanpham

copy-to-clipboard-react's People

Contributors

zlatanpham avatar

Watchers

 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.