mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 10:03:07 +08:00
31 lines
785 B
JavaScript
31 lines
785 B
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import Clipboard from 'clipboard';
|
|
import hoistStatics from 'recompose/hoistStatics';
|
|
|
|
export default hoistStatics((WrappedComponent) => {
|
|
class WithCopyToClipboard extends React.Component {
|
|
componentDidMount() {
|
|
const clipboard = new Clipboard(ReactDOM.findDOMNode(this));
|
|
|
|
clipboard.on('success', (e) => {
|
|
e.clearSelection();
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const {copyTarget = '', copyText = '', className = '', ...rest} = this.props;
|
|
|
|
return <WrappedComponent
|
|
className={className}
|
|
data-clipboard-action="copy"
|
|
data-clipboard-text={copyText}
|
|
data-clipboard-target={copyTarget}
|
|
{...rest}
|
|
/>;
|
|
}
|
|
}
|
|
|
|
return WithCopyToClipboard;
|
|
});
|