-
Notifications
You must be signed in to change notification settings - Fork 192
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
Move site nav into a menu on smaller screens #234
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
84c3b33
Add basic mobile menu implementation
andrewiggins 490df76
Prevent re-building the page content DOM on layout rerender
andrewiggins d2ccaac
Add community links to mobile nav
andrewiggins b233341
Merge branch 'master' into mobile-menu
andrewiggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,23 @@ | ||
import React from 'react' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faDiscord, faGithub } from '@fortawesome/free-brands-svg-icons' | ||
|
||
export default function CommunityLinks({ githubURL, className = '' }) { | ||
return ( | ||
<div className={'community-links ' + className}> | ||
<a href={githubURL} target="_blank" rel="noreferrer noopener" style={{ color: 'inherit' }}> | ||
<FontAwesomeIcon style={{ marginRight: '0.2em' }} icon={faGithub} /> GitHub | ||
</a> | ||
|
||
<a | ||
href="https://discord.gg/DEWjhSw" | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
style={{ color: 'inherit' }} | ||
> | ||
<FontAwesomeIcon style={{ marginRight: '0.2em', marginLeft: '1em' }} icon={faDiscord} />{' '} | ||
Discord | ||
</a> | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -56,12 +56,11 @@ const components = { | |
} | ||
|
||
const Layout = ({ children, pageContext }) => { | ||
const { frontmatter } = pageContext || {} | ||
const [opened, setOpen] = React.useState(false) | ||
const onToggleMenu = React.useCallback(() => setOpen((opened) => !opened), [setOpen]) | ||
|
||
const ContentWrapper = | ||
frontmatter && frontmatter.path && frontmatter.path.startsWith('/components/') | ||
? ComponentLayout | ||
: ({ children }) => <>{children}</> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line was effectively creating a new component on each render of Layout, causing React to rebuild the page each time the menu was toggled. Fixed it by just rendering children directly instead of wrapping them in a function. |
||
const { frontmatter } = pageContext || {} | ||
const useComponentLayout = frontmatter?.path?.startsWith('/components/') ?? false | ||
|
||
return ( | ||
<StaticQuery | ||
|
@@ -82,19 +81,18 @@ const Layout = ({ children, pageContext }) => { | |
<Header | ||
siteTitle={data.site.siteMetadata.title} | ||
githubURL={data.site.siteMetadata.githubURL} | ||
menuOpened={opened} | ||
onToggleMenu={onToggleMenu} | ||
/> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
padding: '0 1rem', | ||
margin: '0 auto', | ||
maxWidth: '1200px', | ||
}} | ||
> | ||
<Navigation style={{ marginRight: '2em' }} /> | ||
<div className="page-wrapper"> | ||
<Navigation opened={opened} githubURL={data.site.siteMetadata.githubURL} /> | ||
|
||
<div style={{ flex: '1 1 auto', minWidth: 0 }}> | ||
<ContentWrapper frontmatter={frontmatter}>{children}</ContentWrapper> | ||
<div className="page-content" style={{ flex: '1 1 auto', minWidth: 0 }}> | ||
{useComponentLayout ? ( | ||
<ComponentLayout frontmatter={frontmatter}>{children}</ComponentLayout> | ||
) : ( | ||
children | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose 640px semi-randomly (I just used the various device emulations devtools has to see what looked good on that sampling of devices). I imagine people here have done much more research on this so feedback here would be appreciated!