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
feat(internals): add rules for border-top/right/bottom/left-color classes #78
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { handler as h } from '#utils'; | ||
import { handler as h, directionMap } from '#utils'; | ||
|
||
export const internalRules = [ | ||
[/^i-bg-(.+)$/, ([, cssvar]) => ({ 'background-color': h.warpToken(cssvar) })], | ||
[/^i-text-(.+)$/, ([, cssvar]) => ({ color: h.warpToken(cssvar) })], | ||
[/^i-border-(.+)$/, ([, cssvar]) => ({ 'border-color': h.warpToken(cssvar) })], | ||
[/^i-border-([rltb])-(.+)$/, ([_, direction, cssvar]) => { | ||
if (direction in directionMap && cssvar != null) { | ||
return directionMap[direction].map( | ||
(dir) => [`border${dir}-color`, h.warpToken(cssvar)], | ||
); | ||
} | ||
}], | ||
]; |
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
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
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.
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.
No big thing 😄 but we don't use underscore variables for non-needed matches in the other regex callbacks.
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.
And another thing... I am not quite sure how this works, but will it be a problem that for example
i-border-r-$color-alert-warning-border
will be matched by both/^i-border-(.+)$
and/^i-border-([rltb])-(.+)$/
? 🤔 🤷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.
Apparently it works, according to the test output... but I can't understand how. 🤷 🙈 😅 😆
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.
Removed underscore in 20824bf
As for why the
/^i-border-(.+)$/
rule didn't work fori-border-l-$color-alert-warning-border
, it was because the second argument of the callback was then"l-$color-alert-warning-border"
, and that when passed to thewarpToken
handler didn't matchstr.match(/^\$\S/)
check. As a result the CSS property was assignedundefined
as value, which makes unocss not generate any CSS for that selector. Does that make sense? 😄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.
Ah ok I think I get it... it DOES match the first regex and tries to create the border-color rule, but since
h.warpToken()
does not return anything the whole rule gets disposed. It then also matches the next rule, which creates the correct rule using the variable. Did I get that correct? 😄 ...Reading your comment again, I see that was about exactly what you said. 😄 Thanks. 🙏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.
As far as I checked, the
cssvar
string needs to start with a$
to be matched with the regex (it's because we say so with^
at the beginning of the group). See here: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.
Just trying to understand, and I am NOT saying that you should do this (😅)... but the best way would have been to write the first regex as to match anything but
[rltb]-
so that it wouldn't even try to create the rules? Is that correct? 🤷 🙂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.
I think I understand now!
I think the reason for this check to be in the
warpToken
handler was that we'd keep the logic for ensuring correct prefixing in one place. So if we were to change how we separate prefixes from actual tokens, we wouldn't need to do it wherever that token could be used.There might also come a time when we rewrite how the color tokens are translated into CSS in our preset, so I'm not sure if it's worth rewriting too much at this point. But that topic is still up for discussion at some point in the future (related potential task)
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.
No, nothing that needs to be changed. 🙂 This just made me understand more about how this whole thing is working. 😄 Thanks for taking your time explaining. 🙂 🙏