|
| 1 | +import * as React from 'react'; |
| 2 | +import ToolTip, { StatefulToolTip } from 'react-portal-tooltip'; |
| 3 | + |
| 4 | +// Tooltip test |
| 5 | + |
| 6 | +class ToolTipTest extends React.Component { |
| 7 | + state = { |
| 8 | + isTooltipActive: false, |
| 9 | + }; |
| 10 | + showTooltip() { |
| 11 | + this.setState({ isTooltipActive: true }); |
| 12 | + } |
| 13 | + hideTooltip() { |
| 14 | + this.setState({ isTooltipActive: false }); |
| 15 | + } |
| 16 | + render() { |
| 17 | + return ( |
| 18 | + <div> |
| 19 | + <p id="text" onMouseEnter={this.showTooltip.bind(this)} onMouseLeave={this.hideTooltip.bind(this)}> |
| 20 | + This is a cool component |
| 21 | + </p> |
| 22 | + <ToolTip active={this.state.isTooltipActive} position="top" arrow="center" parent="#text"> |
| 23 | + <div> |
| 24 | + <p>This is the content of the tooltip</p> |
| 25 | + <img src="image.png" /> |
| 26 | + </div> |
| 27 | + </ToolTip> |
| 28 | + </div> |
| 29 | + ); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +// Parent props |
| 34 | + |
| 35 | +class ToolTipTestParentProp1 extends React.Component { |
| 36 | + state = { |
| 37 | + isTooltipActive: false, |
| 38 | + }; |
| 39 | + showTooltip() { |
| 40 | + this.setState({ isTooltipActive: true }); |
| 41 | + } |
| 42 | + hideTooltip() { |
| 43 | + this.setState({ isTooltipActive: false }); |
| 44 | + } |
| 45 | + render() { |
| 46 | + return ( |
| 47 | + <div> |
| 48 | + <div id="hoverMe" onMouseEnter={this.showTooltip} onMouseLeave={this.hideTooltip}> |
| 49 | + Hover me!!! |
| 50 | + </div> |
| 51 | + <ToolTip active={this.state.isTooltipActive} position="top" arrow="center" parent="#hoverMe"> |
| 52 | + <div> |
| 53 | + <p>This is the content of the tooltip</p> |
| 54 | + </div> |
| 55 | + </ToolTip> |
| 56 | + </div> |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +class ToolTipTestParentProp2 extends React.Component { |
| 62 | + readonly element = React.createRef<HTMLDivElement>(); |
| 63 | + |
| 64 | + constructor(props: {}) { |
| 65 | + super(props); |
| 66 | + } |
| 67 | + state = { |
| 68 | + isTooltipActive: false, |
| 69 | + }; |
| 70 | + showTooltip() { |
| 71 | + this.setState({ isTooltipActive: true }); |
| 72 | + } |
| 73 | + hideTooltip() { |
| 74 | + this.setState({ isTooltipActive: false }); |
| 75 | + } |
| 76 | + render() { |
| 77 | + return ( |
| 78 | + <div> |
| 79 | + <div ref={this.element} onMouseEnter={this.showTooltip} onMouseLeave={this.hideTooltip}> |
| 80 | + Hover me!!! |
| 81 | + </div> |
| 82 | + <ToolTip active={this.state.isTooltipActive} position="top" arrow="center" parent={this.element}> |
| 83 | + <div> |
| 84 | + <p>This is the content of the tooltip</p> |
| 85 | + </div> |
| 86 | + </ToolTip> |
| 87 | + </div> |
| 88 | + ); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +// StatefulToolTip test |
| 93 | + |
| 94 | +const StatefulToolTipTest = () => { |
| 95 | + const button = <span>Hover me to display the tooltip</span>; |
| 96 | + |
| 97 | + return <StatefulToolTip parent={button}>Stateful Tooltip content here!</StatefulToolTip>; |
| 98 | +}; |
0 commit comments