lbry.tech/app/components/navigation.js

77 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-08-29 01:57:18 +02:00
"use strict";
2018-11-30 21:46:22 +01:00
// I M P O R T
2018-08-29 01:57:18 +02:00
import html from "choo/html";
// E X P O R T
2018-10-03 23:13:31 +02:00
export default currentUrl => {
const links = [
{
name: "LBRY.io",
title: "Escape the techno scene",
url: process.env.NODE_ENV === "development" ? "http://localhost:8000" : "https://lbry.io"
2018-10-03 23:13:31 +02:00
},
{
name: "Overview",
title: "LBRY overview",
url: "/overview"
},
{
name: "Playground",
title: "Experience LBRY",
url: "/playground"
},
{
name: "Resources",
title: "View LBRY resources",
2019-01-29 17:16:14 +01:00
url: "/resources"
2018-10-03 23:13:31 +02:00
},
{
name: "Community",
title: "Interact with LBRY",
url: "/community"
}
];
2018-08-29 01:57:18 +02:00
2018-10-03 23:13:31 +02:00
return html`
<nav class="navigation">
2019-01-29 17:16:14 +01:00
<div class="inner-wrap">
<a class="navigation__item logo" href="/" title="LBRY homepage">Home</a>
2018-10-03 23:13:31 +02:00
${links.map(link => renderLink(currentUrl, link))}
2019-01-29 17:16:14 +01:00
</div>
2018-10-03 23:13:31 +02:00
</nav>
`;
};
2018-08-29 01:57:18 +02:00
2018-10-03 23:13:31 +02:00
// H E L P E R
function renderLink(href, link) {
let activeClass;
switch(true) {
case (link.url !== "/" && href.indexOf(link.url) >= 0):
2018-08-29 01:57:18 +02:00
activeClass = true;
2018-10-03 23:13:31 +02:00
break;
2018-08-29 01:57:18 +02:00
2018-10-03 23:13:31 +02:00
default:
activeClass = false;
break;
2018-08-29 01:57:18 +02:00
}
2018-10-03 23:13:31 +02:00
2019-01-29 17:16:14 +01:00
return html`
<a
class="navigation__item${activeClass ? " active" : ""}"
href="${link.url}"
title="${link.title}"
>${link.name}</a>
`;
2018-08-29 01:57:18 +02:00
}