-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SDK: use higher level component to scope styles for Calypso components #26852
Conversation
In this patch I'm doing two things at once to reach the goal of using Calypso UI components: pulling in the UI code and pulling in the styles. As you may note I'm bringing in the entirety of the Calypso styles since the framework styles are monolithic. This has the immediate drawback that the stylesheet is over a megabyte in size, but the immediate advantage that we can import Calypso UI and not have to write it all ourselves. If this turns out to be a good path then we will obviously have to optimize the CSS, which is already in the plans. As the SDK and Calypso framework improves we should see that bundled CSS drop down to very small sizes. Currently the framework isn't ready to split apart the CSS though I'm afraid.
Previously we were pulling in the top-level stylesheet from Calypso and we were doing so from the top of the extension code. This pulled in over a megabyte of CSS and required us to be aware of Calypso's styling and style paths. In this change I have updated the `Card` and `Ribbon` components so that they explicitly import their SASS dependencies. This allows us to pull in _only_ the required style when building the extension. The output dropped from a megabyte to three kilobytes.
> - configuration.module.rules[2].exclude should be one of these: > RegExp | non-empty string | function | [RegExp | non-empty string | function | (recursive) | object { and?, exclude?, include?, not?, or?, test? }] | object { and?, exclude?, include?, not?, or?, test? } Setting it to `undefined` would work as well.
Instead of: ``` <div class="component calypso"></div> ``` Do this: ``` <divclass="calypso"> <div class="component"></div> </div> ```
See my comment on pa9srA-l-p2:
|
Based on the previous experiment to scope our CSS (#26683). This has a bunch of code from that other PR to namespace styles needed for this experiment.
This automates the other part — injecting the scope CSS selector in components.
Instead of manually adding
.calypso
to the block's code, we could add a wrapper component that only adds the scope CSS selector to the component. This would require ensuring each component in Calypso does something like this:Higher order component would be shipped together with blocks and applied in run-time.
Input:
Output:
We can now use scoped CSS that applies only to Calypso components:
Problems
<div class="card calypso"></div>
but CSS is.calypso .card {}
— note the space in between. HTML would need to be<div class="calypso"><div class="card"></div></div>
for this to work. That can be solved by wrapping the component in additional<div>
at the higher level component.Testing
Grab files from
client/gutenberg/extensions/editor-notes/build
and load them in Gutenberg.Observe the
Card
element hascalypso
class in it