-
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.
- Loading branch information
1 parent
2880c29
commit 2e6f488
Showing
6 changed files
with
240 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
const Content = styled.div` | ||
grid-area: content; | ||
`; | ||
|
||
export default Content; |
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,39 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/core'; | ||
|
||
const Header = ({ title, children }) => ( | ||
<header | ||
css={css` | ||
grid-area: page-header; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
border-bottom: 1px solid var(--divider-color); | ||
@media screen and (max-width: 1080px) { | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
`} | ||
> | ||
<h1 | ||
css={css` | ||
font-family: var(--secondary-font-family); | ||
font-size: 2.5rem; | ||
font-weight: normal; | ||
margin-bottom: 0; | ||
`} | ||
> | ||
{title} | ||
</h1> | ||
{children} | ||
</header> | ||
); | ||
|
||
Header.propTypes = { | ||
children: PropTypes.node, | ||
title: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default Header; |
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,8 @@ | ||
import styled from '@emotion/styled'; | ||
import MDXContainer from '../MDXContainer'; | ||
|
||
const MarkdownContent = styled(MDXContainer)` | ||
grid-area: content; | ||
`; | ||
|
||
export default MarkdownContent; |
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,77 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/core'; | ||
import { graphql, useStaticQuery } from 'gatsby'; | ||
import Content from './Content'; | ||
import Header from './Header'; | ||
import MarkdownContent from './MarkdownContent'; | ||
import RelatedContent from './RelatedContent'; | ||
|
||
const TYPES = { | ||
SINGLE_COLUMN: 'SINGLE_COLUMN', | ||
RELATED_CONTENT: 'RELATED_CONTENT', | ||
}; | ||
|
||
const LAYOUTS = { | ||
[TYPES.RELATED_CONTENT]: css` | ||
grid-template-areas: | ||
'page-header page-header' | ||
'content related-content'; | ||
grid-template-columns: minmax(0, 1fr) auto; | ||
grid-gap: 2rem; | ||
@media (max-width: 1240px) { | ||
grid-template-areas: | ||
'page-header' | ||
'content'; | ||
grid-template-columns: minmax(0, 1fr); | ||
} | ||
`, | ||
[TYPES.SINGLE_COLUMN]: css` | ||
grid-template-areas: | ||
'page-header' | ||
'content'; | ||
grid-template-columns: minmax(0, 1fr); | ||
`, | ||
}; | ||
|
||
const PageLayout = ({ children, type }) => { | ||
const { | ||
site: { layout }, | ||
} = useStaticQuery(graphql` | ||
query { | ||
site { | ||
layout { | ||
contentPadding | ||
} | ||
} | ||
} | ||
`); | ||
|
||
return ( | ||
<div | ||
css={css` | ||
display: grid; | ||
grid-gap: ${layout.contentPadding}; | ||
${LAYOUTS[type]}; | ||
`} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
PageLayout.propTypes = { | ||
children: PropTypes.node, | ||
type: PropTypes.oneOf(Object.values(TYPES)).isRequired, | ||
}; | ||
|
||
PageLayout.TYPE = TYPES; | ||
|
||
PageLayout.Content = Content; | ||
PageLayout.Header = Header; | ||
PageLayout.MarkdownContent = MarkdownContent; | ||
PageLayout.RelatedContent = RelatedContent; | ||
|
||
export default PageLayout; |
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,108 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/core'; | ||
import { graphql, useStaticQuery } from 'gatsby'; | ||
import { Button, ExternalLink, Icon } from '@newrelic/gatsby-theme-newrelic'; | ||
import usePageContext from '../../hooks/usePageContext'; | ||
|
||
const RelatedContent = ({ page }) => { | ||
const { site } = useStaticQuery(graphql` | ||
query { | ||
site { | ||
siteMetadata { | ||
repository | ||
} | ||
} | ||
} | ||
`); | ||
const { fileRelativePath } = usePageContext(); | ||
|
||
const { | ||
fields: { gitAuthorTime }, | ||
} = page; | ||
|
||
const { | ||
siteMetadata: { repository }, | ||
} = site; | ||
|
||
return ( | ||
<aside | ||
css={css` | ||
grid-area: related-content; | ||
position: sticky; | ||
top: calc(var(--global-header-height) + 2rem); | ||
align-self: start; | ||
@media (max-width: 1240px) { | ||
display: none; | ||
} | ||
`} | ||
> | ||
<h4>Contribute</h4> | ||
<Button | ||
as={ExternalLink} | ||
href={`${repository}/issues/new/choose`} | ||
css={css` | ||
margin-right: 0.5rem; | ||
`} | ||
variant={Button.VARIANT.PRIMARY} | ||
size={Button.SIZE.SMALL} | ||
> | ||
<Icon | ||
name={Icon.TYPE.GITHUB} | ||
css={css` | ||
margin-right: 0.5rem; | ||
`} | ||
/> | ||
File an issue | ||
</Button> | ||
<Button | ||
as={ExternalLink} | ||
href={`${repository}/tree/main/${fileRelativePath}`} | ||
variant={Button.VARIANT.NORMAL} | ||
size={Button.SIZE.SMALL} | ||
> | ||
<Icon | ||
name={Icon.TYPE.EDIT} | ||
css={css` | ||
margin-right: 0.5rem; | ||
`} | ||
/> | ||
Edit this page | ||
</Button> | ||
|
||
<div | ||
css={css` | ||
font-size: 0.875rem; | ||
font-style: italic; | ||
margin-top: 1rem; | ||
color: var(--color-neutrals-500); | ||
.dark-mode & { | ||
color: var(--color-dark-500); | ||
} | ||
`} | ||
> | ||
{`Page last modified on ${gitAuthorTime}`} | ||
</div> | ||
</aside> | ||
); | ||
}; | ||
|
||
RelatedContent.propTypes = { | ||
page: PropTypes.shape({ | ||
fields: PropTypes.shape({ | ||
gitAuthorTime: PropTypes.string, | ||
}), | ||
}), | ||
}; | ||
|
||
export const query = graphql` | ||
fragment RelatedContent_page on Mdx { | ||
fields { | ||
gitAuthorTime(formatString: "MMMM DD, YYYY") | ||
} | ||
} | ||
`; | ||
|
||
export default RelatedContent; |
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 @@ | ||
export { default } from './PageLayout'; |