Skip to content

Commit 70f5979

Browse files
committed
16-hover
1 parent a07f721 commit 70f5979

File tree

3 files changed

+41
-48
lines changed

3 files changed

+41
-48
lines changed

app/components/Hover.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

app/components/Tooltip.jsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import * as React from "react";
22
import PropTypes from "prop-types";
3-
import withHover from "./withHover";
3+
import Hover from "./Hover";
44

55
const container = {
66
position: "relative",
77
display: "flex",
88
};
99

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+
);
2123
}
2224

2325
Tooltip.propTypes = {
2426
children: PropTypes.node.isRequired,
2527
element: PropTypes.node.isRequired,
2628
};
27-
28-
export default withHover(Tooltip);

app/components/withHover.jsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)