Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into jerel/all-redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 25, 2020
2 parents 01964ff + d08ae19 commit 5d09a22
Show file tree
Hide file tree
Showing 48 changed files with 2,056 additions and 411 deletions.
15 changes: 12 additions & 3 deletions STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,27 @@ The value that is assigned to the key slug is used in order to navigate to your
- `title`: the title of the page
- `template`: the Gatsby template used
- `description`: the description of the page
- `promoteToHomepage` (optional): adds the guide as a tile to the homepage, making it
easier for users to discover
- `callout` (optional): config for the callout tile. Accepts 2 options:
- `title`: provide a title for the callout. Typically used to shorten the
title. The callout will fallback to the guide title if this is not provided.
- `description`: provide a description for the callout. The callout will
fallback to the guide description if this is not provided.

### GuideTemplate Frontmatter example

Be aware that all Frontmatter slugs are `required`.

```md
---
path: '/build-apps/add-time-picker-guide'
duration: '20 min'
title: 'Add the time picker to a sample application'
template: 'GuideTemplate'
description: 'Example guide page'
description: 'Learn how to add a time picker to a sample application'
promoteToHomepage: true
callout:
title: Add a time picker
description: Add the time picker to a sample app to specify a time range in data
---
```

Expand Down
20 changes: 20 additions & 0 deletions src/components/FeatherIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ const ICONS = {
github: (
<path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22" />
),
pen: (
<>
<path d="M12 19l7-7 3 3-7 7-3-3z" />
<path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z" />
<path d="M2 2l7.586 7.586" />
<circle cx="11" cy="11" r="2" />
</>
),
search: (
<>
<circle cx="11" cy="11" r="8" />
<line x1="21" y1="21" x2="16.65" y2="16.65" />
</>
),
'upload-cloud': (
<>
<polyline points="16 16 12 12 8 16" />
Expand All @@ -91,6 +105,12 @@ const ICONS = {
<polyline points="16 16 12 12 8 16" />
</>
),
award: (
<>
<circle cx="12" cy="8" r="7" />
<polyline points="8.21 13.89 7 23 12 20 17 23 15.79 13.88" />
</>
),
};

FeatherIcon.propTypes = {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const Footer = ({ className }) => {
</div>

<div className={styles.right}>
<Link to="/terms">
<FeatherIcon className={styles.linkIcon} name="pen" size="1rem" />
Terms of service
</Link>
{fileRelativePath && (
<ExternalLink
href={`${githubBaseUrl}/blob/master/${fileRelativePath}`}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Footer.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
font-size: 0.75rem;
z-index: 1;

@media (max-width: 1080px) {
flex-direction: column;
}

a {
color: currentColor;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/GuideTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cx from 'classnames';
import { navigate } from 'gatsby';
import styles from './GuideTile.module.scss';

const GuideTile = ({ icon, minutes, title, description, path, className }) => (
const GuideTile = ({ icon, duration, title, description, path, className }) => (
<div className={cx(styles.tile, className, { [styles.tileWithIcon]: icon })}>
{icon && (
<div className={styles.iconContainer}>
Expand All @@ -16,7 +16,7 @@ const GuideTile = ({ icon, minutes, title, description, path, className }) => (

<div className={styles.timeEstimate}>
<FeatherIcon className={styles.timeIcon} name="clock" />
{minutes} minutes
{duration}
</div>
<h2 className={styles.title}>{title}</h2>
<p className={styles.description}>{description}</p>
Expand All @@ -31,7 +31,7 @@ const GuideTile = ({ icon, minutes, title, description, path, className }) => (
);

GuideTile.propTypes = {
minutes: PropTypes.number.isRequired,
duration: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
Expand Down
1 change: 1 addition & 0 deletions src/components/IconReference.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
position: absolute;
font-size: 0.85rem;
top: calc(100% + 0.5rem);
right: 0;
z-index: 1;
}
1 change: 1 addition & 0 deletions src/components/MobileHeader.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}

.logo {
display: block;
width: 160px;
}

Expand Down
141 changes: 37 additions & 104 deletions src/components/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,127 +1,60 @@
import React, { Fragment, useState, useContext } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'gatsby';
import cx from 'classnames';
import { BreadcrumbContext } from './BreadcrumbContext';
import FeatherIcon from './FeatherIcon';
import NewRelicIcon from './NewRelicIcon';
import NavigationItems from './NavigationItems';
import pages from '../data/sidenav.json';

import matchSearchString from '../utils/matchSearchString';
import styles from './Navigation.module.scss';

// recursively create navigation
const renderNav = (pages, depthLevel = 0) => {
// TODO: Refactor this function into a component
// eslint-disable-next-line react-hooks/rules-of-hooks
const crumbs = useContext(BreadcrumbContext).flatMap((x) => x.displayName);
const isHomePage = crumbs.length === 0 && depthLevel === 0;
const iconLibrary = {
'Collect data': 'collectData',
'Build apps': 'buildApps',
'Automate workflows': 'automation',
'Explore docs': 'developerDocs',
};

const groupedPages = pages.reduce((groups, page) => {
const { group = '' } = page;

return {
...groups,
[group]: [...(groups[group] || []), page],
};
}, {});
const filterPageNames = (pages, searchTerm, parent = []) => {
return [
...new Set(
pages.flatMap((page) => {
if (page.children) {
return filterPageNames(page.children, searchTerm, [
...parent,
page.displayName,
]);
} else if (matchSearchString(page.displayName, searchTerm)) {
return [...parent, page.displayName];
} else if (parent.some((el) => matchSearchString(el, searchTerm))) {
return [...parent];
}
})
),
];
};

return Object.entries(groupedPages).map(([group, pages]) => (
<Fragment key={group}>
{group && (
<li className={cx(styles.navLink, styles.groupName)}>{group}</li>
)}
{pages.map((page) => {
const [isExpanded, setIsExpanded] = useState(
isHomePage || crumbs.includes(page.displayName)
);
const isCurrentPage = crumbs[crumbs.length - 1] === page.displayName;
const headerIcon = depthLevel === 0 && (
<NewRelicIcon
className={styles.headerIcon}
name={iconLibrary[page.displayName]}
/>
);
const Navigation = ({ className, searchTerm }) => {
const searchTermSanitized = searchTerm?.replace(
/[.*+?^${}()|[\]\\]/g,
'\\$&'
);

return (
<li key={page.displayName} data-depth={depthLevel}>
{page.url ? (
<Link
className={cx(
{
[styles.isCurrentPage]: isCurrentPage,
},
styles.navLink
)}
to={page.url}
>
<span>
{headerIcon}
{page.displayName}
</span>
{isCurrentPage && (
<FeatherIcon
className={styles.currentPageIndicator}
name="chevron-right"
/>
)}
</Link>
) : (
<button
type="button"
className={styles.navLink}
onClick={() => setIsExpanded(!isExpanded)}
onKeyPress={() => setIsExpanded(!isExpanded)}
tabIndex={0}
>
{depthLevel > 0 && (
<FeatherIcon
className={cx(
{ [styles.isExpanded]: isExpanded },
styles.nestedChevron
)}
name="chevron-right"
/>
)}
{headerIcon}
{page.displayName}
</button>
)}
{page.children && (
<ul
className={cx(styles.nestedNav, {
[styles.isExpanded]: isExpanded,
})}
>
{renderNav(page.children, depthLevel + 1)}
</ul>
)}
</li>
);
})}
</Fragment>
));
};
const filteredPageNames = searchTerm
? filterPageNames(pages, searchTermSanitized)
: undefined;

const Navigation = ({ className }) => {
return (
<nav
className={cx(styles.container, className)}
role="navigation"
aria-label="Navigation"
>
<ul className={styles.listNav}>{renderNav(pages)}</ul>
<ul className={styles.listNav}>
<NavigationItems
searchTerm={searchTermSanitized}
pages={pages}
filteredPageNames={filteredPageNames}
/>
</ul>
</nav>
);
};

Navigation.propTypes = {
className: PropTypes.string,
searchTerm: PropTypes.string,
};

export default Navigation;
82 changes: 1 addition & 81 deletions src/components/Navigation.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,7 @@
font-size: 0.875rem;
}

.listNav,
.nestedNav {
list-style: none;
}

.nestedNav {
padding-left: 1rem;
display: none;

&.isExpanded {
display: block;
}

[data-depth] > & {
padding-left: calc(0.5rem + 1em);
}
}

.listNav {
list-style: none;
padding-left: 0;
}

.navLink {
color: var(--color-neutrals-900);
margin-bottom: 1rem;
display: flex;
align-items: center;
justify-content: space-between;
text-decoration: none;
transition: 0.1s;

&:not(.isCurrentPage):hover {
color: var(--color-neutrals-600);
}

[data-depth='0'] > & {
font-weight: bold;
}
}

.headerIcon {
margin-right: 0.5rem;
}

button.navLink {
color: var(--color-neutrals-900);
background: inherit;
border: none;
padding: 0;
font-size: inherit;
font-weight: inherit;

&:focus {
outline: none;
}
}

.currentPageIndicator {
stroke-width: 4;
}

.nestedChevron {
margin-right: 0.5rem;
stroke-width: 4;
transition: 0.2s;
&.isExpanded {
transform: rotate(90deg);
}
}

.groupName {
color: var(--color-neutrals-600);
font-weight: bold;
font-size: 0.75rem;
text-transform: uppercase;

&:not(:first-child) {
margin-top: 2rem;
}
}

.isCurrentPage {
font-weight: bold;
}
Loading

0 comments on commit 5d09a22

Please sign in to comment.