1 import React
, { Component
} from 'react';
2 import Clipboard
from 'clipboard';
3 import './CopyOnClick.css';
5 class CopyOnClick
extends Component
{
11 const { target
} = this.props
;
13 this.clipboard
= new Clipboard(this.button
, {
14 target
: () => document
.querySelector(target
)
18 componentWillUnmount() {
19 this.clipboard
.destroy();
23 this.setState({ active
: true });
24 setTimeout(this.hideTooltip
, 1000);
28 this.setState({ active
: false });
32 const { children
} = this.props
;
33 let notification
= '';
35 if (this.state
.active
) {
36 notification
= <span className
='CopyOnClick-notification'>Copied
!</span
>;
40 <div ref
={(element
) => this.button
= element
} onClick
={this.showTooltip
}>
48 export default CopyOnClick
;