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

[v2] Implement RFC #2 removing special layout component #4887

Merged
merged 20 commits into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .babel-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function preset(context, options = {}) {
],
plugins: [
r("@babel/plugin-proposal-class-properties"),
r("@babel/plugin-proposal-optional-chaining"),
[
r("@babel/plugin-transform-runtime"),
{
Expand Down
2 changes: 1 addition & 1 deletion Breaking Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* Remove explicit polyfill and use the new builtins: usage support in babel 7.
* Changed `modifyBabelrc` to `onCreateBabelConfig`
* Changed `modifyWebpackConfig` to `onCreateWebpackConfig`
* inlining css changed — remove it as done automatically by core now.
* inlining css changed — remove it from any custom html.js as done automatically by core now.
4 changes: 2 additions & 2 deletions docs/docs/api-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ See
## Concepts

* _Page_ — a site page with a pathname, a template component, and optional
graphql query and layout component
graphql query.
* _Page Component_ — React.js component that renders a page and can optionally
specify a layout component and a graphql query
specify a graphql query
* _Component extensions_ — extensions that are resolvable as components. `.js`
and `.jsx` are supported by core. But plugins can add support for other
compile-to-js languages.
Expand Down
30 changes: 1 addition & 29 deletions docs/docs/building-with-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ A basic directory structure of a project might look like this:
   │      └── 01-03-2017
   │         └── index.md
   ├── templates
   │ └── post.jsx
└── layouts
└── index.jsx
   └── post.jsx
```

### Page components
Expand Down Expand Up @@ -117,31 +114,6 @@ export const pageQuery = graphql`
`;
```

### Layout components

`src/layouts/index.jsx` (optional) wraps page components. You can use it for
portions of pages that are shared across pages like headers and footers.

You can use the `location` prop to render conditionally based on the page
URL.

Example:

```jsx
import React from "react";
import Navigation from "../components/Navigation/Navigation.jsx";

export default class Template extends React.Component {
render() {
if (this.props.location.pathname !== "/") {
return <Navigation>{this.props.children()}</Navigation>;
} else {
return this.props.children();
}
}
}
```

### HTML component

`src/html.jsx` is responsible for everything other than where Gatsby lives in
Expand Down
32 changes: 0 additions & 32 deletions docs/docs/creating-and-modifying-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ exports.createPages = ({ boundActionCreators, graphql }) => {
createPage({
path,
component: blogPostTemplate,
// If you have a layout component at src/layouts/blog-layout.js
layout: `blog-layout`,
// In your blog post template's graphql query, you can use path
// as a GraphQL variable to query for data from the markdown file.
context: {
Expand Down Expand Up @@ -133,33 +131,3 @@ exports.onCreatePage = ({ page, boundActionCreators }) => {
});
};
```

### Choosing the page layout

By default, all pages will use the layout found at `/layouts/index.js`.

You may wish to choose a custom layout for certain pages (such as removing
header and footer for landing pages). You can choose the layout component when
creating pages with the `createPage` action by adding a layout key to the page
object or modify pages created elsewhere using the `onCreatePage` API. All
components in the `/layouts/` directory are automatically available.

```javascript
// Implement the Gatsby API “onCreatePage”. This is
// called after every page is created.
exports.onCreatePage = async ({ page, boundActionCreators }) => {
const { createPage } = boundActionCreators;

return new Promise((resolve, reject) => {
if (page.path.match(/^\/landing-page/)) {
// It's assumed that `landingPage.js` exists in the `/layouts/` directory
page.layout = "landingPage";

// Update the page.
createPage(page);
}

resolve();
});
};
```
5 changes: 2 additions & 3 deletions examples/client-only-paths/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ module.exports = {
},
plugins: [
{
resolve: `gatsby-plugin-google-analytics`,
resolve: `gatsby-plugin-typography`,
options: {
trackingId: `UA-93349937-2`,
pathToConfigModule: `src/utils/typography`,
},
},
`gatsby-plugin-offline`,
],
}
16 changes: 8 additions & 8 deletions examples/client-only-paths/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"version": "1.0.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
"gatsby": "latest",
"gatsby-plugin-google-analytics": "latest",
"gatsby-plugin-offline": "latest",
"gatsby-source-drupal": "latest",
"gatsby": "canary",
"gatsby-plugin-typography": "canary",
"lodash": "^4.16.4",
"react": "^16.3.1",
"react-addons-css-transition-group": "^15.5.2",
"react-typography": "^0.15.0",
"react-dom": "^16.3.1",
"react-typography": "^0.16.13",
"slash": "^1.0.0",
"typography": "^0.15.8",
"typography-breakpoint-constants": "^0.14.0"
"typography": "^0.16.6",
"typography-breakpoint-constants": "^0.15.10"
},
"keywords": [
"gatsby"
Expand All @@ -25,4 +25,4 @@
"develop": "gatsby develop",
"build": "gatsby build"
}
}
}
67 changes: 0 additions & 67 deletions examples/client-only-paths/src/html.js

This file was deleted.

5 changes: 3 additions & 2 deletions examples/client-only-paths/src/layouts/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react"
import { Link } from "gatsby"

import { rhythm } from "../utils/typography"
import typography from "../utils/typography"
const { rhythm } = typography

class DefaultLayout extends React.Component {
render() {
Expand All @@ -21,7 +22,7 @@ class DefaultLayout extends React.Component {
Example of adding client only paths
</h3>
</Link>
{this.props.children()}
{this.props.children}
</div>
)
}
Expand Down
69 changes: 36 additions & 33 deletions examples/client-only-paths/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,54 @@ import ReactCSSTransitionGroup from "react-addons-css-transition-group"
import { Route, Redirect } from "react-router-dom"

import "./main.css"
import Layout from "../layouts"

class AnimationExample extends React.Component {
render() {
return (
<div style={{ position: `relative`, minHeight: `80vh` }}>
<Route
render={({ location }) => (
<div style={styles.fill}>
<Route
exact
path="/"
render={() => <Redirect to="/10/90/50" />}
/>
<Layout>
<div style={{ position: `relative`, minHeight: `80vh` }}>
<Route
render={({ location }) => (
<div style={styles.fill}>
<Route
exact
path="/"
render={() => <Redirect to="/10/90/50" />}
/>

<ul style={styles.nav}>
<NavLink to="/10/90/50">Red</NavLink>
<NavLink to="/120/100/40">Green</NavLink>
<NavLink to="/200/100/40">Blue</NavLink>
<NavLink to="/310/100/50">Pink</NavLink>
</ul>
<ul style={styles.nav}>
<NavLink to="/10/90/50">Red</NavLink>
<NavLink to="/120/100/40">Green</NavLink>
<NavLink to="/200/100/40">Blue</NavLink>
<NavLink to="/310/100/50">Pink</NavLink>
</ul>

<div style={styles.content}>
<ReactCSSTransitionGroup
transitionName="fade"
transitionEnterTimeout={300}
transitionLeaveTimeout={300}
>
{/* no different than other usage of
<div style={styles.content}>
<ReactCSSTransitionGroup
transitionName="fade"
transitionEnterTimeout={300}
transitionLeaveTimeout={300}
>
{/* no different than other usage of
ReactCSSTransitionGroup, just make
sure to pass `location` to `Route`
so it can match the old location
as it animates out
*/}
<Route
location={location}
key={location.key}
path="/:h/:s/:l"
component={HSL}
/>
</ReactCSSTransitionGroup>
<Route
location={location}
key={location.key}
path="/:h/:s/:l"
component={HSL}
/>
</ReactCSSTransitionGroup>
</div>
</div>
</div>
)}
/>
</div>
)}
/>
</div>
</Layout>
)
}
}
Expand Down
4 changes: 0 additions & 4 deletions examples/gatsbygram/.babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions examples/gatsbygram/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ exports.shouldUpdateScroll = args => {
return false
}
}

exports.onInitialClientRender = () => {
window.___GATSBYGRAM_INITIAL_RENDER_COMPLETE = true
}
6 changes: 6 additions & 0 deletions examples/gatsbygram/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ module.exports = {
trackingId: `UA-91652198-1`,
},
},
{
resolve: `gatsby-plugin-typography`,
options: {
pathToConfigModule: `src/utils/typography`,
},
},
],
}
Loading