Repository navigation
Add styled-components, config #121
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,15 +1,28 @@ | ||||
| { | ||||
| "presets": ["next/babel"], | ||||
| "presets": [ | ||||
| "next/babel" | ||||
| ], | ||||
| "plugins": [ | ||||
| [ | ||||
| "module-resolver", | ||||
| { | ||||
| "root": ["."], | ||||
| "root": [ | ||||
| "." | ||||
| ], | ||||
| "alias": { | ||||
| "client": "./client", | ||||
| "server": "./server" | ||||
| "server": "./server", | ||||
| "styles": "./styles" | ||||
| } | ||||
| } | ||||
| ], | ||||
| [ | ||||
| "styled-components", | ||||
| { | ||||
| "ssr": true, | ||||
| "displayName": true, | ||||
| "preprocess": false | ||||
| } | ||||
| ] | ||||
| ] | ||||
| } | ||||
| } | ||||
|
Member
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.
Suggested change
|
||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import App from 'next/app'; | ||
| import React from 'react'; | ||
| import { ThemeProvider } from 'styled-components'; | ||
| import theme from 'styles/theme'; | ||
|
|
||
| export default class MyApp extends App { | ||
| render() { | ||
| const { Component, pageProps } = this.props; | ||
| return ( | ||
| <ThemeProvider theme={theme}> | ||
|
Member
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. are we going to provide dark theme in the future? 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. If it makes sense with CSS in JS, I'd recommend with this media query
Member
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.
Contributor
Author
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. It's something we can look at - one of the advantages of using a global theme is that it's one source of truth for the entire application and whitelabelling and re-theming are a walk in the park 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. Wow, in that case, I'd favor something with more adoption then; like css vars you could change with a toggle or something. I'm sure ThemeProvider is fine too. |
||
| <Component {...pageProps} /> | ||
| </ThemeProvider> | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import Document from 'next/document'; | ||
| import { ServerStyleSheet } from 'styled-components'; | ||
|
|
||
| export default class MyDocument extends Document { | ||
| static async getInitialProps(ctx) { | ||
| const sheet = new ServerStyleSheet(); | ||
| const originalRenderPage = ctx.renderPage; | ||
|
|
||
| try { | ||
| ctx.renderPage = () => | ||
| originalRenderPage({ | ||
| enhanceApp: App => props => sheet.collectStyles(<App {...props} />), | ||
| }); | ||
|
|
||
| const initialProps = await Document.getInitialProps(ctx); | ||
| return { | ||
| ...initialProps, | ||
| styles: ( | ||
| <> | ||
| {initialProps.styles} | ||
| {sheet.getStyleElement()} | ||
| </> | ||
| ), | ||
| }; | ||
| } finally { | ||
| sheet.seal(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const theme = { | ||
| colors: { | ||
| primary: '#0070f3', | ||
| }, | ||
| }; | ||
|
|
||
| export default theme; |

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.
will
styles/ever be accessed fromserver/? if not, can we put it inclient/?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.
I forsee this to be the place where we might (in the future) add some styles that need to be rendered on the server, which is why I left this as it's own folder (I had to do this for Bootstrap on my personal project just this week). Considering that styles are oftentimes implemented on both sides of the boundary, I would recommend we leave it here. Thoughts?
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.
Since
next.jsis taking care of SSR and our current setup has us grabbing components out ofclient/frompages/where the SSR magic happens, I think it makes sense for styles to also be inclient/. I haven't toyed around with any advanced config around SSR though so I'm not sure if we'd need to import anything fromstyles/to theserver/directory. Would you happen to know of any instances where it would be needed to do such an import?Uh oh!
There was an error while loading. Please reload this page.
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.
@timmyichen Sorry - I've been swamped all day. I'm just seeing this. So the scenario I was talking about is when we need to inline critical above-the-fold CSS like mentioned here. Lighthouse throws warnings when moderate sized CSS files are loaded via
linkas CSS imports are render-blocking. An instance of this is if we are using a light enough Grid/Flex framework, it might make sense to inline it.Here are some instances where we do inlining: 1, 2, 3
The way we are hooking up
styled-componentson this PR is also by inlining the styles although it isn't as straight forward as that.