Skip to content
This repository has been archived by the owner before Nov 9, 2022. It is now read-only.

josefaidt/gatsby-styled-components-theme-demo

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Gatsby, styled-components Theme demo

Demo using Gatsby, styled-components, and wrapping the root element to use ThemeProvider

Setup

// gastby-browser.js
import React from 'react'
import { ThemeProvider } from 'styled-components'

const theme = {
  main: '#c6797e',
}
export const wrapRootElement = ({ element }) => (
  <ThemeProvider theme={theme}>{element}</ThemeProvider>
)
// src/components/layout.js
import React from 'react'
import PropTypes from 'prop-types'
import { useStaticQuery, graphql } from 'gatsby'
import styled from 'styled-components'
import Header from './header'
import './layout.css'

const Container = styled.div`
  background-color: ${props => props.theme.main};
  margin: 0 auto;
  max-width: 960px;
  padding: 0px 1.0875rem 1.45rem;
  padding-top: 0;
`

const Layout = ({ children }) => {
  const data = useStaticQuery(graphql`
    query SiteTitleQuery {
      site {
        siteMetadata {
          title
        }
      }
    }
  `)

  return (
    <>
      <Header siteTitle={data.site.siteMetadata.title} />
      <Container>
        <main>{children}</main>
        <footer>
          © {new Date().getFullYear()}, Built with
          {` `}
          <a href="https://www.gatsbyjs.org">Gatsby</a>
        </footer>
      </Container>
    </>
  )
}

Layout.propTypes = {
  children: PropTypes.node.isRequired,
}

export default Layout

About

Demo using Gatsby + styled-components's ThemeProvider

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published