-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
RFC: styled-components #434
Conversation
6424b3d
to
4f438d2
Compare
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.
👍 👍 👍
So the end resolution is to ultimately transition all If yes, what do you think would be the appropriate transition strategy?
Would some kind of automation make sense for the transition? I would move the decision about |
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'm favorable to it.
- I would like to have an idea of the transition strategy
- I would propose to separate RFCs for
styled-components
andbasscss
- Would be great to wrap up the RFC in a txt file, eg:
rfc/002-styled-components
. For future developers to easily browse that kind of documents in one place.
4f438d2
to
d638b57
Compare
@znarf I've added the RFC doc.
This RFC is only about including
I agree. I removed the reference to potentially moving to Let me know if you have any other questions. |
d638b57
to
1f06e84
Compare
I think it's great to start with the We should put the removal of Our |
I will do that and add it to the description of this PR. 👍
It appears we are only using |
@HipsterBrown A few days ago, I was not far from proposing to drop |
I really like this rfc process. Great write up @HipsterBrown and good suggestions @znarf! |
TL;DR:
There is a lot of repeated and inconsistent styles spread around the application. Using an extensible library like
styled-components
and its ecosystem will make building UIs efficient and consistent.Motivation:
While working on the layout and design of the new homepage (as well as the search page previously), I had some trouble learning the best practice for using a responsive grid with repeating styles and modifying existing component styles without exposing global selectors.
styled-jsx
is great at scoping selectors to the component, but it has not been useful for sharing common styles and creating extensible UI components.The
react-bootstrap
grid components allows for responsive width sizing but does not have a nice API for working with flexbox or spacing utilities (Bootstrap v4 has this but not coming anytime soon toreact-bootstrap
).Solution:
While searching for a solution to these issues, I looked to one of my favorite CSS libraries, basscss for inspiration and discovered a simple yet powerful grid library, built by the author of basscss, called
grid-styled
that usesstyled-components
as a peer dependency.styled-components
works with Next.js, including server-side rendering, and allows for styling third-party components. I believe adopting this library and pattern will cleanup a lot of our css-in-js code with no apparent impacts in performance.We can also use it alongside
styled-jsx
while we update existing components.Alternatives:
I tried to recreate the API provided by
grid-styled
usingstyled-jsx
however dynamically creating media queries and making the components extensible required more custom tooling than it was worth.Proof of Concept:
Included in this PR is an example of using
styled-components
andgrid-styled
to refactor the SearchPage. The only custom css required was written to customize theFormControl
fromreact-bootstrap
.Adoption / Transition Strategy:
Because we can use
styled-components
andstyled-jsx
together in the app, we should be able to completely adoptstyled-components
over time. As we work on files that usestyled-jsx
, one refactor commit should be made to convert the file to usestyled-components
. This will probably start with replacing the global styles in the_document.js
page and the<Header>
component with aninjectGlobal
declaration and a theme with our common colors, font sizes, spacing values, etc.I have not been able to find an automated solution for converting
styled-jsx
blocks intostyled-components
.