Commit 08cad84
authored
This PR adds a new `--default(…)` option that can be used inside
`--value(…)` or `--modifier(…)` such that functional utilities without
an explicit value/modifier can still be defined as a functional 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.
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.
Main motivation is to be able to re-implement utilities such as
`shadow/50` purely 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.
For consistency reasons, this is also implemented for `--modifier(…)`
such that you can use a default value there. E.g. when re-implementing
`text-sm` where a default `line-height` is set without the explicit use
of a modifier.
Fixes: #16824
## Test plan
1. Added a handful of new tests to make sure this functionality works
2. Existing tests still pass
1 parent 0f6f7d4 commit 08cad84
3 files changed
Lines changed: 151 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29574 | 29574 | | |
29575 | 29575 | | |
29576 | 29576 | | |
| 29577 | + | |
| 29578 | + | |
| 29579 | + | |
| 29580 | + | |
| 29581 | + | |
| 29582 | + | |
| 29583 | + | |
| 29584 | + | |
| 29585 | + | |
| 29586 | + | |
| 29587 | + | |
| 29588 | + | |
| 29589 | + | |
| 29590 | + | |
| 29591 | + | |
| 29592 | + | |
| 29593 | + | |
| 29594 | + | |
| 29595 | + | |
| 29596 | + | |
| 29597 | + | |
| 29598 | + | |
| 29599 | + | |
| 29600 | + | |
| 29601 | + | |
| 29602 | + | |
| 29603 | + | |
| 29604 | + | |
| 29605 | + | |
| 29606 | + | |
| 29607 | + | |
| 29608 | + | |
| 29609 | + | |
| 29610 | + | |
| 29611 | + | |
| 29612 | + | |
| 29613 | + | |
| 29614 | + | |
| 29615 | + | |
| 29616 | + | |
| 29617 | + | |
| 29618 | + | |
| 29619 | + | |
| 29620 | + | |
| 29621 | + | |
| 29622 | + | |
| 29623 | + | |
| 29624 | + | |
| 29625 | + | |
| 29626 | + | |
| 29627 | + | |
| 29628 | + | |
| 29629 | + | |
| 29630 | + | |
| 29631 | + | |
| 29632 | + | |
| 29633 | + | |
| 29634 | + | |
| 29635 | + | |
| 29636 | + | |
| 29637 | + | |
| 29638 | + | |
| 29639 | + | |
| 29640 | + | |
| 29641 | + | |
| 29642 | + | |
| 29643 | + | |
| 29644 | + | |
| 29645 | + | |
| 29646 | + | |
| 29647 | + | |
| 29648 | + | |
| 29649 | + | |
| 29650 | + | |
| 29651 | + | |
| 29652 | + | |
| 29653 | + | |
| 29654 | + | |
| 29655 | + | |
| 29656 | + | |
| 29657 | + | |
| 29658 | + | |
| 29659 | + | |
| 29660 | + | |
| 29661 | + | |
| 29662 | + | |
| 29663 | + | |
| 29664 | + | |
| 29665 | + | |
| 29666 | + | |
| 29667 | + | |
| 29668 | + | |
| 29669 | + | |
| 29670 | + | |
| 29671 | + | |
| 29672 | + | |
| 29673 | + | |
| 29674 | + | |
| 29675 | + | |
| 29676 | + | |
| 29677 | + | |
| 29678 | + | |
| 29679 | + | |
| 29680 | + | |
| 29681 | + | |
| 29682 | + | |
| 29683 | + | |
| 29684 | + | |
| 29685 | + | |
| 29686 | + | |
| 29687 | + | |
| 29688 | + | |
| 29689 | + | |
| 29690 | + | |
| 29691 | + | |
| 29692 | + | |
| 29693 | + | |
| 29694 | + | |
| 29695 | + | |
| 29696 | + | |
| 29697 | + | |
| 29698 | + | |
| 29699 | + | |
| 29700 | + | |
| 29701 | + | |
| 29702 | + | |
| 29703 | + | |
| 29704 | + | |
29577 | 29705 | | |
29578 | 29706 | | |
29579 | 29707 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5956 | 5956 | | |
5957 | 5957 | | |
5958 | 5958 | | |
| 5959 | + | |
| 5960 | + | |
5959 | 5961 | | |
5960 | 5962 | | |
5961 | 5963 | | |
| |||
6069 | 6071 | | |
6070 | 6072 | | |
6071 | 6073 | | |
6072 | | - | |
| 6074 | + | |
6073 | 6075 | | |
6074 | 6076 | | |
6075 | 6077 | | |
| |||
6135 | 6137 | | |
6136 | 6138 | | |
6137 | 6139 | | |
6138 | | - | |
6139 | | - | |
6140 | | - | |
| 6140 | + | |
| 6141 | + | |
6141 | 6142 | | |
6142 | 6143 | | |
6143 | 6144 | | |
| |||
6197 | 6198 | | |
6198 | 6199 | | |
6199 | 6200 | | |
6200 | | - | |
6201 | 6201 | | |
6202 | 6202 | | |
6203 | 6203 | | |
6204 | 6204 | | |
6205 | 6205 | | |
6206 | 6206 | | |
6207 | | - | |
6208 | | - | |
6209 | | - | |
6210 | | - | |
6211 | | - | |
6212 | | - | |
6213 | | - | |
6214 | 6207 | | |
6215 | 6208 | | |
6216 | | - | |
6217 | | - | |
| 6209 | + | |
| 6210 | + | |
6218 | 6211 | | |
6219 | | - | |
| 6212 | + | |
6220 | 6213 | | |
6221 | 6214 | | |
6222 | 6215 | | |
6223 | | - | |
6224 | 6216 | | |
6225 | 6217 | | |
6226 | 6218 | | |
| |||
6238 | 6230 | | |
6239 | 6231 | | |
6240 | 6232 | | |
6241 | | - | |
| 6233 | + | |
6242 | 6234 | | |
6243 | 6235 | | |
6244 | 6236 | | |
| |||
6309 | 6301 | | |
6310 | 6302 | | |
6311 | 6303 | | |
6312 | | - | |
| 6304 | + | |
6313 | 6305 | | |
6314 | | - | |
6315 | | - | |
| 6306 | + | |
6316 | 6307 | | |
6317 | 6308 | | |
6318 | 6309 | | |
| 6310 | + | |
| 6311 | + | |
| 6312 | + | |
| 6313 | + | |
| 6314 | + | |
| 6315 | + | |
| 6316 | + | |
| 6317 | + | |
| 6318 | + | |
| 6319 | + | |
| 6320 | + | |
6319 | 6321 | | |
6320 | 6322 | | |
6321 | 6323 | | |
| |||
0 commit comments