2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
2017-01-21 22:31:41 +01:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
export class ToolTip extends React.PureComponent {
|
2017-05-17 10:10:25 +02:00
|
|
|
static propTypes = {
|
2017-01-21 22:31:41 +01:00
|
|
|
body: React.PropTypes.string.isRequired,
|
2017-06-06 23:19:12 +02:00
|
|
|
label: React.PropTypes.string.isRequired,
|
|
|
|
};
|
2017-05-17 10:10:25 +02:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-01-21 22:31:41 +01:00
|
|
|
showTooltip: false,
|
|
|
|
};
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleClick() {
|
2017-01-21 22:31:41 +01:00
|
|
|
this.setState({
|
|
|
|
showTooltip: !this.state.showTooltip,
|
|
|
|
});
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTooltipMouseOut() {
|
2017-01-21 22:31:41 +01:00
|
|
|
this.setState({
|
|
|
|
showTooltip: false,
|
|
|
|
});
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-01-21 22:31:41 +01:00
|
|
|
return (
|
2017-06-06 23:19:12 +02:00
|
|
|
<span className={"tooltip " + (this.props.className || "")}>
|
|
|
|
<a
|
|
|
|
className="tooltip__link"
|
|
|
|
onClick={() => {
|
|
|
|
this.handleClick();
|
|
|
|
}}
|
|
|
|
>
|
2017-01-21 22:31:41 +01:00
|
|
|
{this.props.label}
|
|
|
|
</a>
|
2017-06-06 23:19:12 +02:00
|
|
|
<div
|
|
|
|
className={
|
|
|
|
"tooltip__body " + (this.state.showTooltip ? "" : " hidden")
|
|
|
|
}
|
|
|
|
onMouseOut={() => {
|
|
|
|
this.handleTooltipMouseOut();
|
|
|
|
}}
|
|
|
|
>
|
2017-01-21 22:31:41 +01:00
|
|
|
{this.props.body}
|
|
|
|
</div>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
2017-05-09 00:22:27 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default ToolTip;
|