From 9f8ddb66c584146b1f4021b5fb0757313f549411 Mon Sep 17 00:00:00 2001 From: Nat Alison Date: Fri, 14 Feb 2020 14:35:36 -0800 Subject: [PATCH] refactor(www): Move out pageWithSidebar from layout (#21333) * Move out pageWithSidebar from layout and into the templates/pages that actually need it. * update based on recent merges * doh * dont generate sidebar if itemlist doenst exist * fix stuff * get rid of unneeded import * remove enableScrollSync prop --- www/src/components/layout.js | 20 +-- www/src/components/page-with-sidebar.js | 63 ++++---- www/src/pages/features.js | 57 +++---- www/src/pages/features/cms.js | 109 +++++++------ www/src/pages/features/jamstack.js | 105 ++++++------ www/src/templates/template-api-markdown.js | 86 +++++----- www/src/templates/template-docs-markdown.js | 152 +++++++++--------- .../templates/template-feature-comparison.js | 75 ++++----- 8 files changed, 335 insertions(+), 332 deletions(-) diff --git a/www/src/components/layout.js b/www/src/components/layout.js index 982dde759e891..2879442ac84b5 100644 --- a/www/src/components/layout.js +++ b/www/src/components/layout.js @@ -4,13 +4,11 @@ import React from "react" import { Global } from "@emotion/core" -import { getItemList } from "../utils/sidebar/item-list" import { globalStyles } from "../utils/styles/global" import { breakpointGutter } from "../utils/styles" import Banner from "../components/banner" import Navigation from "../components/navigation" import MobileNavigation from "../components/navigation-mobile" -import PageWithSidebar from "../components/page-with-sidebar" import SiteMetadata from "../components/site-metadata" import SkipNavLink from "../components/skip-nav-link" import "../assets/fonts/futura" @@ -18,15 +16,7 @@ import { defaultLang } from "../utils/i18n" export const LocaleContext = React.createContext(defaultLang) -export default function DefaultLayout({ - location, - locale, - enableScrollSync, - children, -}) { - const itemList = getItemList(location.pathname) - const isSidebarDisabled = !itemList - +export default function DefaultLayout({ location, locale, children }) { return ( @@ -47,13 +37,7 @@ export default function DefaultLayout({ }, }} > - children} - /> + {children} diff --git a/www/src/components/page-with-sidebar.js b/www/src/components/page-with-sidebar.js index d516adaf77721..77c0d7940352c 100644 --- a/www/src/components/page-with-sidebar.js +++ b/www/src/components/page-with-sidebar.js @@ -2,38 +2,39 @@ import { jsx } from "theme-ui" import { Fragment } from "react" +import { getItemList } from "../utils/sidebar/item-list" import StickyResponsiveSidebar from "./sidebar/sticky-responsive-sidebar" -export default props => { - if (props.disable) { - return props.renderContent() - } else { - return ( - -
t.sizes.sidebarWidth.default, - t => t.sizes.sidebarWidth.large, - ], - }} - > - {props.renderContent()} -
- -
- ) +export default ({ children, enableScrollSync, location }) => { + const itemList = getItemList(location.pathname) + if (!itemList) { + return children } + return ( + +
t.sizes.sidebarWidth.default, + t => t.sizes.sidebarWidth.large, + ], + }} + > + {children} +
+ +
+ ) } diff --git a/www/src/pages/features.js b/www/src/pages/features.js index 51738fb7e170d..daad8d9620a3c 100644 --- a/www/src/pages/features.js +++ b/www/src/pages/features.js @@ -11,6 +11,7 @@ import FooterLinks from "../components/shared/footer-links" import LegendTable from "../components/features/legend-table" import FeaturesFooter from "../components/features/features-footer" import SimpleEvaluationTable from "../components/features/simple-evaluation-table" +import PageWithSidebar from "../components/page-with-sidebar" const FeaturesHeader = () => (
@@ -104,34 +105,36 @@ const FeaturesHeader = () => ( class FeaturesPage extends Component { render() { return ( - - - Features - - - -
- - + + + Features + - -
- -
+ + +
+ + + +
+ +
+
) } diff --git a/www/src/pages/features/cms.js b/www/src/pages/features/cms.js index 1493150e35fa2..32a8491b39372 100644 --- a/www/src/pages/features/cms.js +++ b/www/src/pages/features/cms.js @@ -4,6 +4,7 @@ import { graphql } from "gatsby" import Button from "../../components/button" import Layout from "../../components/layout" +import PageWithSidebar from "../../components/page-with-sidebar" import EvaluationTable from "../../components/features/evaluation-table" import { getFeaturesData } from "../../utils/get-csv-features-data" import Container from "../../components/container" @@ -35,60 +36,62 @@ const CmsFeaturesPage = ({ data, location }) => { ) return ( - - -
- - -

Comparison

-

- To see a filtered view of Gatsby compared with specific CMS - technologies, choose the technologies to compare and then press - Compare: -

-
-
- {featureComparisonOptions.cms.map( - ({ key: optionKey, display }) => ( - - {display} - - ) - )} + + + +
+ + +

Comparison

+

+ To see a filtered view of Gatsby compared with specific CMS + technologies, choose the technologies to compare and then press + Compare: +

+
+
+ {featureComparisonOptions.cms.map( + ({ key: optionKey, display }) => ( + + {display} + + ) + )} +
+
- -
- - - -
- -
+ + + + + + +
) } diff --git a/www/src/pages/features/jamstack.js b/www/src/pages/features/jamstack.js index 5cd9463d21d65..f64528a9e1891 100644 --- a/www/src/pages/features/jamstack.js +++ b/www/src/pages/features/jamstack.js @@ -14,6 +14,7 @@ import CompareButton from "../../components/features/compare-button" import Breadcrumb from "../../components/docs-breadcrumb" import featureComparisonOptions from "../../data/features/comparison-options.json" import useComparisonState from "../../hooks/use-comparison-state" +import PageWithSidebar from "../../components/page-with-sidebar" const FeaturesHeader = () => (
@@ -38,58 +39,60 @@ const JamstackFeaturesPage = ({ data, location }) => { ) return ( - - -
- - -

Comparison

-

- To see a filtered view of Gatsby with specific JAMstack - technologies, choose the technologies to compare and then press - Compare: -

+ + + +
+ + +

Comparison

+

+ To see a filtered view of Gatsby with specific JAMstack + technologies, choose the technologies to compare and then press + Compare: +

-
- {featureComparisonOptions.jamstack.map( - ({ key: optionKey, display }) => ( - - {display} - - ) - )} -
- - - -
- -
+
+ {featureComparisonOptions.jamstack.map( + ({ key: optionKey, display }) => ( + + {display} + + ) + )} +
+ + + +
+ +
+
) } diff --git a/www/src/templates/template-api-markdown.js b/www/src/templates/template-api-markdown.js index a40acc1e32647..837976caf1d8a 100644 --- a/www/src/templates/template-api-markdown.js +++ b/www/src/templates/template-api-markdown.js @@ -4,13 +4,13 @@ import React from "react" import { Helmet } from "react-helmet" import { graphql } from "gatsby" import { MDXRenderer } from "gatsby-plugin-mdx" -import theme from "../gatsby-plugin-theme-ui" +import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org" // API Rendering Stuff import { sortBy } from "lodash-es" import Layout from "../components/layout" -import { itemListDocs } from "../utils/sidebar/item-list" +import PageWithSidebar from "../components/page-with-sidebar" import MarkdownPageFooter from "../components/markdown-page-footer" import DocSearchContent from "../components/docsearch-content" import FooterLinks from "../components/shared/footer-links" @@ -96,45 +96,49 @@ export default function APITemplate({ data, location, pageContext }) { - - - - -

- {page.frontmatter.title} -

-
- -
- {page.body} -

{page.frontmatter.contentsHeading || "APIs"}

- -

Reference

- - - -
-
-
- + + + + + +

+ {page.frontmatter.title} +

+
+ +
+ {page.body} +

{page.frontmatter.contentsHeading || "APIs"}

+ +

Reference

+ + + +
+
+
+ +
) diff --git a/www/src/templates/template-docs-markdown.js b/www/src/templates/template-docs-markdown.js index b801825b14a3f..0727ecc6b66fa 100644 --- a/www/src/templates/template-docs-markdown.js +++ b/www/src/templates/template-docs-markdown.js @@ -7,6 +7,7 @@ import { MDXRenderer } from "gatsby-plugin-mdx" import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org" import Layout from "../components/layout" +import PageWithSidebar from "../components/page-with-sidebar" import MarkdownPageFooter from "../components/markdown-page-footer" import DocSearchContent from "../components/docsearch-content" import TableOfContents from "../components/docs-table-of-contents" @@ -46,87 +47,88 @@ function DocsTemplate({ data, location, pageContext: { next, prev } }) { - - - - -

- {page.frontmatter.title} -

-
- - {toc && ( + + + + + +

+ {page.frontmatter.title} +

+
+ + {toc && ( +
+ `calc(${t.sizes.headerHeight} + ${t.sizes.bannerHeight} + ${t.space[9]})`, + maxHeight: t => + `calc(100vh - ${t.sizes.headerHeight} - ${t.sizes.bannerHeight} - ${t.space[9]} - ${t.space[9]})`, + overflow: `auto`, + }, + }} + > + +
+ )}
- `calc(${t.sizes.headerHeight} + ${t.sizes.bannerHeight} + ${t.space[9]})`, - maxHeight: t => - `calc(100vh - ${t.sizes.headerHeight} - ${t.sizes.bannerHeight} - ${t.space[9]} - ${t.space[9]})`, - overflow: `auto`, + [page.tableOfContents.items && mediaQueries.xl]: { + maxWidth: `mainContentWidth.withSidebar`, + minWidth: 0, }, }} > - -
- )} -
-
- {page.body} - {page.frontmatter.issue && ( - - See the issue relating to this stub on GitHub - - )} - - +
+ {page.body} + {page.frontmatter.issue && ( + + See the issue relating to this stub on GitHub + + )} + + +
-
-
-
- +
+
+ +
) diff --git a/www/src/templates/template-feature-comparison.js b/www/src/templates/template-feature-comparison.js index 8b767b1cde01e..b3c2d619bd99c 100644 --- a/www/src/templates/template-feature-comparison.js +++ b/www/src/templates/template-feature-comparison.js @@ -4,6 +4,7 @@ import { Component } from "react" import { Helmet } from "react-helmet" import { css } from "@emotion/core" import Layout from "../components/layout" +import PageWithSidebar from "../components/page-with-sidebar" import FooterLinks from "../components/shared/footer-links" import Container from "../components/container" import EvaluationTable from "../components/features/evaluation-table" @@ -33,44 +34,46 @@ class FeatureComparison extends Component { return ( - - {titleString} - - -
- -

{titleString}

- {options.map(o => ( -
-

- + + {titleString} + + +
+ +

{titleString}

+ {options.map(o => ( +
+

- {o.display} -

- {o.description} -
- ))} - - -
- - -
+ > + + {o.display} +

+ {o.description} +
+ ))} + + +
+ + +
+
) }