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

refactor(www): Move base layout component into layouts plugin #21478

Merged
merged 11 commits into from
Feb 27, 2020
20 changes: 8 additions & 12 deletions www/src/components/guidelines/layout.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import React from "react"
import PropTypes from "prop-types"
import { Helmet } from "react-helmet"
import { Global } from "@emotion/core"

import BaseLayout from "../layout"
import { globalStyles } from "../../utils/styles/global"
import { Box } from "./system"
import Header from "./header"
import Footer from "../shared/footer-links"

const Layout = ({ children, background, location, pageTitle }) => (
<BaseLayout location={location}>
const Layout = ({ children, background, pageTitle }) => (
<Box bg="background" position="relative">
<Global
styles={{
".ReactModal__Overlay": {
Expand All @@ -34,15 +32,13 @@ const Layout = ({ children, background, location, pageTitle }) => (
<Helmet>
<title>{pageTitle ? `${pageTitle} | Guidelines` : `Guidelines`}</title>
</Helmet>
<Box bg="background" position="relative">
{background && background}
<Header />
<Box as="main" className="main-body">
{children}
<Footer />
</Box>
{background && background}
<Header />
<Box as="main" className="main-body">
{children}
<Footer />
</Box>
</BaseLayout>
</Box>
)

Layout.propTypes = {
Expand Down
29 changes: 13 additions & 16 deletions www/src/components/layout/layout-with-heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@ import { jsx } from "theme-ui"
import PropTypes from "prop-types"

import PageHeading from "./page-heading"
import BaseLayout from "../layout"
import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org"

const LayoutWithHeading = props => {
const { children, location, pageTitle = ``, pageIcon } = props
const { children, pageTitle = ``, pageIcon } = props

return (
<BaseLayout location={location}>
<div
sx={{
pb: t => t.fontSizes[10],
<div
sx={{
pb: t => t.fontSizes[10],

[mediaQueries.md]: {
ml: t => t.sizes.pageHeadingDesktopWidth,
pb: 0,
},
}}
>
{pageTitle && <PageHeading title={pageTitle} icon={pageIcon} />}
{children}
</div>
</BaseLayout>
[mediaQueries.md]: {
ml: t => t.sizes.pageHeadingDesktopWidth,
pb: 0,
},
}}
>
{pageTitle && <PageHeading title={pageTitle} icon={pageIcon} />}
{children}
</div>
)
}

Expand Down
9 changes: 4 additions & 5 deletions www/src/components/showcase-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Img from "gatsby-image"
import qs from "qs"

import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org"
import Layout from "../components/layout"
import Modal from "../components/modal"
import ShareMenu from "../components/share-menu"
import Button from "../components/button"
Expand Down Expand Up @@ -140,7 +139,8 @@ function getExitLocation(filters = {}) {
}
}

function ShowcaseModal({ children, location }) {
function ShowcaseModal({ children, location, isModal }) {
if (!isModal) return children
const { previousSite, nextSite } = usePrevAndNextSite(location.pathname)
const { filters } = location.state || {}
return (
Expand Down Expand Up @@ -245,9 +245,8 @@ function ShowcaseModal({ children, location }) {
const ShowcaseDetails = ({ location, site, isModal, categories }) => {
const screenshotFile = site.childScreenshot.screenshotFile.childImageSharp

const PageLayout = isModal ? ShowcaseModal : Layout
return (
<PageLayout location={location}>
<ShowcaseModal isModal={isModal} location={location}>
<div
sx={{
display: `flex`,
Expand Down Expand Up @@ -395,7 +394,7 @@ const ShowcaseDetails = ({ location, site, isModal, categories }) => {
</div>
</div>
</div>
</PageLayout>
</ShowcaseModal>
)
}

Expand Down
17 changes: 15 additions & 2 deletions www/src/layouts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
export default function Layout({ children }) {
return children
/** @jsx jsx */
import { jsx } from "theme-ui"
import BaseLayout from "../components/layout"
import { getLocaleAndBasePath } from "../utils/i18n"

export default function Layout({ location, children }) {
if (location.state && location.state.isModal) {
return children
}
const { locale } = getLocaleAndBasePath(location.pathname)
return (
<BaseLayout location={location} locale={locale}>
{children}
</BaseLayout>
)
}
33 changes: 13 additions & 20 deletions www/src/pages/404.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import React from "react"
import Container from "../components/container"
import Layout from "../components/layout"
import { Link } from "gatsby"
import FooterLinks from "../components/shared/footer-links"

class FourOhFour extends React.Component {
render() {
return (
<Layout location={this.props.location}>
<Container>
<h1>Page not found</h1>
<p>
Oops! The page you are looking for has been removed or relocated.
</p>
<Link to="/">
<p>Go Back</p>
</Link>
</Container>
<FooterLinks />
</Layout>
)
}
export default function FourOhFour() {
return (
<>
<Container>
<h1>Page not found</h1>
<p>Oops! The page you are looking for has been removed or relocated.</p>
<Link to="/">
<p>Go Back</p>
</Link>
</Container>
<FooterLinks />
</>
)
}

export default FourOhFour
Loading