Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-clipboard.js
Advanced tools
Readme
React wrapper for clipboard.js
$ npm i --save react-clipboard.js
You can use clipboard.js
original data-*
attributes:
import ReactDOM from 'react-dom';
import React, { Component } from 'react';
import Clipboard from 'react-clipboard.js';
class MyView extends Component {
render() {
return (
<Clipboard data-clipboard-text="I'll be copied">
copy to clipboard
</Clipboard>
);
}
}
ReactDOM.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 ReactDOM from 'react-dom';
import React, { Component } from 'react';
import Clipboard 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 copied');
}
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 (
<Clipboard option-text={this.getText} onSuccess={this.onSuccess}>
copy to clipboard
</Clipboard>
);
}
}
ReactDOM.render(<MyView/>, document.getElementById('app'));
Custom HTML tags may be used as well (you can use custom components as well): Beware: Stateless/Functional components are yet to be added
import ReactDOM from 'react-dom';
import React, { Component } from 'react';
import Clipboard 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>
);
}
}
ReactDOM.render(<MyView/>, document.getElementById('app'));
Default html properties may be passed with the button-*
pattern:
import ReactDOM from 'react-dom';
import React, { Component } from 'react';
import Clipboard from 'react-clipboard.js';
class MyView extends Component {
render() {
return (
<Clipboard data-clipboard-text="I'll be copied" button-title="I'm a tooltip">
copy to clipboard
</Clipboard>
);
}
}
ReactDOM.render(<MyView/>, document.getElementById('react-body'));
This code is released under CC0 (Public Domain)
FAQs
Clipboard.js wrapper for ReactJS
The npm package react-clipboard.js receives a total of 28,715 weekly downloads. As such, react-clipboard.js popularity was classified as popular.
We found that react-clipboard.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.