lbry.tech/app/components/navigation.js

77 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-08-28 18:57:18 -05:00
"use strict";
2018-11-30 14:46:22 -06:00
// I M P O R T
2018-08-28 18:57:18 -05:00
import html from "choo/html";
// E X P O R T
2018-10-03 16:13:31 -05:00
export default currentUrl => {
const links = [
{
2019-04-11 15:41:07 -04:00
name: "LBRY.com",
2018-10-03 16:13:31 -05:00
title: "Escape the techno scene",
2019-03-19 17:56:32 -05:00
url: process.env.NODE_ENV === "development" ? "http://localhost:8000" : "https://lbry.com"
2018-10-03 16:13:31 -05:00
},
{
name: "Overview",
title: "LBRY overview",
url: "/overview"
},
{
name: "Playground",
title: "Experience LBRY",
url: "/playground"
},
{
name: "Resources",
title: "View LBRY resources",
2019-01-29 11:16:14 -05:00
url: "/resources"
2018-10-03 16:13:31 -05:00
},
{
name: "Community",
title: "Interact with LBRY",
url: "/community"
}
];
2018-08-28 18:57:18 -05:00
2018-10-03 16:13:31 -05:00
return html`
<nav class="navigation">
2019-01-29 11:16:14 -05:00
<div class="inner-wrap">
<a class="navigation__item logo" href="/" title="LBRY homepage">Home</a>
2018-10-03 16:13:31 -05:00
${links.map(link => renderLink(currentUrl, link))}
2019-01-29 11:16:14 -05:00
</div>
2018-10-03 16:13:31 -05:00
</nav>
`;
};
2018-08-28 18:57:18 -05:00
2018-10-03 16:13:31 -05: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-28 18:57:18 -05:00
activeClass = true;
2018-10-03 16:13:31 -05:00
break;
2018-08-28 18:57:18 -05:00
2018-10-03 16:13:31 -05:00
default:
activeClass = false;
break;
2018-08-28 18:57:18 -05:00
}
2018-10-03 16:13:31 -05:00
2019-01-29 11:16:14 -05:00
return html`
<a
class="navigation__item${activeClass ? " active" : ""}"
href="${link.url}"
title="${link.title}"
>${link.name}</a>
`;
2018-08-28 18:57:18 -05:00
}