Add --default(…) option in --value(…) to support fallback values#19989
Open
RobinMalfait wants to merge 1 commit intomainfrom
Open
Add --default(…) option in --value(…) to support fallback values#19989RobinMalfait wants to merge 1 commit intomainfrom
--default(…) option in --value(…) to support fallback values#19989RobinMalfait wants to merge 1 commit intomainfrom
Conversation
Contributor
WalkthroughAdds tests enforcing that functional utilities require 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
This allows us to re-implement functional utilities with a default value in CSS using `@utility`. Used the explicit `--default()` argument of `--value()` for a few reasons. 1. It's explicit about being a falllback value. If you have `@utility foo-*`, then you want to be able to use `foo`, but `foo-bad` should not compile. 2. When `--value(…)` is used in (complex) property values (think a bunch of `calc(…)` expressions), then we don't need a separate property for this. One of the ideas was to have a literal fallback: ```css @Utility tab-* { tab-size: 4; tab-size: --value(number); } ``` For `tab`, this would compile to: ```css .tab { tab-size: 4; } ``` For `tab-123`, this would compile to: ```css .tab { tab-size: 4; tab-size: 123; } ``` Getting rid of the `tab-size: 4` would be an option, but it's a common pattern in real CSS for fallback values (think hex background color, over a more modern `oklch` color). For `tab-foo`, this would compile to: ```css .tab { tab-size: 4; } ``` Which means that we have an infinite amount classes that would result in the same class, which is bad. We could special case this one because the internal `value` would still be `null`, but it might be too confusing. This syntax without the `--default` also means repetition of certain properties. Add `--modifier(…)` to the mix, and there is even more repetition going on. Another option to consider is that the default fallback is just another option in the `--value(…, 4)`, but if a default fallback is a keyword, then there is a chance that this might conflict with actual keywords we interpret.
435aba9 to
8c4744c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
--default(…)option that can be used inside a--value(…)such that functional utilities without an explicit value can still be defined as a function utility. It would also allow you to use a functional utility without a value and with a modifier, e.g.:shadow/50.This allows us to re-implement functional utilities with a default value in CSS using
@utility.Used the explicit
--default(…)argument of--value(…)for a few reasons.@utility foo-*, then you want to be able to usefoo, butfoo-badshould not compile.--value(…)is used in (complex) property values (think a bunch ofcalc(…)expressions), then we don't need a separate property for this.One of the ideas was to have a literal fallback:
For
tab, this would compile to:For
tab-123, this would compile to:Getting rid of the
tab-size: 4would be an option, but it's a common pattern in real CSS for fallback values (think hex background color, over a more modernoklchcolor).For
tab-foo, this would compile to:Which means that we have an infinite amount classes that would result in the same class, which is bad. We could special case this one because the internal
valuewould still benull, but it might be too confusing.This syntax without the
--default(…)also means repetition of certain properties. Add--modifier(…)to the mix, and there is even more repetition going on.Another option to consider is that the default fallback is just another option in the
--value(…, 4), but if a default fallback is a keyword, then there is a chance that this might conflict with actual keywords we interpret.Main motivation is to be able to re-implement utilities such as
shadow/50purely in CSS. It's also something we support in the JS based APIs, but not in the CSS based one, so while it's a "new" feature, it's more like a missing feature right now, and often a reason for people to use the JS based APIs instead.Fixes: #16824
Test plan