Socket
Socket
Sign inDemoInstall

react-clipboardjs-copy

Package Overview
Dependencies
10
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-clipboardjs-copy

clipboard.js copy component for react


Version published
Weekly downloads
34
decreased by-44.26%
Maintainers
1
Install size
239 kB
Created
Weekly downloads
 

Changelog

Source

2.0.2 (2024-04-07)

  • 添加examples
  • 调试迁移到vite

Readme

Source

react-clipboardjs-copy

build Download Version License

A react copy component that based on clipboard.js

中文

Installing

npm install --save react-clipboardjs-copy

Basic usage

import React from 'react';
import ReactClipboard from 'react-clipboardjs-copy';
import './App.css';
export default class App extends React.Component {
  render() {
    return (
      <div className="App">
        <section className="app-item">
          <div className="app-item-desc">Copy text</div>
          <ReactClipboard text="copy text" onSuccess={() => {}} onError={() => {}}>
            <button
              onClick={() => {
                console.log('click button');
              }}
            >
              Copy Text
            </button>
          </ReactClipboard>
        </section>
        <section className="app-item">
          <div className="app-item-desc">
            <textarea id="textarea">Mussum ipsum cacilds...</textarea>
            <div />
          </div>
          <ReactClipboard action="cut" target="#textarea" onSuccess={() => {}} onError={() => {}}>
            <button>Cut</button>
          </ReactClipboard>
        </section>
      </div>
    );
  }
}
<input id="input" value="git@github.com:freeshineit/react-clipboardjs-copy.git" />
<ReactClipboard
  target="#input"
  onSuccess={handleSuccess}
  onError={handleError}
>
  <button>
    Copy Input value
  </button>
</ReactClipboard>

Options(props)

PropertyDescriptionTypeDefault
actionOverwrites default command (cut or copy) , Corresponding to clipboard.js attribute data-clipboard-action.cut | copycopy
targetReact component will copy target element content. Corresponding to clipboard.js attribute data-clipboard-target.string | function(elem: Element): Element-
textReact component will copy content. Corresponding to clipboard.js attribute data-clipboard-textstring | function(elem: Element): string
containerFor use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value.Elementbody
selectionSetting whether to clear the copy or cut selectedbooleanfalse
onSuccessOperation success callbackfunction(event?: ClipboardJS.Event): void-
onErrorOperation error callbackfunction(event?: ClipboardJS.Event): void-

Developing

git clone git@github.com:freeshineit/react-clipboardjs-copy.git

cd react-clipboardjs-copy

pnpm install

## development
pnpm run dev

## test
pnpm run test

## production
pnpm run build

Reference material

clipboard.js

License

MIT © Shine Shao

Keywords

FAQs

Last updated on 06 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc