-
Notifications
You must be signed in to change notification settings - Fork 48
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
Reflect on the various styling approaches #963
Comments
Global css + Boostrap are useful for keeping general styling consistent across the site without having to maintain extra "wrapper" components. styled-component's Motivation page lists out reasons to use it. I think it's nice to encapsulate the styling to the component without any chance of it affecting other components. inline-styling is easy to write, but hard to maintain...
I'd vote to stop using inline-styling, but no strong feelings towards the other two.
Maybe if we were doing a completely overhaul of the site? Realistically though, probably not, seems like extra work for no real gain? |
Adding on...
+1 for striving to keep general styling consistent and generic.
+1 here too
My vote is "prefer styled components for anything that's not site-wide, avoid adding new inline, don't worry about changing existing styling until it's being touched for some other reason".
Hard no from me here, until and unless we're doing a from-scratch rewrite. (So, what Jover said but +2 😁) |
Thanks for the feedback! How about this as a rule of thumb that can be put in static-site/README.md?
Potential cleanup work to keep things in line with above:
|
+1 to the above.
Maybe add another bullet to the guideline above, something like "if modifying something that uses inline styling, consider converting to a global style or a styled component as appropriate."
These 3 seem like they deserve distinct issues (and personally I think the last one is much higher priority than the other two). |
Realistically, adding styles at a global level to a site with many diverse pages is not a trivial task. If you mean adding styles scoped to a CSS class name / id then I'd suggest using CSS modules instead, and at that point the difference with Styled Components is largely ideological. In terms of how the site feels, consistency is key. To me that means colours, margin sizes, font sizes etc that we can use throughout the site (we have a bit of this via our styled components theme), but it would also include consistent styles for UI elements like buttons. My suggestion for new work is to use as much of these site-wide styles as possible, and as we notice similarities in UI elements to lift them up into site-wide variables or reusable components. In terms of the technology to use, I'd either lean into Styled Components and use the theme styles as much as possible, or use CSS modules with global variables for consistency; given our usage of the former, it's simpler to stay on that road. Using inline-styles to override one value is just fine in my eyes. |
A few of us met in person last month and decided that we would switch from Next.js Pages Router to App Router. That means migrating away from styled-components. @genehack has started this in #1032:
|
Currently, CSS styles are applied using various approaches listed below with examples.
Global defaults defined in static-site/src/styles/globals.css:
nextstrain.org/static-site/src/styles/globals.css
Lines 4 to 7 in 1963a24
Inline styling:
nextstrain.org/static-site/src/components/ListResources/ResourceGroup.tsx
Line 43 in 1963a24
Bootstrap defined in static-site/src/styles/bootstrap.css:
nextstrain.org/static-site/src/components/Footer/index.jsx
Lines 18 to 20 in 1963a24
styled-components:
nextstrain.org/static-site/src/components/splash/index.jsx
Lines 376 to 381 in 1963a24
It seems like most (or all?) are useful. However, when defining new styles, it's not clear what should be used. Most files I've worked on have used styled-components so that's what I've been using.
Questions for discussion
Related discussions
The text was updated successfully, but these errors were encountered: