-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.js
More file actions
58 lines (50 loc) · 1.11 KB
/
Copy pathHeader.js
File metadata and controls
58 lines (50 loc) · 1.11 KB
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
57
58
import PropTypes from 'prop-types';
import Link from 'next/link';
import { githubUser, githubRepo } from '../config';
function HeaderLink(props) {
const { link } = props;
let { title } = props;
// Remove file extension
title = title.replace(/\.[^/.]+$/, '');
return (
<li className="col-sm-2 col-lg-12">
<Link href={`/${link}`}>
<a>{title}</a>
</Link>
</li>
);
}
HeaderLink.propTypes = {
title: PropTypes.string.isRequired,
link: PropTypes.string.isRequired,
};
function Header(props) {
const { paths } = props;
let pathElement = null;
if (paths && Array.isArray(paths)) {
pathElement = paths.map(
(path) => <HeaderLink key={path} title={path} link={path} />,
);
} else {
pathElement = String(paths);
}
return (
<div>
<h1><strong>{githubRepo}</strong></h1>
<h2>
by
{' '}
{githubUser}
</h2>
<nav>
<ul className="row">
{pathElement}
</ul>
</nav>
</div>
);
}
Header.propTypes = {
paths: PropTypes.arrayOf(PropTypes.string).isRequired,
};
export default Header;