-
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
Add functional utility syntax #15455
Open
RobinMalfait
wants to merge
9
commits into
next
Choose a base branch
from
feat/functional-utility-syntax
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+836
−5
Conversation
This file contains 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
RobinMalfait
force-pushed
the
feat/functional-utility-syntax
branch
from
December 20, 2024 14:23
bf7dc05
to
13e75f4
Compare
In Resolving against |
it was a typo — fixed. |
- If you are using a bare value or modifier that is a number, then we make sure that it is a valid multiplier of `0.25` - If you are using a bare value or modifier that is a percentage, then we make sure that it is a valid positive integer. - If you are using a fraction, then we make sure that both the numerator and denominator are positive integers. - If the bare value resolves to a non-ratio value, and if a modifier is used, then we need to make sure that the modifier resolves as well. E.g.: `example-1/2.3` this won't resolve to a `ratio` because the denominator is invalid. This will resolve to an `integer` or `number` for the value of `1`, but then we need to make sure that `2.3` is a valid modifier.
RobinMalfait
force-pushed
the
feat/functional-utility-syntax
branch
from
December 22, 2024 23:21
c91ccb7
to
4eba187
Compare
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 support for functional utilities constructed via CSS.
Registering functional utilities in CSS
To register a functional utility in CSS, use the
@utility potato-*
syntax, where the-*
signals that this is a functional utility:Resolving values
The special
value(…)
function is used to resolve the utility value.Resolving against
@theme
valuesTo resolve the value against a set of theme keys, use
value(--theme-key-*)
:Bare values
To resolve the value as a bare value, use
value({type})
, where{type}
is the data type you want to validate the bare value as:Arbitrary values
To support arbitrary values, use
value([{type}])
(notice the square brackets) to tell Tailwind which types are supported as an arbitrary value:Supporting theme values, bare values, and arbitrary values together
All three forms of the
value(…)
function can be used within a rule as multiple declarations, and any declarations that fail to resolve will be omitted in the output:This makes it possible to treat the value differently in each case if necessary, for example translating a bare integer to a percentage:
The
value(…)
function can also take multiple arguments and resolve them left to right if you don't need to treat the return value differently in different cases:Negative values
To support negative values, register separate positive and negative utilities into separate declarations:
Modifiers
Modifiers are handled using the
modifier(…)
function which works exactly like thevalue(…)
function but operates on a modifier if present:If a modifier isn't present, any declaration depending on a modifier is just not included in the output.
Fractions
To handle fractions, we rely on the CSS
ratio
data type. If this is used withvalue(…)
, it's a signal to Tailwind to treat the value + modifier as a single value: