-
Notifications
You must be signed in to change notification settings - Fork 4
/
ToolTip.tsx
56 lines (50 loc) · 1.2 KB
/
ToolTip.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as React from "react";
export interface ToolTipState {
show: boolean;
}
export interface ToolTipProps {
trigger: JSX.Element;
text: string;
direction?: string;
}
/**
* Displays a tooltip helper displaying additional information.
*/
export default class ToolTip extends React.Component<
ToolTipProps,
ToolTipState
> {
constructor(props) {
super(props);
this.state = {
show: false,
};
this.showToolTip = this.showToolTip.bind(this);
this.hideToolTip = this.hideToolTip.bind(this);
}
render(): JSX.Element {
return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<div
className="tool-tip-container"
onMouseEnter={this.showToolTip}
onMouseLeave={this.hideToolTip}
role="tooltip"
>
{this.props.trigger}
<span
className={`tool-tip ${this.state.show ? "" : "hide"} ${
this.props.direction ? this.props.direction : ""
}`}
dangerouslySetInnerHTML={{ __html: this.props.text }}
></span>
</div>
);
}
showToolTip() {
this.setState({ show: true });
}
hideToolTip() {
this.setState({ show: false });
}
}