-
Notifications
You must be signed in to change notification settings - Fork 4.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
Support opacity modifiers for colors in JIT #4348
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4348 +/- ##
==========================================
- Coverage 71.85% 71.80% -0.06%
==========================================
Files 220 220
Lines 4769 4802 +33
Branches 790 802 +12
==========================================
+ Hits 3427 3448 +21
- Misses 1262 1268 +6
- Partials 80 86 +6
Continue to review full report at Codecov.
|
@adamwathan Will things like |
@MichaelDeBoey Yep they will! |
Is there any possibility that this could be extend for shadows? Instead of hard coding new colors in # tailwind.config.js
boxShadow: {
- 'lg-hard-coded-blue': '0 10px 15px -3px rgba(37, 110, 255, 0.1), 0 4px 6px -2px rgba(37, 110, 255, 0.05)'
+ 'lg': '0 10px 15px -3px rgba({color}, 0.1), 0 4px 6px -2px rgba({color}, 0.05)'
} - <div class="shadow-lg-hard-coded-blue">
+ <div class="shadow-lg-blue-600"> |
@hmaesta Hey! I don't think this particular feature is a great way to add that sort of flexibility to shadows unfortunately. I would like to solve the "colored shadows" problem at some point though for sure, something that's been tumbling around in the back of my mind for like 2 years honestly. |
This is now available to test in canary if you want to give it a go early:
|
This PR adds a new syntax for specifying color opacity when using the JIT engine.
Instead of needing to use utilities like
bg-opacity-50
,text-opacity-25
, orplaceholder-opacity-40
, this PR makes it possible to just tack the opacity right on to the end of the color:The motivation for this is to remove the need to add new color opacity utilities any time we add other new utilities that are color based. For example, currently the gradient utilities do not support opacity at all:
People expect this to work (#3875) but in reality the better solution would be something like this:
The problem with this solution is it scales really poorly. Any time we add a new color utility, we need a new corresponding opacity utility, which means coming up with a new core plugin name, documenting it, etc.
This PR introduces an approach that allows you to apply opacity to any color by just adding
/{opacity}
to the end of the color, and it is handled at an earlier phase in the compiler so that no color related plugins even have to know that this syntax exists.The opacity values you add at the end of the color name are taken from your
opacity
scale in your theme, and the utility-specific opacity scales are ignored, the idea being that this feature effectively deprecates that stuff.This feature also supports arbitrary opacity values, in case you want to pull the opacity from a CSS variable or use some other one-off value, using this syntax:
This feature is only available in JIT mode, as making it work in the classic engine would introduce a tremendous amount of bloat due to the combinatoric explosion of classes.