-
Notifications
You must be signed in to change notification settings - Fork 841
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
[DISCUSS] Unifying our tooling for generating style code across Elastic #1656
Comments
@elastic/apm-ui @elastic/infrastructure-ui @elastic/cloud-ui @elastic/codesearch @zumwalt I promised @sqren a meeting to discuss styled component usage in Kibana but figured it was something we could do async since we're all in different timezones. I've tried to write down some of my opinions about it, but I'm up for ideas. We have not started work on any of this stuff and only have a general directive so there's no immediate pressure to make a decision. |
What's the argument against SASS all the things? |
I think the move to CSS Modules is a great step in the right direction, since they introduce encapsulation and avoid the global scoping problems that plain css/less/sass suffers from. Demo application with CSS Modules and Styled-Components Q & A
True, and probably the biggest blocker for having multiple systems. AFAICT everybody in Kibana using SC has also embraced Polished which is a small library that offers the manipulations you mention. The naming does differ a bit, eg. instead of
This should be easy to fix. There is an official babel plugin that solves exactly this (you are not the only one to be annoyed by this :) )
Good point. I like the way Infra approached this and I don't think it's a lot of work to setup (wrap your application in a theme provider and inject eui variables). But having something that Just Works™ is definitely appealing.
Agree - I've also noticed this. I think it comes from SC being a new approach and none of us really knows what the ideal way to structure it is. If we choose to keep styled-components around we should collaborate cross-team and figure out some best practices that could make it into a set of guidelines/style-guide.
This is similar to the point you made above with On a final note I don't intent to come across as too dismissive to the idea of ditching SC in favor of CSS Modules. I'm mostly ok with it but want to make sure we are aligned with the pros/cons before teams spend a significant amount of time and resources refactoring their plugins to a new paradigm. |
To your last point, don't worry, And don't assume my walls of text are me trying to force decisions either. I just come from a previous background of writing out specs and assumptions before committing to work. So to me it's just useful process :) The one thing I'll mention about Polished, which is nice and recreates a lot of Sass functions is that it doesn't recreate the sass functions / mixins we create ourselves. |
Thanks for compiling these arguments. I agree that a unification of the styling mechanism is highly desirable. To me the biggest advantage of styled components is that styles can be located inline right alongside the presentational react components. This enables a separation of concerns (visual presentation as the result of entwined DOM structure and styles) instead of the "separation of technologies" as enforced by the JS/CSS file split. From the feature list it looks like the astroturf library you mentioned can give us that feature as well as enabled the full re-use of the amazing work you put into the sass system. So 👍 to that from my side. |
Summary from All hands discussion:
If you're not using Sass now in Kibana, I would recommend
You can wait on this process till after, but starting now gives us some manner of unity before this event happens and will make your conversion simpler later on. I will set up a meeting and record it for all interested parties next week. |
Was there representation from Cloud in that meeting? |
Yep, but we don't really care much as long as we can keep on doing what
we're doing
…On Fri, May 24, 2019, 06:14 Rory Hunter ***@***.***> wrote:
Was there representation from Cloud in that meeting?
—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
<#1656?email_source=notifications&email_token=AAHEDFNFMYF6QADHJFM5K7LPW6WXFA5CNFSM4G3IIC5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWEUPIA#issuecomment-495536032>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHEDFLJ2T4JS7MJW2APESTPW6WXFANCNFSM4G3IIC5A>
.
|
This week @thompsongl is starting proof of concept (likely multiple of them) work for this project. We'll set up a meeting in the following weeks and send a note to all of dev for review before we move forward. The earliest we'd anticipate movement here would be 7.4. |
const buttonClass = rule({
color: 'tomato',
border: '1px solid orange'.
});
const Button = () => <button className={buttonClass}>Click me!</button>;
|
@streamich Check the latest Kibana weekly for the latest status on the CSS-in-JS solution. There's a meeting recording as well as a gist linking out to some PoCs we're evaluating. We definitely don't want to come up with a third way of building CSS in Kibana, so I'd hold on adding something new there. Our plan is to send out a dev email / schedule a meeting for next week to the larger UI teams if you're interested.
As to this. I'm guessing this is simply an oversight at the moment, but I'm not super knowledgable about that project and how Sass works there. I assumed it was the same as it works now. We have hundreds of Sass files in Kibana and they'll need to compile down since my guess is the platform conversion work and this CSS in JS work we're planning will both be gradual, separate projects. Likely @epixa or @joshdover can fill in the gaps there. |
I haven't been able to find any references to Sass or scss in new platform locations. Relatedly, I haven't found anything in terms of documentation for styling in new platform. @streamich is it just the lack of support at this time that raises questions about Sass in new platform, or is there documentation that suggests what styling (generally) will require? |
We'll need to get back to working on this issue for the 7.8 time frame. In particular, the use case is being able to have components like EuiControlBar and EuiTooltip render as "dark theme in light mode". |
can you expand on that, or link to an existing definition/conversation? |
This was sort of an internal note that @snide and I discussed. But we're seeing more components that render with dark backgrounds like EuiControlBar and EuiTooltip. Right now all their contents (aside from plain text which can easily inherit color), assumes they're in light theme and therefore won't render with proper contrast or visibility at all. The current terrible way to handle this is to have a class wrapper that imports the dark theme colors and re-exports all the components, doubling the compiled CSS which is no good. This really should be done at the component scope allowing for a "theme" context of variables to be passed and the appropriate styles be applied. |
I think we may be done discussing and moving on to an actual plan 🎉 So I'm closing this issue in favor of #3912 |
Summary
Currently there are various ways to generate "css" code at Elastic used throughout our products. To my knowledge there are the following systems currently in play.
All of these have differing sources of truth. It would be nice if we could all use the same global scope.
Main problems with how we do things today
What we want as an end result
Proposal
We move to a CSS in JS system that allows for Sass to be written alongside the JS layer. Current proposals include moving to either https://github.com/gajus/babel-plugin-react-css-modules or https://github.com/4Catalyzer/astroturf
Why one of those systems seems like a decent path forward
The negative is primarily that the separation of concerns leaves the opportunity for dead CSS. Deleting a class in the JS means you have to find and delete that class in the CSS.
The other negative is that it goes against our "use what you want" mantras. However, this seems to be less a concern as we've proscribed "Typescript everything" and "React everything" over the past two years.
Why is Sass such a sticking point to the designers
Sass does alot. It's not just providing variables. It's over a decade old and the utility of the language itself is very powerful beyond the ways you're used to using it.
That out of the way. Not all of Kibana is React yet. Compiled CSS is still needed in certain places so Sass (even if used in CSS in JS primarily) gives us an escape hatch in those pesky places (It can still compile down or be imported into singleton css compiles). Second, the vast majority of our code is currently in Sass using EUI's Sass scope. The migration took us over a year, and outside of the blob nature of the CSS generated, we have no complaints with our Sass usage as tooling. It's battle tested, comes with everything you need out of the box (no importing from NPM for color manipulation or other design tooling) to do 99% of our styling needs. It's also already documented extremely thoroughly, and something we can assume new designers will be familiar with when we hire them.
The problems we have with the Sass are mostly in how we've compiled it. Things we hope to solve with a CSS in JS solution.
Also of note is that the entirety of the Sass global scope comes in one line in Kibana
@include styling_constants
. This is very powerful. With any JS solution, we'd never get something as portable because it would need to abibe by usual JS importing rules.Why is global scope useful to designers
Usually when you read articles about CSS you hear a lot about removing global scope. This is valid for compilation and the actual CSS, but often the opposite is true when we talk about how we develop design (where we often import global scope on purpose). To maintain consistent design in a large product you need a fairly opinionated and importable global scope. Again, we're not talking about just variables here, we're talking about broad, heavy handed mixins that do everything from color contrast to form bordering to focus states to animation curves. None of these make sense to be abstracted to a JS "component" layer, especially considering we often pass multiple mixins onto single selectors. They are simply portable snippets of style code that make up the DNA of our shared styling. Often they are used together or in pieces across a broad range of products.
Why has Styled Components usage been difficult alongside EUI
Styled components as a platform is fine. It's problems are mostly in our usage, which may or may not be fixable, so here's the problems we've had in case people have good ideas.
tintOrShade
or@include euiBottomShadow($euiColorPrimary, .2)
and you have to remake it in JS.Reasons it would be nice to use the same tools
Other possible alternatives
The text was updated successfully, but these errors were encountered: