-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this also adds a new lifecycle callback "onInitialClientRender" to Browser API. It is called when the initial render of a Gatsby App is done on the client.
- Loading branch information
1 parent
84c4b77
commit f01497b
Showing
13 changed files
with
199 additions
and
9 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,6 @@ | ||
# Using JSS | ||
|
||
https://using-jss.gatsbyjs.org | ||
|
||
Example site that demonstrates how to build Gatsby sites | ||
with [JSS](http://cssinjs.org/). |
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 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `Gatsby with JSS`, | ||
}, | ||
plugins: [ | ||
`gatsby-plugin-jss`, | ||
], | ||
} |
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,22 @@ | ||
{ | ||
"name": "gatsby-example-using-jss", | ||
"private": true, | ||
"description": "Gatsby example site using the JSS plugin", | ||
"version": "1.0.0", | ||
"author": "Vladimir Guguiev <[email protected]>", | ||
"dependencies": { | ||
"gatsby": "latest", | ||
"gatsby-link": "latest", | ||
"gatsby-plugin-jss": "latest" | ||
}, | ||
"keywords": [ | ||
"gatsby" | ||
], | ||
"license": "MIT", | ||
"main": "n/a", | ||
"scripts": { | ||
"develop": "gatsby develop", | ||
"build": "gatsby build", | ||
"serve": "gatsby serve" | ||
} | ||
} |
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,45 @@ | ||
// @flow | ||
import React from "react" | ||
import Link from 'gatsby-link' | ||
import injectSheet from "react-jss" | ||
|
||
const styles = { | ||
heading: { | ||
padding: `10px`, | ||
backgroundColor: `darksalmon`, | ||
color: `white`, | ||
fontFamily: `monospace`, | ||
fontWeight: 300, | ||
}, | ||
main: { | ||
display: `flex`, | ||
justifyContent: `space-between`, | ||
fontFamily: `monospace`, | ||
}, | ||
footer: { | ||
marginTop: `15px`, | ||
backgroundColor: `azure`, | ||
fontFamily: `monospace`, | ||
}, | ||
} | ||
|
||
type Props = { | ||
classes: { [string]: string } | ||
} | ||
|
||
const DetailPage = ({ classes }: Props) => ( | ||
<div> | ||
<h1 className={classes.heading} >Detail page</h1> | ||
<main className={classes.main} > | ||
<Link to="/" >Go to Home page</Link> | ||
<a href="https://www.gatsbyjs.org/packages/gatsby-plugin-jss/"> | ||
gatsby-plugin-jss docs | ||
</a> | ||
</main> | ||
<footer className={classes.footer} > | ||
The styling on this page is implemented with JSS and it works even with disabled JavaScript | ||
</footer> | ||
</div> | ||
) | ||
|
||
export default injectSheet(styles)(DetailPage) |
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,45 @@ | ||
// @flow | ||
import React from "react" | ||
import Link from 'gatsby-link' | ||
import injectSheet from "react-jss" | ||
|
||
const styles = { | ||
heading: { | ||
padding: `10px`, | ||
backgroundColor: `darkturquoise`, | ||
color: `white`, | ||
fontFamily: `monospace`, | ||
fontWeight: 300, | ||
}, | ||
main: { | ||
display: `flex`, | ||
justifyContent: `space-between`, | ||
fontFamily: `monospace`, | ||
}, | ||
footer: { | ||
marginTop: `15px`, | ||
backgroundColor: `azure`, | ||
fontFamily: `monospace`, | ||
}, | ||
} | ||
|
||
type Props = { | ||
classes: { [string]: string } | ||
} | ||
|
||
const HomePage = ({ classes }: Props) => ( | ||
<div> | ||
<h1 className={classes.heading} >Home page</h1> | ||
<main className={classes.main} > | ||
<Link to="/detail" >Go to Detail page</Link> | ||
<a href="https://www.gatsbyjs.org/packages/gatsby-plugin-jss/"> | ||
gatsby-plugin-jss docs | ||
</a> | ||
</main> | ||
<footer className={classes.footer} > | ||
The styling on this page is implemented with JSS and it works even with disabled JavaScript | ||
</footer> | ||
</div> | ||
) | ||
|
||
export default injectSheet(styles)(HomePage) |
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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
# gatsby-plugin-jss | ||
|
||
Stub README | ||
Provide drop-in support for using the css-in-js library | ||
[JSS](https://github.com/cssinjs/react-jss) including server rendering. | ||
|
||
## Install | ||
|
||
`npm install --save gatsby-plugin-jss` | ||
|
||
## How to use | ||
|
||
First add the plugin to your `gatsby-config.js`. | ||
|
||
```javascript | ||
plugins: [ | ||
`gatsby-plugin-jss`, | ||
] | ||
``` | ||
|
||
## Example | ||
|
||
https://github.com/gatsbyjs/gatsby/tree/master/examples/using-jss |
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
Empty file.
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,6 @@ | ||
// remove the JSS style tag generated on the server to avoid conflicts with the one added on the client | ||
exports.onInitialClientRender = () => { | ||
// eslint-disable-next-line no-undef | ||
const ssStyles = window.document.getElementById(`server-side-jss`) | ||
ssStyles && ssStyles.parentNode.removeChild(ssStyles) | ||
} |
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,20 @@ | ||
import React from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
import { JssProvider, SheetsRegistry } from 'react-jss' | ||
|
||
exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) => { | ||
const sheets = new SheetsRegistry() | ||
|
||
const bodyHTML = renderToString( | ||
<JssProvider registry={sheets}> | ||
{bodyComponent} | ||
</JssProvider> | ||
) | ||
|
||
replaceBodyHTMLString(bodyHTML) | ||
setHeadComponents([ | ||
<style type="text/css" id="server-side-jss"> | ||
{sheets.toString()} | ||
</style>, | ||
]) | ||
} |
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