1.0.0 • Published 5 years ago

clipboard-react v1.0.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
5 years ago

clipboard-react

A lightweight react component for copying text to clipboard, inspired by clipboard.js.

Install

npm install clipboard-react

Usage

import Copy from 'clipboard-react'

<Copy text="hello world" onSuccess={() => alert('Copied')} onError={reason => alert('Failed')}>Copy</Copy>

Exec copy action when user click 'Copy'.

APIs

Copy component

import Copy from 'clipboard-react'

<Copy text="hello world">Copy</Copy>

The component props:

NameTypeDefaultDesc
textstringThe content will be copied
onSuccessFunctionThe callback when copy successfully
onErrorFunctionThe callback when copy failed
sniffbooltruetrue: do not display when the document.queryCommandSupported('copy') command is supported by the browser
OtherwiseThe otherwise props will added to React element

copy method

Copy imperatively.

import { copy } from 'clipboard-react'

async function doCopy() {
    await copy('hello');
    console.log('Copy successfully');
}

copySync method

import { copySync } from 'clipboard-react'

const successed = copySync('hello');

supported method

Check whether or not the document.queryCommandSupported('copy') command is supported by the browser.

import { supported } from 'clipboard-react'

const isSupported = supported();
1.0.0

5 years ago