-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Adding gatsby-plugin-styletron and an example site for it. #2365
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"env": { | ||
"browser": true | ||
}, | ||
"globals": { | ||
"graphql": false | ||
} | ||
} |
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,4 @@ | ||
# Using Styletron CSS-in-JS engine | ||
|
||
Read more on how to style components | ||
with [Styletron](http://styletron.js.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,15 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `Gatsby with Styletron`, | ||
}, | ||
plugins: [ | ||
`gatsby-plugin-styletron`, | ||
{ | ||
resolve: `gatsby-plugin-google-analytics`, | ||
options: { | ||
trackingId: `UA-93349937-2`, | ||
}, | ||
}, | ||
`gatsby-plugin-offline`, | ||
], | ||
} |
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,29 @@ | ||
{ | ||
"name": "gatsby-example-using-styletron", | ||
"private": true, | ||
"description": "Gatsby example site using the styletron plugin", | ||
"version": "1.0.0", | ||
"author": "Nadiia Dmytrenko <nadiia.dmytrenko@gmail.com>", | ||
"dependencies": { | ||
"gatsby": "latest", | ||
"gatsby-link": "latest", | ||
"gatsby-plugin-google-analytics": "latest", | ||
"gatsby-plugin-offline": "latest", | ||
"gatsby-plugin-styletron": "latest", | ||
"lodash": "^4.16.4", | ||
"react-typography": "^0.15.0", | ||
"slash": "^1.0.0", | ||
"styletron-react": "^3.0.0-rc.2", | ||
"typography": "^0.15.8", | ||
"typography-breakpoint-constants": "^0.14.0" | ||
}, | ||
"keywords": [ | ||
"gatsby" | ||
], | ||
"license": "MIT", | ||
"main": "n/a", | ||
"scripts": { | ||
"develop": "gatsby develop", | ||
"build": "gatsby build" | ||
} | ||
} |
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,64 @@ | ||
import React, { Component } from "react" | ||
import * as PropTypes from "prop-types" | ||
import { TypographyStyle } from "react-typography" | ||
import typography from "./utils/typography" | ||
|
||
let stylesStr | ||
if (process.env.NODE_ENV === `production`) { | ||
try { | ||
stylesStr = require(`!raw-loader!../public/styles.css`) | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
|
||
const propTypes = { | ||
headComponents: PropTypes.node.isRequired, | ||
body: PropTypes.node.isRequired, | ||
postBodyComponents: PropTypes.node.isRequired, | ||
} | ||
|
||
class Html extends Component { | ||
render() { | ||
let css | ||
if (process.env.NODE_ENV === `production`) { | ||
css = ( | ||
<style | ||
id="gatsby-inlined-css" | ||
dangerouslySetInnerHTML={{ __html: stylesStr }} | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<html op="news" lang="en"> | ||
<head> | ||
{this.props.headComponents} | ||
|
||
<meta name="referrer" content="origin" /> | ||
<meta charSet="utf-8" /> | ||
<meta name="description" content="Gatsby example site using Glamor" /> | ||
<meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0" | ||
/> | ||
<title>Gatsby Glamor</title> | ||
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. Same. |
||
<TypographyStyle typography={typography} /> | ||
{css} | ||
</head> | ||
<body> | ||
<div | ||
id="___gatsby" | ||
dangerouslySetInnerHTML={{ __html: this.props.body }} | ||
/> | ||
{this.props.postBodyComponents} | ||
</body> | ||
</html> | ||
) | ||
} | ||
} | ||
|
||
Html.propTypes = propTypes | ||
|
||
module.exports = Html |
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,43 @@ | ||
import React from "react" | ||
import {styled} from "styletron-react" | ||
|
||
// Create a Container element that'll render a <div> tag with some styles | ||
const Container = styled('div', { | ||
margin: `0 auto`, | ||
marginTop: `3rem`, | ||
padding: `1.5rem`, | ||
maxWidth: 800, | ||
color: `red`, | ||
}) | ||
|
||
// Create a Title element that'll render an <h1> tag with some styles | ||
const Title = styled('h1', { | ||
fontSize: `1.5em`, | ||
textAlign: `center`, | ||
color: `#744d9e`, | ||
}) | ||
|
||
// Create a Wrapper element that'll render a <section> tag with some styles | ||
const Wrapper = styled('div', { | ||
padding: `4em`, | ||
background: `#f5f3f7`, | ||
}) | ||
|
||
class IndexPage extends React.Component { | ||
render() { | ||
return ( | ||
<Container> | ||
<Wrapper> | ||
<Title>Hello World, this is my first component styled with Styletron!</Title> | ||
<p> | ||
<a href="https://www.gatsbyjs.org/packages/gatsby-plugin-styletron/"> | ||
gatsby-plugin-styletron docs | ||
</a> | ||
</p> | ||
</Wrapper> | ||
</Container> | ||
) | ||
} | ||
} | ||
|
||
export default IndexPage |
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,40 @@ | ||
import Typography from "typography" | ||
import { | ||
MOBILE_MEDIA_QUERY, | ||
TABLET_MEDIA_QUERY, | ||
} from "typography-breakpoint-constants" | ||
|
||
const options = { | ||
baseFontSize: `18px`, | ||
baseLineHeight: 1.45, | ||
blockMarginBottom: 0.75, | ||
scaleRatio: 2.15, | ||
overrideStyles: ({ rhythm, scale }, options) => { | ||
return { | ||
"h1,h2,h3,h4": { | ||
lineHeight: 1.2, | ||
}, | ||
[TABLET_MEDIA_QUERY]: { | ||
// Make baseFontSize on mobile 17px. | ||
html: { | ||
fontSize: `${17 / 16 * 100}%`, | ||
}, | ||
}, | ||
[MOBILE_MEDIA_QUERY]: { | ||
// Make baseFontSize on mobile 16px. | ||
html: { | ||
fontSize: `${16 / 16 * 100}%`, | ||
}, | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
const typography = new Typography(options) | ||
|
||
// Hot reload typography in development. | ||
if (process.env.NODE_ENV !== `production`) { | ||
typography.injectStyles() | ||
} | ||
|
||
export default typography |
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,5 @@ | ||
{ | ||
"presets": [ | ||
["../../.babelrc.js", { "browser": true }] | ||
] | ||
} |
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,5 @@ | ||
{ | ||
"rules": { | ||
"react/display-name": [0] | ||
} | ||
} |
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,2 +1,3 @@ | ||
/*.js | ||
!index.js | ||
/gatsby-node.js | ||
/gatsby-ssr.js | ||
/gatsby-browser.js |
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,17 @@ | ||
# gatsby-plugin-styletron | ||
|
||
Stub README | ||
A [Gatsby](https://github.com/gatsbyjs/gatsby) plugin for [styletron](https://github.com/rtsao/styletron) with built-in server-side rendering support. | ||
|
||
## Install | ||
|
||
`npm install --dev gatsby-plugin-styletron` | ||
|
||
## How to use | ||
|
||
Edit `gatsby-config.js` | ||
|
||
```javascript | ||
plugins: [ | ||
`gatsby-plugin-styletron`, | ||
] | ||
``` |
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,11 @@ | ||
const React = require(`react`) | ||
const Styletron = require(`styletron-client`) | ||
const { StyletronProvider } = require(`styletron-react`) | ||
|
||
const styletron = new Styletron() | ||
|
||
exports.wrapRootComponent = ({ Root }) => () => ( | ||
<StyletronProvider styletron={styletron}> | ||
<Root /> | ||
</StyletronProvider> | ||
) |
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,25 @@ | ||
const React = require(`react`) | ||
const Styletron = require(`styletron-server`) | ||
const { StyletronProvider } = require(`styletron-react`) | ||
const { renderToString } = require(`react-dom/server`) | ||
|
||
exports.replaceRenderer = ({ bodyComponent, setHeadComponents, replaceBodyHTMLString }) => { | ||
const styletron = new Styletron() | ||
|
||
const app = ( | ||
<StyletronProvider styletron={styletron}> | ||
{bodyComponent} | ||
</StyletronProvider> | ||
) | ||
|
||
replaceBodyHTMLString(renderToString(app)) | ||
|
||
const stylesheets = styletron.getStylesheets() | ||
const headComponents = stylesheets.map((sheet, index) => ( | ||
<style media={sheet.media || `all`} key={index}> | ||
{sheet.css} | ||
</style> | ||
)) | ||
|
||
setHeadComponents(headComponents) | ||
} |
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.
This should probably be updated to say
Styletron
instead ofGlamor
.