2018-10-02 16:48:27 -04:00
|
|
|
import React, { Component } from 'react';
|
2019-05-27 13:26:29 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-11 15:59:37 -04:00
|
|
|
|
|
|
|
import './tooltip.css';
|
2018-10-01 12:20:25 -04:00
|
|
|
import { InfoIcon } from './icons';
|
2018-09-11 15:59:37 -04:00
|
|
|
|
2019-08-09 13:49:43 -04:00
|
|
|
class Tooltip extends Component<any, any> { // TODO: add proper types
|
|
|
|
static propTypes = { // TODO: generate propTypes from TS
|
|
|
|
text: PropTypes.string
|
|
|
|
};
|
|
|
|
|
2018-10-01 11:59:39 -04:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
active: false
|
|
|
|
};
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
}
|
2018-09-11 15:59:37 -04:00
|
|
|
|
2018-10-01 11:59:39 -04:00
|
|
|
handleClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({
|
|
|
|
active: !this.state.active
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="tooltip-wrap">
|
2019-05-27 11:31:48 -04:00
|
|
|
<button className={(this.state.active? 'active ': '') + 'tooltip-hint icon-button'}
|
2019-05-27 11:39:16 -04:00
|
|
|
title={this.props.text}
|
|
|
|
onClick={this.handleClick}>
|
2018-10-25 06:48:25 -04:00
|
|
|
Hint
|
2018-10-01 12:20:25 -04:00
|
|
|
<InfoIcon />
|
2018-10-01 11:59:39 -04:00
|
|
|
</button>
|
|
|
|
{
|
|
|
|
this.state.active?
|
2019-05-27 11:39:16 -04:00
|
|
|
(
|
|
|
|
<div className="tooltip bs-tooltip-bottom">
|
|
|
|
<div className="arrow"></div>
|
|
|
|
<div className="tooltip-inner">{this.props.text}</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
: null
|
2018-10-01 11:59:39 -04:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-05-27 13:26:29 -04:00
|
|
|
|
2018-09-11 15:59:37 -04:00
|
|
|
export default Tooltip;
|