Initial commit
[elation-signature-composer.git] / src / components / CopyOnClick / CopyOnClick.js
blob66464adc5aefa7611d5a9cded39dac2fc4050fae
1 import React, { Component } from 'react';
2 import Clipboard from 'clipboard';
3 import './CopyOnClick.css';
5 class CopyOnClick extends Component {
6 state = {
7 active: false
10 componentDidMount() {
11 const { target } = this.props;
13 this.clipboard = new Clipboard(this.button, {
14 target: () => document.querySelector(target)
15 });
18 componentWillUnmount() {
19 this.clipboard.destroy();
22 showTooltip = () => {
23 this.setState({ active: true });
24 setTimeout(this.hideTooltip, 1000);
27 hideTooltip = () => {
28 this.setState({ active: false });
31 render() {
32 const { children } = this.props;
33 let notification = '';
35 if (this.state.active) {
36 notification = <span className='CopyOnClick-notification'>Copied!</span>;
39 return (
40 <div ref={(element) => this.button = element} onClick={this.showTooltip}>
41 {children}
42 {notification}
43 </div>
48 export default CopyOnClick;