diff --git a/src/components/BreadcrumbContext.js b/src/components/BreadcrumbContext.js
new file mode 100644
index 000000000..936ae93ae
--- /dev/null
+++ b/src/components/BreadcrumbContext.js
@@ -0,0 +1,3 @@
+import React from 'react';
+
+export const BreadcrumbContext = React.createContext([]);
diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js
index d493644e4..378e9f87a 100644
--- a/src/components/Sidebar.js
+++ b/src/components/Sidebar.js
@@ -1,47 +1,51 @@
-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 { link } from '../types';
import styles from './Sidebar.module.scss';
// recursively create navigation
-const renderNav = (page, index) => (
-
- {page.url ? (
-
- {page.displayName}
-
- ) : (
- {page.displayName}
- )}
- {page.children && {page.children.map(renderNav)}
}
-
-);
+const renderNav = (page, index) => {
+ const crumbs = useContext(BreadcrumbContext).flatMap((x) => x.displayName);
+ const [isDisplay, setIsDisplay] = useState(crumbs.includes(page.displayName));
+
+ return (
+
+ {page.url ? (
+ {page.displayName}
+ ) : (
+ setIsDisplay(!isDisplay)}
+ onKeyPress={() => setIsDisplay(!isDisplay)}
+ tabIndex={0}
+ >
+ {page.displayName}
+
+ )}
+ {page.children && (
+
+ {page.children.map(renderNav)}
+
+ )}
+
+ );
+};
-const Sidebar = ({ className, pages, isOpen, toggle }) => (
+const Sidebar = ({ className, pages, isOpen }) => (
);
Sidebar.propTypes = {
className: PropTypes.string,
- toggle: PropTypes.func.isRequired,
pages: PropTypes.arrayOf(link).isRequired,
isOpen: PropTypes.bool,
};
diff --git a/src/components/Sidebar.module.scss b/src/components/Sidebar.module.scss
index 5a67af271..2ad420809 100644
--- a/src/components/Sidebar.module.scss
+++ b/src/components/Sidebar.module.scss
@@ -14,10 +14,6 @@
&:hover {
text-decoration: underline;
}
-
- &.isActive {
- font-weight: bold;
- }
}
h3 {
@@ -67,3 +63,46 @@
margin-right: 1rem;
background-image: url('../images/developers-logo.svg');
}
+
+.nestedNav {
+ display: none;
+}
+
+.isDisplay {
+ display: block;
+}
+
+.listNav {
+ div {
+ margin-bottom: 1rem;
+ }
+ li {
+ color: var(--color-black);
+ font-weight: bold;
+ ul {
+ li {
+ font-weight: normal;
+ ul {
+ padding-left: 0.5rem;
+ li {
+ font-weight: bold;
+ text-transform: uppercase;
+ color: var(--color-neutrals-600);
+ font-size: 14px;
+ ul {
+ padding-left: 0rem;
+ li {
+ font-weight: normal;
+ text-transform: initial;
+ color: var(--color-black);
+ ul {
+ padding-left: 1rem;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/templates/ApiReferenceTemplate.js b/src/templates/ApiReferenceTemplate.js
index f20e74fb4..e9796b36f 100644
--- a/src/templates/ApiReferenceTemplate.js
+++ b/src/templates/ApiReferenceTemplate.js
@@ -13,6 +13,10 @@ import SEO from '../components/Seo';
import templateStyles from './ReferenceTemplate.module.scss';
import useApiDoc from '../hooks/useApiDoc';
+import { BreadcrumbContext } from '../components/BreadcrumbContext';
+import createBreadcrumbs from '../utils/create-breadcrumbs';
+import pages from '../data/sidenav.json';
+
const ApiReferenceTemplate = ({ data }) => {
const { mdx } = data;
const { frontmatter } = mdx;
@@ -25,49 +29,53 @@ const ApiReferenceTemplate = ({ data }) => {
constants = [],
} = useApiDoc(api) ?? {};
- return (
-
-
- {api}
-
-
+ const crumbs = createBreadcrumbs(frontmatter.path, pages);
-
+ return (
+
+
+
+ {api}
- {methods.length > 0 && (
-
- API methods
- {methods.map((method, i) => (
-
- ))}
+
- )}
- {typeDefs.length > 0 && (
- Type definitions
- {typeDefs.map((typeDef, i) => (
-
- ))}
+ Usage
+ {usage}
- )}
- {constants.length > 0 && (
-
- Constants
- {constants.map((constant, i) => (
-
- ))}
-
- )}
-
+ {methods.length > 0 && (
+
+ API methods
+ {methods.map((method, i) => (
+
+ ))}
+
+ )}
+
+ {typeDefs.length > 0 && (
+
+ Type definitions
+ {typeDefs.map((typeDef, i) => (
+
+ ))}
+
+ )}
+
+ {constants.length > 0 && (
+
+ Constants
+ {constants.map((constant, i) => (
+
+ ))}
+
+ )}
+
+
);
};
diff --git a/src/templates/ComponentReferenceTemplate.js b/src/templates/ComponentReferenceTemplate.js
index a5ef245f4..a11cb38f2 100644
--- a/src/templates/ComponentReferenceTemplate.js
+++ b/src/templates/ComponentReferenceTemplate.js
@@ -2,6 +2,7 @@ import React from 'react';
import cx from 'classnames';
import { graphql } from 'gatsby';
import PropTypes from 'prop-types';
+
import InlineCodeSnippet from '../components/InlineCodeSnippet';
import ReactMarkdown from 'react-markdown';
import ReferenceExample from '../components/ReferenceExample';
@@ -15,6 +16,10 @@ import useComponentDoc from '../hooks/useComponentDoc';
import IconGallery from '../components/IconGallery';
import TypeDefReference from '../components/TypeDefReference';
+import { BreadcrumbContext } from '../components/BreadcrumbContext';
+import createBreadcrumbs from '../utils/create-breadcrumbs';
+import pages from '../data/sidenav.json';
+
const previewStyles = {
Spinner: {
height: '16px',
@@ -35,71 +40,75 @@ const ComponentReferenceTemplate = ({ data }) => {
propTypes = [],
} = useComponentDoc(component) ?? {};
- return (
-
-
- {component}
-
-
-
+ const crumbs = createBreadcrumbs(frontmatter.path, pages);
- {examples.length > 0 && (
-
- Examples
-
- {examples.map((example, i) => (
-
- ))}
-
+ return (
+
+
+
+ {component}
+
- )}
- {component === 'Icon' && (
- )}
-
+ {examples.length > 0 && (
+
+ Examples
+
+ {examples.map((example, i) => (
+
+ ))}
+
+
+ )}
+
+ {component === 'Icon' && (
+
+ )}
- {methods.length > 0 && (
- Methods
- {methods.map((method, i) => (
-
- ))}
+ Props
+
- )}
- {typeDefs.length > 0 && (
-
- Type definitions
- {typeDefs.map((typeDef, i) => (
-
- ))}
-
- )}
-
+ {methods.length > 0 && (
+
+ Methods
+ {methods.map((method, i) => (
+
+ ))}
+
+ )}
+
+ {typeDefs.length > 0 && (
+
+ Type definitions
+ {typeDefs.map((typeDef, i) => (
+
+ ))}
+
+ )}
+
+
);
};
diff --git a/src/templates/GuideTemplate.js b/src/templates/GuideTemplate.js
index be15c186f..3786e7941 100644
--- a/src/templates/GuideTemplate.js
+++ b/src/templates/GuideTemplate.js
@@ -11,6 +11,7 @@ import Step from '../components/Step';
import Steps from '../components/Steps';
import Intro from '../components/Intro';
import SEO from '../components/Seo';
+import { BreadcrumbContext } from '../components/BreadcrumbContext';
import createBreadcrumbs from '../utils/create-breadcrumbs';
import pages from '../data/sidenav.json';
@@ -32,14 +33,16 @@ const GuideTemplate = ({ data }) => {
const crumbs = createBreadcrumbs(frontmatter.path, pages);
return (
-
-
-
- {title}
-
- {body}
-
-
+
+
+
+
+ {title}
+
+ {body}
+
+
+
);
};