Commit e0bf89c3 authored by Amaury Martiny's avatar Amaury Martiny
Browse files

Fix feedback

parent 97e00974
Pipeline #44253 canceled with stages
......@@ -21,6 +21,10 @@ class ClickToCopy extends PureComponent {
copied: false
};
componentWillUnmount () {
window.clearTimeout(this.timeout);
}
handleCopy = () => {
// https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
// Note react-copy-to-clipboard created a bug, https://github.com/nkbt/react-copy-to-clipboard/issues/92
......@@ -32,29 +36,32 @@ class ClickToCopy extends PureComponent {
document.body.removeChild(el);
this.setState({ copied: true });
};
handleResetCopied = () => {
this.setState({ copied: false });
// Show the copied state only for 1s
if (this.timeout) {
window.clearTimeout(this.timeout);
}
this.timeout = window.setTimeout(
() => this.setState({ copied: false }),
1000
);
};
handleResetCopied = () => {};
render () {
const { children, label, ...otherProps } = this.props;
const { copied } = this.state;
return (
<div
data-tip={copied ? 'Copied.' : label}
key={copied ? 'copied' : 'not-copied'}
onClick={this.handleCopy}
>
<div data-tip='' onClick={this.handleCopy}>
{children}
<ReactTooltip
afterHide={this.handleResetCopied}
effect='solid'
event='mouseover'
eventOff='mouseout'
place='bottom'
getContent={[() => (copied ? 'Copied.' : label), 50]}
{...otherProps}
/>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment