-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: recursively create sidebar navigation
- Loading branch information
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'gatsby'; | ||
|
||
import { link } from '../types'; | ||
// TODO: styles | ||
|
||
// TODO: aria | ||
|
||
// recursively create navigation | ||
const renderNav = (page, index) => ( | ||
<li key={index}> | ||
<Link to={page.url}>{page.displayName}</Link> | ||
{page.children && <ul>{page.children.map(renderNav)}</ul>} | ||
</li> | ||
); | ||
|
||
const Sidebar = ({ pages }) => ( | ||
<aside className="Sidebar"> | ||
<div>This is the sidebar</div> | ||
<h3>Pages</h3> | ||
<nav> | ||
<ul>{pages.map(renderNav)}</ul> | ||
</nav> | ||
</aside> | ||
); | ||
|
||
Sidebar.propTypes = { | ||
pages: PropTypes.array, // TODO | ||
pages: PropTypes.arrayOf(link), | ||
}; | ||
|
||
export default Sidebar; |
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