Skip to content

Commit

Permalink
Add styled-components example site
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Jun 2, 2017
1 parent a6f779d commit 589120f
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/using-glamor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-example-using-drupal",
"name": "gatsby-example-using-glamor",
"private": true,
"description": "Gatsby example site using the Drupal source plugin",
"description": "Gatsby example site using the Glamor plugin",
"version": "1.0.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions examples/using-styled-components/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"browser": true
},
"globals": {
"graphql": false
}
}
6 changes: 6 additions & 0 deletions examples/using-styled-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Using Drupal

https://using-drupal.gatsbyjs.org

Example site that demostrates how to build Gatsby sites
that pull data from the [Drupal CMS](https://www.drupal.org/).
15 changes: 15 additions & 0 deletions examples/using-styled-components/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
siteMetadata: {
title: `Gatsby with styled components`,
},
plugins: [
`gatsby-plugin-styled-components`,
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: `UA-93349937-2`,
},
},
`gatsby-plugin-offline`,
],
}
28 changes: 28 additions & 0 deletions examples/using-styled-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "gatsby-example-using-styled-components",
"private": true,
"description": "Gatsby example site using the styled components plugin",
"version": "1.0.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
"gatsby": "canary",
"gatsby-link": "canary",
"gatsby-plugin-google-analytics": "canary",
"gatsby-plugin-offline": "canary",
"gatsby-plugin-styled-components": "canary",
"lodash": "^4.16.4",
"react-typography": "^0.15.0",
"slash": "^1.0.0",
"typography": "^0.15.8",
"typography-breakpoint-constants": "^0.14.0"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"main": "n/a",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build"
}
}
53 changes: 53 additions & 0 deletions examples/using-styled-components/src/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react"
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)
}
}

module.exports = React.createClass({
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>
<TypographyStyle typography={typography} />
{css}
</head>
<body>
<div
id="___gatsby"
dangerouslySetInnerHTML={{ __html: this.props.body }}
/>
{this.props.postBodyComponents}
</body>
</html>
)
},
})
39 changes: 39 additions & 0 deletions examples/using-styled-components/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react"
import styled from "styled-components"

// Create a Title component that'll render an <h1> tag with some styles
const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
`

// Create a Wrapper component that'll render a <section> tag with some styles
const Wrapper = styled.section`
padding: 4em;
background: papayawhip;
`

class IndexPage extends React.Component {
render() {
return (
<div
style={{
margin: `0 auto`,
marginTop: `3rem`,
padding: `1.5rem`,
maxWidth: 800,
color: `red`,
}}
>
<Wrapper>
<Title>
Hello World, this is my first styled component!
</Title>
</Wrapper>
</div>
)
}
}

export default IndexPage
40 changes: 40 additions & 0 deletions examples/using-styled-components/src/utils/typography.js
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

0 comments on commit 589120f

Please sign in to comment.