-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from newrelic/zstickles/reference-page
Reference Template
- Loading branch information
Showing
9 changed files
with
240 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import cx from 'classnames'; | ||
|
||
import './Container.scss'; | ||
|
||
const Container = ({ children }) => ( | ||
<div className="u-container">{children}</div> | ||
const Container = ({ children, className }) => ( | ||
<div className={cx('u-container', className)}>{children}</div> | ||
); | ||
|
||
Container.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default Container; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'gatsby'; | ||
import cx from 'classnames'; | ||
|
||
import { link } from '../types'; | ||
import './Sidebar.scss'; | ||
|
||
// recursively create navigation | ||
const renderNav = (page, index) => ( | ||
<li key={index}> | ||
<Link to={page.url} className={cx({ 'is-active': page.active })}> | ||
{page.displayName} | ||
</Link> | ||
{page.children && <ul>{page.children.map(renderNav)}</ul>} | ||
</li> | ||
); | ||
|
||
const Sidebar = ({ pages, isOpen, toggle }) => ( | ||
<aside className={cx('Sidebar', { 'is-open': isOpen })}> | ||
<div className="Sidebar-top"> | ||
<h3>Pages</h3> | ||
<button | ||
aria-expanded={isOpen} | ||
className="Sidebar-toggle" | ||
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> | ||
</nav> | ||
</aside> | ||
); | ||
|
||
Sidebar.propTypes = { | ||
toggle: PropTypes.func.isRequired, | ||
pages: PropTypes.arrayOf(link).isRequired, | ||
isOpen: PropTypes.bool, | ||
}; | ||
|
||
Sidebar.defaultProps = { | ||
isOpen: false, | ||
}; | ||
|
||
export default Sidebar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.Sidebar { | ||
padding: 1rem; | ||
|
||
ul { | ||
margin: 0; | ||
padding-left: 1rem; | ||
list-style: none; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
color: var(--color-black); | ||
display: inline-block; | ||
padding: 0.2rem 0; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
&.is-active { | ||
font-weight: bold; | ||
} | ||
} | ||
|
||
h3 { | ||
margin: 0; | ||
} | ||
|
||
button { | ||
background: none; | ||
border: 0; | ||
cursor: pointer; | ||
width: 3rem; | ||
display: none; | ||
|
||
@media (max-width: 760px) { | ||
display: block; | ||
} | ||
} | ||
|
||
.Sidebar-top { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
nav { | ||
margin-top: 1rem; | ||
|
||
@media (max-width: 760px) { | ||
display: none; | ||
} | ||
} | ||
|
||
&.is-open { | ||
nav { | ||
@media (max-width: 760px) { | ||
display: block; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import Container from '../components/Container'; | ||
import Layout from '../components/Layout'; | ||
import Sidebar from '../components/Sidebar'; | ||
|
||
// TODO: move this js file to same directory and update import | ||
import '../templates/Reference.scss'; | ||
|
||
// TODO: pull this in from Gatsby | ||
const pages = [ | ||
{ displayName: 'Overview', url: '' }, | ||
{ | ||
displayName: 'CLI', | ||
url: '', | ||
children: [ | ||
{ displayName: 'newrelic', url: '' }, | ||
{ displayName: 'nr1', url: '' }, | ||
], | ||
}, | ||
{ displayName: 'GraphQL', url: '' }, | ||
{ | ||
displayName: 'Applications', | ||
url: '', | ||
children: [ | ||
{ displayName: 'Component Library', url: '', active: true }, | ||
{ displayName: 'File structure', url: '' }, | ||
], | ||
}, | ||
{ | ||
displayName: 'Data Collectors', | ||
url: '', | ||
children: [ | ||
{ displayName: 'Custom Attributes', url: '' }, | ||
{ displayName: 'Custom Events', url: '' }, | ||
{ displayName: 'Open Telemetry', url: '' }, | ||
{ displayName: 'Telemetry SDK', url: '' }, | ||
], | ||
}, | ||
{ | ||
displayName: 'Automation', | ||
url: '', | ||
children: [ | ||
{ displayName: 'Cloud Formation Provider', url: '' }, | ||
{ displayName: 'Terraform Provider', url: '' }, | ||
{ | ||
displayName: 'Agent Deploy', | ||
url: '', | ||
children: [ | ||
{ displayName: 'Ansible', url: '' }, | ||
{ displayName: 'Chef', url: '' }, | ||
{ displayName: 'Puppet', url: '' }, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const Reference = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<Layout> | ||
<Container className="ReferenceTemplate"> | ||
<Sidebar | ||
pages={pages} | ||
isOpen={isOpen} | ||
toggle={() => setIsOpen(!isOpen)} | ||
/> | ||
<main className="ReferenceTemplate-content"> | ||
The main page content goes here | ||
</main> | ||
</Container> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default Reference; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.ReferenceTemplate { | ||
display: grid; | ||
grid-template-columns: 1fr 3fr; | ||
grid-template-areas: 'sidebar main'; | ||
|
||
@media (max-width: 760px) { | ||
grid-template-columns: none; | ||
grid-template-areas: 'sidebar' 'main'; | ||
} | ||
|
||
.Sidebar { | ||
grid-area: sidebar; | ||
} | ||
|
||
.ReferenceTemplate-content { | ||
grid-area: main; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
// NOTE: while creating a recursive data structure is feasible, | ||
// it is not very performant. | ||
export const link = PropTypes.shape({ | ||
displayName: PropTypes.string.isRequired, | ||
url: PropTypes.string.isRequired, | ||
active: PropTypes.bool, | ||
children: PropTypes.array, | ||
}); |