-
Notifications
You must be signed in to change notification settings - Fork 14k
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
[SIP-37] Proposal to implement CSS-in-JS using Emotion π©βπ€ #9123
Comments
What sort of TypeScript guarantees do we get with Emotion? When adding the css tag to a component to we get safety of only being able to set valid CSS properties and valid values for these properties? |
@etr2460 For the For the The docs/examples on the matter here explain it more eloquently than I can :) |
It sounds like short-term (or longer) this will further fragment the approach in the codebase. Given all of the other large changes in flight and in the pipeline (including design overhauls etc), is the cost/benefit there to justify doing this now? Who is committing to converting the existing codebase rather than fragmenting it further? |
Hot @DiggidyDave I do agree with that ;) |
@DiggidyDave this proposal is due largely to serve the goals of the design overhaul. That redesign will require a pretty massive revamp of the existing LESS codebase anyway. This also relates to the cleanup of LESS code we've been working on to move toward a set of variables (a theme, effectively). These efforts combined seem like the best way to
So, while I don't disagree with your stance about fragmentation, I would suggest that it is the easiest means of migration to the new design system, and it is compatible with the existing setup (LESS still works on any/all components). It will also make styling (and comprehending existing styling) of components easier for future devs. |
Thanks @rusackas I wouldn't call my comment a "stance" so much as an expression of a concern. π The benefits you've articulated seem substantial, I was just making sure there is a discussion of any potential "cons" here among stakeholders. |
Thanks @rusackas for making this SIP.
I had a small feature already in the dashboard code that can be much cleaner if i had help from a css-in-JS framework: Can Emotion handle this case easily? I am new to all css-in-js libraries. Once we decided, i'd like to re-write this module to use our pick. Thanks! |
Just want to add another long-term benefit I see from using |
@graceguo-supercat It is definitely possible to style a component based on state using react hooks. I've attached a teensy demo of this using Create React App, attached here. Just |
There are a couple of alternatives of CSS-in-JS flavors out there, just summing it up here in case they may be of some interest. The following three libraries are being developed by Brent Jackson and the Gatsby team based around the idea of a design system. Styled-System: Works on top of styled-components/emotion: Rebass: Some components built on top of styled system Theme UI: Inspired by styled-system Tailwind: utility-first css library, more similar to bootstrap and easier to migrate? Linaria: zero-runtime css-in-js Stylex: Facebook's zero-runtime css-in-js approach. (not actually available, only demoed in react conf) CSS/SCSS modules: |
@bugzpodder Thanks for the list. I think something like Styled-System may come into play eventually, but that has a prerequisite of the adoption of Emotion or Styled-Components, which is enough scope for this SIP, I think :) Linaria is interesting, and may be worth considering if we run into performance issues with Emotion. The good news is, it follows a largely similar pattern of code style, so it should be a not-too-painful migration if warranted. I'd still prefer to go with the front-runners for the time being, for the expanded community at the very least. I've been long-intrigued by TailWind as well, and plan to use it for other projects, but it looks like a serious burden to migrate the codebase onto or off of it. |
Voted in, work in progress, closing the SIP as an issue. More good stuff to come! Thanks all! |
Apache Superset has been using Emotion for quite a while now (original proposal [here](apache/superset#9123), and best practices captured [here](https://github.com/apache/superset/wiki/Emotion-Styling-Guidelines-and-Best-Practices). We'd be proud to have our link on the roster!
Apache Superset has been using Emotion for quite a while now (original proposal [here](apache/superset#9123), and best practices captured [here](https://github.com/apache/superset/wiki/Emotion-Styling-Guidelines-and-Best-Practices). We'd be proud to have our link on the roster!
[SIP-37] Proposal to implement CSS-in-JS using Emotion π©βπ€
Motivation
Superset has been built with React components utilizing a few layers of styling. Most components are build using React-Bootstrap (v0.31), which is in turn built on Bootstrap 3. Bootstrap 3 is built using LESS, and is themed/overridden in Superset with Bootswatch and a Bootswatch theme called Cosmo, also built with LESS. At this point, efforts have been made to consolidate styling with LESS variables, and cleaning up use of LESS styles throughout the codebase, but some key problems remain:
Migrating to CSS-in-JS accomplishes a few goals:
<Button primary>
or<Card small>
)Proposed Change
In short, the plan is to implement components using Emotion. This can be done immediately for new components with no fallout to the existing codebase, but can also be extended to wrap or rewrite existing components in the interest of modernizing old code and libraries.
Further implementation details below.
New or Changed Public Interfaces
N/A
New dependencies
Emotion and various submodules - MIT License
babel-plugin-emotion
- MIT Licenseemotion-ts-plugin
- MIT Licensejest-emotion
- MIT LicenseMigration Plan and Compatibility
The plan to move toward Emotion-styled components would take the following path:
theme
file, and provide it to all components in the React component tree via EmotionsThemeProvider
HOC. This will lead to duplication of these variables, but this is temporary.To extend this idea toward deprecating Bootswatch/Cosmo, and eventually upgrading React-Bootstrap, the following approach may be used:
React-Bootstrap
based components into similarly named wrapper components, and applying custom styles and theme variables as needed to shape the atomic component toward the target design(s). Here's a sketch of how a wrapped React-Bootstrap button might look, with some arbitrary custom styles illustrating prop and theme usage.In the event of an emergency involving support or implementation of Emotion, it should be fairly straightforward to migrate to Styled-Components as an optional ejection path. They follow the same patterns.
Rejected Alternatives
The text was updated successfully, but these errors were encountered: