| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 6 4 4 3 5 | import React from 'react';
import copy from 'copy-to-clipboard';
const CopyToClipboard = React.createClass({
propTypes: {
text: React.PropTypes.string.isRequired,
children: React.PropTypes.node.isRequired,
onCopy: React.PropTypes.func
},
onClick() {
copy(this.props.text);
if (this.props.onCopy) {
this.props.onCopy(this.props.text);
}
},
render() {
return React.cloneElement(React.Children.only(this.props.children), {onClick: this.onClick});
}
});
export default CopyToClipboard;
|