mirror of
https://github.com/wassname/talk.git
synced 2026-07-04 11:04:47 +08:00
38 lines
851 B
JavaScript
38 lines
851 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;
|
|
});
|