File tree Expand file tree Collapse file tree 3 files changed +41
-48
lines changed Expand file tree Collapse file tree 3 files changed +41
-48
lines changed Original file line number Diff line number Diff line change
1
+ import * as React from "react" ;
2
+
3
+ export default class Hover extends React . Component {
4
+ constructor ( props ) {
5
+ super ( props ) ;
6
+
7
+ this . state = {
8
+ hovering : false ,
9
+ } ;
10
+
11
+ this . mouseOver = this . mouseOver . bind ( this ) ;
12
+ this . mouseOut = this . mouseOut . bind ( this ) ;
13
+ }
14
+ mouseOver ( ) {
15
+ this . setState ( { hovering : true } ) ;
16
+ }
17
+ mouseOut ( ) {
18
+ this . setState ( { hovering : false } ) ;
19
+ }
20
+ render ( ) {
21
+ return (
22
+ < div onMouseOver = { this . mouseOver } onMouseOut = { this . mouseOut } >
23
+ { this . props . children ( this . state . hovering ) }
24
+ </ div >
25
+ ) ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change 1
1
import * as React from "react" ;
2
2
import PropTypes from "prop-types" ;
3
- import withHover from "./withHover " ;
3
+ import Hover from "./Hover " ;
4
4
5
5
const container = {
6
6
position : "relative" ,
7
7
display : "flex" ,
8
8
} ;
9
9
10
- class Tooltip extends React . Component {
11
- render ( ) {
12
- const { children, element, hovering } = this . props ;
13
-
14
- return (
15
- < div style = { container } >
16
- { hovering === true && element }
17
- { children }
18
- </ div >
19
- ) ;
20
- }
10
+ export default function Tooltip ( { children, element } ) {
11
+ return (
12
+ < Hover >
13
+ { ( hovering ) => {
14
+ return (
15
+ < div style = { container } >
16
+ { hovering === true && element }
17
+ { children }
18
+ </ div >
19
+ ) ;
20
+ } }
21
+ </ Hover >
22
+ ) ;
21
23
}
22
24
23
25
Tooltip . propTypes = {
24
26
children : PropTypes . node . isRequired ,
25
27
element : PropTypes . node . isRequired ,
26
28
} ;
27
-
28
- export default withHover ( Tooltip ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments