Skip to content

Commit 3f0d76d

Browse files
committed
14-tooltip
1 parent e818250 commit 3f0d76d

File tree

3 files changed

+124
-12
lines changed

3 files changed

+124
-12
lines changed

app/components/Table.jsx

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
import * as React from "react";
22
import PropTypes from "prop-types";
33
import { hashtag } from "./icons";
4+
import Tooltip from "./Tooltip";
5+
6+
function MoreInfo({
7+
created_at,
8+
forked_count,
9+
language,
10+
updated_at,
11+
watchers,
12+
login,
13+
}) {
14+
return (
15+
<ul className="tooltip stack">
16+
<li className="split">
17+
<span>By:</span> <span>{login}</span>
18+
</li>
19+
{language && (
20+
<li className="split">
21+
<span>Language:</span> <span>{language}</span>
22+
</li>
23+
)}
24+
<li className="split">
25+
<span>Created:</span>{" "}
26+
<span>{new Date(created_at).toLocaleDateString()}</span>
27+
</li>
28+
<li className="split">
29+
<span>Updated:</span>{" "}
30+
<span>{new Date(updated_at).toLocaleDateString()}</span>
31+
</li>
32+
<li className="split">
33+
<span>Watchers:</span>
34+
<span>{watchers.toLocaleString()}</span>
35+
</li>
36+
{forked_count && (
37+
<li className="split">
38+
<span>Forked:</span> <span>{forked_count.toLocaleString()}</span>
39+
</li>
40+
)}
41+
</ul>
42+
);
43+
}
44+
45+
MoreInfo.propTypes = {
46+
created_at: PropTypes.string.isRequired,
47+
language: PropTypes.string,
48+
updated_at: PropTypes.string.isRequired,
49+
watchers: PropTypes.number.isRequired,
50+
type: PropTypes.string.isRequired,
51+
login: PropTypes.string.isRequired,
52+
};
453

554
function TableHead() {
655
return (
@@ -23,23 +72,40 @@ function TableRow({
2372
forks,
2473
open_issues,
2574
name,
75+
created_at,
76+
updated_at,
77+
language,
78+
watchers,
2679
}) {
27-
const { login, avatar_url } = owner;
80+
const { login, avatar_url, type } = owner;
2881

2982
return (
3083
<tr>
3184
<td>{index + 1}</td>
3285
<td>
33-
<div className="row gap-md">
34-
<img
35-
width={32}
36-
height={32}
37-
className="avatar"
38-
src={avatar_url}
39-
alt={`Avatar for ${login}`}
40-
/>
41-
<a href={`https://github.com/${login}/${name}`}>{name}</a>
42-
</div>
86+
<Tooltip
87+
element={
88+
<MoreInfo
89+
created_at={created_at}
90+
language={language}
91+
updated_at={updated_at}
92+
watchers={watchers}
93+
type={type}
94+
login={login}
95+
/>
96+
}
97+
>
98+
<div className="row gap-md">
99+
<img
100+
width={32}
101+
height={32}
102+
className="avatar"
103+
src={avatar_url}
104+
alt={`Avatar for ${login}`}
105+
/>
106+
<a href={`https://github.com/${login}/${name}`}>{name}</a>
107+
</div>
108+
</Tooltip>
43109
</td>
44110
<td>{stargazers_count}</td>
45111
<td>{forks}</td>

app/components/Tooltip.jsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as React from "react";
2+
import PropTypes from "prop-types";
3+
4+
const container = {
5+
position: "relative",
6+
display: "flex",
7+
};
8+
9+
export default class Tooltip extends React.Component {
10+
constructor(props) {
11+
super(props);
12+
13+
this.state = {
14+
hovering: false,
15+
};
16+
17+
this.mouseOver = this.mouseOver.bind(this);
18+
this.mouseOut = this.mouseOut.bind(this);
19+
}
20+
mouseOver() {
21+
this.setState({ hovering: true });
22+
}
23+
mouseOut() {
24+
this.setState({ hovering: false });
25+
}
26+
render() {
27+
const { hovering } = this.state;
28+
const { children, element } = this.props;
29+
30+
return (
31+
<div
32+
onMouseOver={this.mouseOver}
33+
onMouseOut={this.mouseOut}
34+
style={container}
35+
>
36+
{hovering === true && element}
37+
{children}
38+
</div>
39+
);
40+
}
41+
}
42+
43+
Tooltip.propTypes = {
44+
children: PropTypes.node.isRequired,
45+
element: PropTypes.node.isRequired,
46+
};

app/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class App extends React.Component {
99
return (
1010
<div className="light">
1111
<div className="container">
12-
<Battle />
12+
<Popular />
1313
</div>
1414
</div>
1515
);

0 commit comments

Comments
 (0)