diff --git a/src/components/Navigation.js b/src/components/Navigation.js index 9f235475d..d74fe789a 100644 --- a/src/components/Navigation.js +++ b/src/components/Navigation.js @@ -1,52 +1,78 @@ -import React, { useState, useContext } from 'react'; +import React, { Fragment, useState, useContext } from 'react'; import PropTypes from 'prop-types'; import { Link } from 'gatsby'; import cx from 'classnames'; import { BreadcrumbContext } from './BreadcrumbContext'; +import FeatherIcon from './FeatherIcon'; import pages from '../data/sidenav.json'; import styles from './Navigation.module.scss'; // recursively create navigation 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 crumbs = useContext(BreadcrumbContext).flatMap((x) => x.displayName); - const display = page.url ? ( - {page.displayName} - ) : ( -
setIsDisplay(!isDisplay)} - onKeyPress={() => setIsDisplay(!isDisplay)} - tabIndex={0} - > - {page.displayName} -
- ); - let subNav; + const groupedPages = pages.reduce((groups, page) => { + const { group = '' } = page; - if (page.children) { - subNav = renderNav(page.children, depthLevel + 1); - } - return ( -
  • - {display} - -
  • - ); - }); + return { + ...groups, + [group]: [...(groups[group] || []), page], + }; + }, {}); + + return Object.entries(groupedPages).map(([group, pages]) => ( + + {group && ( +
  • {group}
  • + )} + {pages.map((page) => { + const [isExpanded, setIsExpanded] = useState( + crumbs.length === depthLevel || crumbs.includes(page.displayName) + ); + const isCurrentPage = crumbs[crumbs.length - 1] === page.displayName; + + return ( +
  • + {page.url ? ( + + {page.displayName} + {isCurrentPage && ( + + )} + + ) : ( + + )} + {page.children && ( +
      + {renderNav(page.children, depthLevel + 1)} +
    + )} +
  • + ); + })} +
    + )); }; const Navigation = ({ className }) => { diff --git a/src/components/Navigation.module.scss b/src/components/Navigation.module.scss index 4393fd6fe..9bb71c303 100644 --- a/src/components/Navigation.module.scss +++ b/src/components/Navigation.module.scss @@ -1,73 +1,64 @@ .container { font-size: 0.875rem; +} - ul { - margin: 0; - padding-left: 1rem; - list-style: none; - } - - a { - color: var(--color-black); - } - - // remove? - button { - background: none; - border: 0; - cursor: pointer; - width: 3rem; - display: none; - } - - nav { - margin-top: 1rem; - } +.listNav, +.nestedNav { + list-style: none; } .nestedNav { + padding-left: 1rem; display: none; -} -.isDisplay { - display: block; + &.isExpanded { + display: block; + } } .listNav { - ul { - padding-left: 1rem; - } + padding-left: 0; } -.navDepth0 { - color: var(--color-black); - font-weight: bold; - div { - margin: 1rem 0; - } - li { - margin: 1rem 0; +.navLink { + color: var(--color-neutrals-900); + margin-bottom: 1rem; + display: flex; + align-items: center; + justify-content: space-between; + text-decoration: none; + + [data-depth='0'] > & { + font-weight: bold; } } -.navDepth1 { - font-weight: normal; - ul { - padding-left: 0.2rem; +button.navLink { + color: var(--color-neutrals-900); + background: inherit; + border: none; + padding: 0; + font-size: inherit; + font-weight: inherit; + + &:focus { + outline: none; } } -.navDepth2 { +.currentPageIndicator { + stroke-width: 4; +} + +.groupName { + color: var(--color-neutrals-600); font-weight: bold; + font-size: 0.75rem; text-transform: uppercase; - color: var(--color-neutrals-600); - font-size: 14px; -} -.navDepth3 { - font-weight: normal; - text-transform: initial; - color: var(--color-black); + &:not(:first-child) { + margin-top: 2rem; + } } .isCurrentPage { diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js index 9f8b2283f..b7c5205dd 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -11,7 +11,7 @@ const Sidebar = ({ className }) => ( - + ); diff --git a/src/components/Sidebar.module.scss b/src/components/Sidebar.module.scss index 9c8eef789..f007215b5 100644 --- a/src/components/Sidebar.module.scss +++ b/src/components/Sidebar.module.scss @@ -15,3 +15,7 @@ width: 160px; } } + +.nav { + margin-top: 1rem; +}