-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 complex addUtilities()
configs
#15029
Conversation
addUtility()
configsaddUtilities()
configs
bf3770a
to
298a8dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small thing in the tests but otherwise seems good
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Closes #15012 We do not have replacements for these plugins _just yet_. In order to increase compatibility with setups that rely on some of these legacy plugins, this PR bundles `@tailwindcss/forms`, `@tailwindcss/typography`, and `@tailwindcss/aspect-ratio` (after #15029) with the standalone build now. In comparison to v3, this omits the `@tailwindcss/container-queries` plugin since is not a first-party feature of Tailwind CSS v4. ## Test Plan Added an integration test. I also tested this by running the standalone binary in a temporary folder with as simple input css: ```css @import "tailwindcss"; @plugin "@tailwindcss/typography"; ```
@philipp-spiess Am I right to assume that in v4, we need to migrate from addUtilities({
"@media (min-width: 768px)": {
".article-display-m": {
"font-size": 60px;
}
}
}) to: addUtilities({
".article-display-m": {
"@media (min-width: 768px)": {
"font-size": 60px;
}
}
}) |
@davidmatter Huh this is... interesting! Yes if you can migrate to that that would be easiest. Is this a plugin doing or how did you discover this? |
We're quite a large company with an extensive CSS-based design system with hundreds of (for example) typography definitions. Now, to get proper intellisense in our code editors and to integrate better with our tailwind projects, we've come up with a custom plugin that parses some of our foundational CSS utilities and adds the definitions to tailwind using e.g.
It works quite well actually in v3 :) In a perfect world, these definitions would of course be extracted to their own components to support the official tailwind way of doing things etc. but that would be A LOT of work. |
For parsing and |
I see, so you're not expecting this to generate the right CSS anyways and only use this to extend the type hints for intellisense? I think it should be possible to write a quick function that inverts the object properties in this case? |
@philipp-spiess Thanks for taking the time. Well, we actually use it to generate prunable CSS. TBH I think it's the best pattern to work with legacy CSS code because of 1) Intellisense and 2) Resulting CSS can be pruned by tailwind and runs through the official plugin system. Inverting the objects is alright for us. I suspect that we're not the only ones using this pattern, though. Might be advisable to mark this as a breaking change to save everyone's time :) |
BTW: Good to see an Austrian engineer being part of tailwind! Keep it up |
This PR adds support for complex
addUtilities()
configuration objects that use child combinators and other features.For example, in v3 it was possible to add a utility that changes the behavior of all children of the utility class node by doing something like this:
This is a pattern that was used by first-party plugins like
@tailwindcss/aspect-ratio
but that we never made working in v4, since it requires parsing the selector and properly extracting all utility candidates.While working on the codemod that can transform
@layer utilities
scoped declarations like the above, we found out a pretty neat heuristics on how to migrate these cases. We're basically finding all class selectors and replace them with&
. Then we create a nested CSS structure like this:Due to first party support for nesting, this works as expected in v4.
Test Plan
We added unit tests to ensure the rewriting works in some edge cases. Furthermore we added an integration test running the
@tailwindcss/aspect-ratio
plugin. We've also installed the tarballs in the Remix example from the playgrounds and ensure we can use the@tailwindcss/aspect-ratio
plugin just like we could in v3: