add tooltip on copy when there is no onCopy prop

This commit is contained in:
Jonathan Rainville 2018-10-19 11:16:25 -04:00 committed by Pascal Precht
parent ab77cc012e
commit e660eaea72
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
3 changed files with 46 additions and 19 deletions

View File

@ -2,7 +2,6 @@ import PropTypes from "prop-types";
import React from 'react';
import ReactJson from "react-json-view";
import {Row, Col, Table} from "reactstrap";
import GasStationContainer from "../containers/GasStationContainer";
import {formatContractForDisplay} from '../utils/presentation';
import CopyButton from './CopyButton';

View File

@ -1,19 +1,51 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Badge} from "reactstrap";
import {Badge, Tooltip} from "reactstrap";
import classNames from 'classnames';
import {CopyToClipboard} from 'react-copy-to-clipboard';
import uuid from 'uuid/v1';
import './CopyButton.css';
const CopyButton = ({text, onCopy, title, size}) => (
<CopyToClipboard text={text}
onCopy={onCopy}
class CopyButton extends React.Component {
constructor(props) {
super(props);
this.id = uuid();
this.state = {
showCopied: false
};
}
onCopy() {
if (this.props.onCopy) {
return this.props.onCopy();
}
this.setState({
showCopied: true
});
// Hide the tooltip after a few seconds
clearTimeout(this.showTimeout);
this.showTimeout = setTimeout(() => {
this.setState({showCopied: false});
}, 1500);
}
render() {
const {text, title, size} = this.props;
return (<CopyToClipboard text={text}
onCopy={() => this.onCopy()}
title={title}>
<Badge className={classNames('copy-to-clipboard', 'p-' + (size ? size : 3))}
color="primary"><i className="fa fa-copy"/></Badge>
</CopyToClipboard>
);
color="primary" id={'copy-button-' + this.id}>
<i className="fa fa-copy"/>
{this.state.showCopied &&
<Tooltip isOpen={true} target={'copy-button-' + this.id}>
Copied to clipboard
</Tooltip>}
</Badge>
</CopyToClipboard>);
}
}
CopyButton.propTypes = {
text: PropTypes.oneOfType([

View File

@ -4,15 +4,11 @@ import autoscroll from 'autoscroll-react';
import "./Logs.css";
class Logs extends React.Component {
render() {
return (
<div className="logs" {...this.props}>
{this.props.children}
const Logs = (props) => (
<div className="logs" {...props}>
{props.children}
</div>
);
}
}
);
Logs.propTypes = {
children: PropTypes.object