Created
May 2, 2021 16:20
-
-
Save otsolap/9bf186db6793bdcf721d520a45336e09 to your computer and use it in GitHub Desktop.
Navigation.js File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { graphql, StaticQuery, Link } from "gatsby" | |
import Nav from "react-bootstrap/Nav" | |
import Navbar from "react-bootstrap/Navbar" | |
import NavDropdown from "react-bootstrap/NavDropdown" | |
function menuLinks() { | |
return ( | |
<StaticQuery | |
query={graphql` | |
query menuItems { | |
site { | |
siteMetadata { | |
MenuLinks { | |
link | |
title | |
subMenu { | |
link | |
title | |
} | |
} | |
} | |
} | |
} | |
`} | |
render={data => ( | |
<ul> | |
{data.site.siteMetadata.MenuLinks.map((path) => ( | |
<Nav.Link as="li" key={path.title}> | |
<Link | |
to={path.link} | |
> | |
{path.title} | |
</Link> | |
{path.subMenu && path.subMenu.length > 0 ? ( | |
<NavDropdown class="sub-items responsive-navbar-nav"> | |
{path.subMenu.map((subpath) => ( | |
<NavDropdown.Item a href={subpath.link}> | |
{subpath.title} | |
</NavDropdown.Item> | |
))} | |
</NavDropdown> | |
) : null} | |
</Nav.Link>)) | |
}</ul> | |
)} | |
/> | |
) | |
} | |
class Navigation extends React.Component { | |
render() { | |
return ( | |
<Navbar collapseOnSelect expand="md" className="site-navigation"> | |
<Navbar.Brand class="logo" href="/">Metsän Otus</Navbar.Brand> | |
<Navbar.Toggle aria-controls="responsive-navbar-nav" /> | |
<Navbar.Collapse id="responsive-navbar-nav"> | |
<ul> | |
{menuLinks} | |
</ul> | |
</Navbar.Collapse> | |
</Navbar > | |
) | |
} | |
} | |
export default Navigation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment