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

Question about gatsby-plugin-styled-components #2893

Closed
fermartz opened this issue Nov 11, 2017 · 3 comments
Closed

Question about gatsby-plugin-styled-components #2893

fermartz opened this issue Nov 11, 2017 · 3 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@fermartz
Copy link

fermartz commented Nov 11, 2017

First of all, thanks to all the contributors of GATSBY, I love it! My question is very simple but I couldn't find any posting with the answer.

How can I inject global styles for gatsby-plugin-styled-components if I'm not using Typography.js?
For example:
Where do I inject the following code?

injectGlobal`
  * { box-sizing: border-box; }
  body { margin: 0; color: #374047}
`

Thanks in advance!

@dustinhorton
Copy link
Contributor

dustinhorton commented Nov 12, 2017

Unless I'm misunderstanding (and this truly needs to be done differently with styled components), the HN site example shows how this can be achieved:

import "../css/news.css"

edit: I hadn't realized injectGlobal was a styled components method, but I see it @ https://www.styled-components.com/docs/api. Curious why you'd need this in a Gatsby app where it'll easily handle just authoring a stylesheet.

@fermartz
Copy link
Author

fermartz commented Nov 12, 2017

@dustinhorton thanks.
I created a layout folder with an index.js file. I then injected the following global styles and it worked like a charm :-)

import React from "react"

import { injectGlobal } from 'styled-components'

injectGlobal`
*,
*::after,
*::before {
  margin: 0;
  padding: 0;
  box-sizing: inherit; }

html {
  font-size: 62.5%; }

body {
  box-sizing: border-box; }

body {
  font-family: "Lato", sans-serif;
  font-weight: 400;
  line-height: 1.7;
  color: #374047; }
`

export default ({children}) =>
 <div>
     {children()}
 </div>

@fernandes
Copy link

@fermartz maybe this issue can be closed? :)

@fk fk added type: question or discussion Issue discussing or asking a question about Gatsby API/Plugins labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants