Skip to content
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

Support grouping rules like @media and @layer and fix shadow DOM support #103

Merged
merged 17 commits into from
Mar 3, 2024

Conversation

m-akinc
Copy link
Contributor

@m-akinc m-akinc commented Feb 10, 2024

Fixes #41 and #93

  • Added support for CSSGroupingRules like @layer, @media, etc.
  • Fixed bugs in support for shadow DOM.
    • When multiple such elements on the page shared stylesheets, they would not all be added to shadowHosts because of the use of __pseudoStatesRewritten. This would prevent them from getting classes applied by shadowHosts.forEach(updateShadowHost).
    • When rewriting a selector like :host(.foo) .control:hover, it was incorrectly assuming any state selectors (e.g. :hover) occurred inside the :host() selector and generated a bogus selector like :host(.foo) .control.pseudo-hover-all. Now handling scenarios like this by writing :host(.foo.pseudo-hover-all) .control instead.
    • pseudo-*-all classes were being applied to a custom element (by the attachShadow override) even if none of its stylesheets were rewritten (and therefore it was not added to shadowHosts). This could result in those classes not being removed later.
    • updateShadowHost was only looking at classes on ancestors, so any pseudo-* class applied directly to the shadow host because of a selector (i.e. in applyParameter) would get removed.
    • updateShadowHost would propagate pseudo-hover, for example, from an ancestor to a shadow host. It should only be propagating pseudo-*-all.
    • updateShadowHost wouldn't cross shadow boundaries, so nested shadow DOM (i.e. a custom element in the shadow DOM of a custom element) wouldn't get the global pseudo-*-all class.
  • Added support for targeting elements in shadow DOM with selectors:
parameters = {
  pseudo: {
    hover: ":host(.hover) .innerControl"
  }
}
  • Added new rewriteStyleSheet test cases
  • Had to update version of tsup due to error I was running into

This reverts commit cfeee48.
@m-akinc
Copy link
Contributor Author

m-akinc commented Feb 27, 2024

@ghengeveld @JonathanKolnik 🙏 Could I get a review of this PR? I think it would open this addon up to a whole lot of new potential users that can't currently use it (like my team 😁).

@ghengeveld
Copy link
Member

@m-akinc I'll take a good look at this and your other PRs tomorrow. You did a lot of great work here!

Copy link
Member

@ghengeveld ghengeveld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is really great work! 👏

I left a few minor suggestions which you may want to look at. I also would've appreciated some new Storybook stories to showcase the scenarios this PR is addressing, so that we also have visual confirmation that it works as intended (and Chromatic will snapshot them to detect future regressions). Any chance you can add some?

Thanks a lot for all the effort! I couldn't have done all this myself.

src/preview/rewriteStyleSheet.test.ts Show resolved Hide resolved
src/preview/withPseudoState.ts Outdated Show resolved Hide resolved
m-akinc and others added 2 commits February 28, 2024 13:38
@m-akinc
Copy link
Contributor Author

m-akinc commented Feb 28, 2024

I added a story for a nested custom component and one for CSS at-rules. Let me know if you need anything else before merging.

Copy link
Member

@ghengeveld ghengeveld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work! Ready to merge?

@m-akinc
Copy link
Contributor Author

m-akinc commented Feb 29, 2024

LGTM. Nice work! Ready to merge?

Yes! 🚀

@ghengeveld ghengeveld merged commit db41072 into chromaui:main Mar 3, 2024
@ghengeveld
Copy link
Member

CI is failing to release, working on that...

@ghengeveld ghengeveld added minor Increment the minor version when merged release Create a `latest` release when merged labels Mar 4, 2024
@github-actions github-actions bot added the released This issue/pull request has been released. label Mar 4, 2024
Copy link

github-actions bot commented Mar 4, 2024

🚀 PR was released in v2.2.0 🚀

@github-actions github-actions bot added the prerelease This change is available in a prerelease. label Mar 4, 2024
@m-akinc m-akinc deleted the support-grouping-rules branch March 27, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged prerelease This change is available in a prerelease. release Create a `latest` release when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pseudo-state rules passed to a scss media query mixin do not appear to be added to the DOM
2 participants