-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Improve arbitrary value support #5568
Merged
Merged
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
d3cb1cc
to
60148c2
Compare
RobinMalfait
commented
Sep 22, 2021
src/util/pluginUtils.js
Outdated
Comment on lines
312
to
257
let idx = input.indexOf(delim) | ||
if (idx === -1) return [undefined, input] | ||
return [input.slice(0, idx), input.slice(idx + 1)] |
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.
Changed this a little, because I wanted to get the [typehint, rest]
and if there is no typehint, I wanted [undefined, rest]
. The previous code would have generated [rest]
for the last case.
db53b1b
to
4194b96
Compare
This will allow us to use `outline-[OUTLINE,OPTIONAL_OFFSET]` Input: ```html outline-[2px_solid_black] ``` Output: ```css .outline-\[2px_solid_black\] { outline: 2px solid black; outline-offset: 0; } ``` --- Input: ```html outline-[2px_solid_black,2px] ``` Output: ```css .outline-\[2px_solid_black\2c 2px\] { outline: 2px solid black; outline-offset: 2px; } ```
Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types These data types will be used to "guess" the type of an arbitrary value if there is some ambiguity going on. For example: ``` bg-[#0088cc] -> This is a `color` -> `background-color` bg-[url('...')] -> This is a `url` -> `background-image` ``` If you are using css variables, then there is no way of knowing which type it is referring to, in that case you can be explicit: ``` bg-[color:var(--value)] -> This is a `color` -> `background-color` bg-[url:var(--value)] -> This is a `url` -> `background-image` ``` When you explicitly pass a data type, then we bypass the type system and assume you are right. This is nice in a way because now we don't have to run all of the guessing type code. On the other hand, you can introduce runtime issues that we are not able to detect: ``` :root { --value: 12px; } /* Later... */ bg-[color:var(--value)] -> Assumes `color` -> *eventually* -> `background-color: 12px` ```
4194b96
to
d499c59
Compare
23 tasks
45 tasks
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.
Edit: This PR is fairly big and contains multiple scopes, so I will be splitting this PR into multiple PR's!
PR 1: #5585
PR 2: #5587
PR 3: #5590
PR 4: #5588
This PR will improve arbitrary value support for various plugins. I had to introduce a few more typehints, the names can still be changed if we want to!
Here are the changes to various plugins:
Background images
Added an
url
typehint, that checks for theurl
prefix.Input:
Output:
Background size & background position
Both
background-size
andbackground-position
can acceptlength
values like200px 100px
. This means that this is ambiguous, for this reason I introduced asize
andposition
typehint.Input:
Output:
Font family & font weight
Font families and font weights can be ambiguous but they aren't always. For example,
font-[300]
is a font-weight because you can't have afont-family
of value300
. Howeverfont-[black]
can both refer tofont-family: black;
andfont-weight: black;
For this reason I introduced
family
andweight
typehints.Input:
Output:
Outline
The outline plugin can be configured as an array in the config, therefore I mimicked this behaviour in the arbitrary value support for this plugin as well. The first argument will be the
outline
, the second argument will be theoutline-offset
which defaults to0
.Input:
Output: