| 1 |
|
| 2 |
import React, { Component } from 'react'; |
| 3 |
import CopyToClipboard from 'react-copy-to-clipboard'; |
| 4 |
|
| 5 |
import Icon from 'Shared/Icon'; |
| 6 |
import Tooltip from 'Shared/Tooltip'; |
| 7 |
import { __wpupg } from 'Shared/Translations'; |
| 8 |
|
| 9 |
import '../../css/admin/shared/copy-clipboard.scss'; |
| 10 |
|
| 11 |
export default class CopyToClipboardIcon extends Component { |
| 12 |
constructor(props) { |
| 13 |
super(props); |
| 14 |
|
| 15 |
this.state = { |
| 16 |
copied: false, |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
onCopy() { |
| 21 |
this.setState({ |
| 22 |
copied: true, |
| 23 |
}, () => { |
| 24 |
setTimeout(() => { |
| 25 |
this.setState({ |
| 26 |
copied: false, |
| 27 |
}); |
| 28 |
}, 2000); |
| 29 |
}); |
| 30 |
} |
| 31 |
|
| 32 |
render() { |
| 33 |
return ( |
| 34 |
<CopyToClipboard |
| 35 |
text={this.props.text} |
| 36 |
onCopy={this.onCopy.bind(this)} |
| 37 |
> |
| 38 |
<span |
| 39 |
className="wpupg-admin-table-container-copy" |
| 40 |
style={{ |
| 41 |
opacity: this.state.copied ? 0.2 : 1 |
| 42 |
}} |
| 43 |
> |
| 44 |
{ |
| 45 |
this.props.hasOwnProperty( 'type' ) |
| 46 |
&& 'text' === this.props.type |
| 47 |
? |
| 48 |
<Tooltip content={ this.state.copied ? __wpupg( 'Copied!' ) : __wpupg( 'Copy to clipboard' ) }> |
| 49 |
<span>{ this.props.text }</span> |
| 50 |
</Tooltip> |
| 51 |
: |
| 52 |
<Icon |
| 53 |
type="clipboard" |
| 54 |
title={ this.state.copied ? __wpupg( 'Copied!' ) : __wpupg( 'Copy to clipboard' ) } |
| 55 |
/> |
| 56 |
} |
| 57 |
</span> |
| 58 |
</CopyToClipboard> |
| 59 |
); |
| 60 |
} |
| 61 |
} |