Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

website: Add docsearch classes #2548

Merged
merged 8 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/arch/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@arch-ui/typography": "^0.0.15",
"@emotion/core": "^10.0.27",
"@emotion/styled": "^10.0.27",
"@reach/router": "^1.2.1",
"@reach/router": "^1.3.3",
"clipboard-copy": "^3.0.0",
"gatsby": "^2.13.25",
"react": "^16.13.0"
Expand Down
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@mapbox/rehype-prism": "^0.3.1",
"@mdx-js/mdx": "^1.0.20",
"@mdx-js/react": "^1.0.20",
"@reach/router": "^1.3.3",
"@reach/skip-nav": "^0.1.2",
"@sindresorhus/slugify": "^0.6.0",
"facepaint": "^1.2.1",
Expand Down
109 changes: 67 additions & 42 deletions website/src/components/SidebarNav.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,79 @@
/** @jsx jsx */

import React, { Fragment } from 'react'; // eslint-disable-line no-unused-vars
import React, { useMemo, Fragment } from 'react'; // eslint-disable-line no-unused-vars
import { Link } from 'gatsby';
import { colors, gridSize } from '@arch-ui/theme';
import { jsx } from '@emotion/core';
import { Location } from '@reach/router';
import { useNavData } from '../utils/hooks';

export const SidebarNav = () => {
const navData = useNavData();
return (
<nav aria-label="Documentation Menu">
{navData.map(navGroup => {
const sectionId = `docs-menu-${navGroup.navTitle}`;
return (
<div key={navGroup.navTitle}>
<GroupHeading id={sectionId}>{navGroup.navTitle.replace('-', ' ')}</GroupHeading>
<List aria-labelledby={sectionId}>
{navGroup.pages.map(node => {
return (
<ListItem key={node.path} to={node.path}>
{node.context.pageTitle}
</ListItem>
);
})}
{navGroup.subNavs.length ? (
<li>
{navGroup.subNavs.map(navGroup => {
return (
<Fragment key={navGroup.navTitle}>
<GroupSubHeading id={sectionId}>
{navGroup.navTitle.replace('-', ' ')}
</GroupSubHeading>
<List aria-labelledby={sectionId}>
{navGroup.pages.map(node => {
return (
<ListItem key={node.path} to={node.path}>
{node.context.pageTitle}
</ListItem>
);
})}
</List>
</Fragment>
);
})}
</li>
) : null}
</List>
</div>
);
})}
</nav>
<Location>
{({ location: { pathname } }) => (
<nav aria-label="Documentation Menu">
{navData.map((navGroup, i) => {
return <NavGroup key={i} navGroup={navGroup} pathname={pathname} />;
})}
</nav>
)}
</Location>
);
};

const NavGroup = ({ navGroup, pathname }) => {
const sectionId = `docs-menu-${navGroup.navTitle}`;

const isPageInGroupActive = useMemo(() => {
let paths = [];

navGroup.pages.forEach(i => paths.push(i.path));

if (navGroup.subNavs.length) {
navGroup.subNavs.forEach(group => group.pages.forEach(i => paths.push(i.path)));
}

return paths.some(i => i === pathname);
}, [pathname]);

return (
<div key={navGroup.navTitle}>
<GroupHeading id={sectionId} className={isPageInGroupActive ? 'docSearch-lvl0' : null}>
{navGroup.navTitle.replace('-', ' ')}
</GroupHeading>
<List aria-labelledby={sectionId}>
{navGroup.pages.map(node => {
return (
<ListItem key={node.path} to={node.path}>
{node.context.pageTitle}
</ListItem>
);
})}
{navGroup.subNavs.length ? (
<li>
{navGroup.subNavs.map(navGroup => {
return (
<Fragment key={navGroup.navTitle}>
<GroupSubHeading id={sectionId}>
{navGroup.navTitle.replace('-', ' ')}
</GroupSubHeading>
<List aria-labelledby={sectionId}>
{navGroup.pages.map(node => {
return (
<ListItem key={node.path} to={node.path}>
{node.context.pageTitle}
</ListItem>
);
})}
</List>
</Fragment>
);
})}
</li>
) : null}
</List>
</div>
);
};

Expand Down Expand Up @@ -114,6 +138,7 @@ const ListItem = props => (
fontWeight: 500,
},
}}
activeClassName="docSearch-lvl1"
{...props}
/>
</li>
Expand Down
12 changes: 5 additions & 7 deletions website/src/templates/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ export default function Template({
{({ sidebarOffset, sidebarIsVisible }) => (
<Container>
<Sidebar isVisible={sidebarIsVisible} offsetTop={sidebarOffset} />
<Content>
<main>
<SkipNavContent />
<MDXProvider components={mdComponents}>
<MDXRenderer>{body}</MDXRenderer>
</MDXProvider>
</main>
<Content className="docSearch-content">
<SkipNavContent />
<MDXProvider components={mdComponents}>
<MDXRenderer>{body}</MDXRenderer>
</MDXProvider>
<EditSection>
<p>
Have you found a mistake, something that is missing, or could be improved on this
Expand Down
12 changes: 5 additions & 7 deletions website/src/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ export default function Template({
<Container>
<Sidebar isVisible={sidebarIsVisible} offsetTop={sidebarOffset} />
<Content>
<main>
<SkipNavContent />
<MDXProvider components={mdComponents}>
<MDXRenderer>{body}</MDXRenderer>
</MDXProvider>
{renderNavSection(fields.navGroup)}
</main>
<SkipNavContent />
<MDXProvider components={mdComponents}>
<MDXRenderer>{body}</MDXRenderer>
</MDXProvider>
{renderNavSection(fields.navGroup)}
</Content>
</Container>
)}
Expand Down
2 changes: 1 addition & 1 deletion website/src/templates/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const Layout = ({ children }) => {
const layoutGutter = gridSize * 4;

export const Content = props => (
<div
<main
css={{
minWidth: 0,
lineHeight: '1.6',
Expand Down
12 changes: 5 additions & 7 deletions website/src/templates/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ export default function Template({
<Container>
<Sidebar isVisible={sidebarIsVisible} offsetTop={sidebarOffset} />
<Content>
<main>
<SkipNavContent />
<MDXProvider components={mdComponents}>
<MDXRenderer>{body}</MDXRenderer>
</MDXProvider>
<PackagesList />
</main>
<SkipNavContent />
<MDXProvider components={mdComponents}>
<MDXRenderer>{body}</MDXRenderer>
</MDXProvider>
<PackagesList />
</Content>
</Container>
)}
Expand Down
28 changes: 19 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2942,7 +2942,7 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@reach/router@^1.1.1", "@reach/router@^1.2.1":
"@reach/router@^1.1.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.2.1.tgz#34ae3541a5ac44fa7796e5506a5d7274a162be4e"
integrity sha512-kTaX08X4g27tzIFQGRukaHmNbtMYDS3LEWIS8+l6OayGIw6Oyo1HIF/JzeuR2FoF9z6oV+x/wJSVSq4v8tcUGQ==
Expand All @@ -2953,6 +2953,16 @@
react-lifecycles-compat "^3.0.4"
warning "^3.0.0"

"@reach/router@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.3.3.tgz#58162860dce6c9449d49be86b0561b5ef46d80db"
integrity sha512-gOIAiFhWdiVGSVjukKeNKkCRBLmnORoTPyBihI/jLunICPgxdP30DroAvPQuf1eVfQbfGJQDJkwhJXsNPMnVWw==
dependencies:
create-react-context "0.3.0"
invariant "^2.2.3"
prop-types "^15.6.1"
react-lifecycles-compat "^3.0.4"

"@reach/skip-nav@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@reach/skip-nav/-/skip-nav-0.1.2.tgz#3a154d834c970577117bf6f56b3acc5492d4b8f2"
Expand Down Expand Up @@ -7188,6 +7198,14 @@ create-react-class@^15.5.1:
loose-envify "^1.3.1"
object-assign "^4.1.1"

[email protected], create-react-context@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.3.0.tgz#546dede9dc422def0d3fc2fe03afe0bc0f4f7d8c"
integrity sha512-dNldIoSuNSvlTJ7slIKC/ZFGKexBMBrrcc+TTe1NdmROnaASuLPvqpwj9v4XS4uXZ8+YPu0sNmShX2rXI5LNsw==
dependencies:
gud "^1.0.0"
warning "^4.0.3"

create-react-context@^0.1.5:
version "0.1.6"
resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.1.6.tgz#0f425931d907741127acc6e31acb4f9015dd9fdc"
Expand All @@ -7201,14 +7219,6 @@ create-react-context@^0.2.1:
fbjs "^0.8.0"
gud "^1.0.0"

create-react-context@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.3.0.tgz#546dede9dc422def0d3fc2fe03afe0bc0f4f7d8c"
integrity sha512-dNldIoSuNSvlTJ7slIKC/ZFGKexBMBrrcc+TTe1NdmROnaASuLPvqpwj9v4XS4uXZ8+YPu0sNmShX2rXI5LNsw==
dependencies:
gud "^1.0.0"
warning "^4.0.3"

cross-env@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.0.tgz#5a3b2ddce51ec713ea58f2fb79ce22e65b4f5479"
Expand Down