Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into jerel/layout-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 16, 2020
2 parents 9ce8975 + 009e72f commit 6104e0b
Show file tree
Hide file tree
Showing 8 changed files with 653 additions and 483 deletions.
3 changes: 3 additions & 0 deletions src/components/BreadcrumbContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

export const BreadcrumbContext = React.createContext([]);
69 changes: 43 additions & 26 deletions src/components/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
import React from 'react';
import React, { useState, useContext } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'gatsby';
import cx from 'classnames';
import { BreadcrumbContext } from './BreadcrumbContext';

import Logo from './Logo';
import { link } from '../types';
import styles from './Sidebar.module.scss';

// recursively create navigation
const renderNav = (page, index) => (
<li key={index}>
{page.url ? (
<Link to={page.url} className={cx({ [styles.isActive]: page.active })}>
{page.displayName}
</Link>
const renderNav = (pages, depthLevel = 0) => {
return pages.map((page, index) => {
const crumbs = useContext(BreadcrumbContext).flatMap((x) => x.displayName);
const [isDisplay, setIsDisplay] = useState(
crumbs.length === depthLevel || crumbs.includes(page.displayName)
);
const isCurrentPage = crumbs[crumbs.length - 1] === page.displayName;

const display = page.url ? (
<Link to={page.url}>{page.displayName}</Link>
) : (
<div>{page.displayName}</div>
)}
{page.children && <ul>{page.children.map(renderNav)}</ul>}
</li>
);
<div
role="button"
onClick={() => setIsDisplay(!isDisplay)}
onKeyPress={() => setIsDisplay(!isDisplay)}
tabIndex={0}
>
{page.displayName}
</div>
);
let subNav;

const Sidebar = ({ className, pages, isOpen, toggle }) => (
if (page.children) {
subNav = renderNav(page.children, depthLevel + 1);
}
return (
<li
className={cx(styles[`navDepth${depthLevel}`], {
[styles.isCurrentPage]: isCurrentPage,
})}
key={index}
>
{display}
<ul className={cx(styles.nestedNav, { [styles.isDisplay]: isDisplay })}>
{subNav}
</ul>
</li>
);
});
};

const Sidebar = ({ className, pages, isOpen }) => (
<aside className={cx(styles.sidebar, className, { [styles.isOpen]: isOpen })}>
<Link to="/">
<Logo className={styles.logo} />
</Link>
<div className={styles.top}>
<h3>Pages</h3>
<button
aria-expanded={isOpen}
aria-label="Main Menu Toggle"
type="button"
onClick={() => toggle()}
>
{isOpen ? 'close' : 'open'}
</button>
</div>
<nav role="navigation" aria-label="Sidebar">
<ul>{pages.map(renderNav)}</ul>
<ul className={styles.listNav}>{renderNav(pages)}</ul>
</nav>
</aside>
);

Sidebar.propTypes = {
className: PropTypes.string,
toggle: PropTypes.func.isRequired,
pages: PropTypes.arrayOf(link).isRequired,
isOpen: PropTypes.bool,
};
Expand Down
58 changes: 50 additions & 8 deletions src/components/Sidebar.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.sidebar {
padding: 2rem;
border-right: 1px solid var(--color-neutrals-100);
font-size: 0.875rem;

ul {
margin: 0;
Expand All @@ -12,14 +13,6 @@
text-decoration: none;
color: var(--color-black);
display: inline-block;

&:hover {
text-decoration: underline;
}

&.isActive {
font-weight: bold;
}
}

h3 {
Expand Down Expand Up @@ -63,3 +56,52 @@
.logo {
width: 200px;
}

.nestedNav {
display: none;
}

.isDisplay {
display: block;
}

.listNav {
ul {
padding-left: 1rem;
}
}

.navDepth0 {
color: var(--color-black);
font-weight: bold;
div {
margin: 1rem 0;
}
li {
margin: 1rem 0;
}
}

.navDepth1 {
font-weight: normal;
ul {
padding-left: 0.2rem;
}
}

.navDepth2 {
font-weight: bold;
text-transform: uppercase;
color: var(--color-neutrals-600);
font-size: 14px;
}

.navDepth3 {
font-weight: normal;
text-transform: initial;
color: var(--color-black);
}

.isCurrentPage {
font-weight: bold;
}
Loading

0 comments on commit 6104e0b

Please sign in to comment.