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(preset-mini): pseudo-class function for custom arguments #2694
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ef231db
feat: add has variants
enpitsuLin e93cac5
test: add test target and update snapshot
enpitsuLin 7aaafb4
chore: `has-*` shouldn't be experimental
enpitsuLin 8332f5b
feat: add `peer-has-*` and `group-has-*` variant
enpitsuLin 54741f5
test: update output snapshot
enpitsuLin 174e5db
fix: undefined bracketValue
enpitsuLin c8cbe35
Merge branch 'unocss:main' into feat/has-variants
enpitsuLin 248eaa5
refactor: implemant w/ `taggedPseudoClassMatcher`
enpitsuLin cc401ff
refactor: all variants move to preset-mini
enpitsuLin 5767af0
test: update test assets and snapshot
enpitsuLin a03188e
test: revert test snapshot output
enpitsuLin 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
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { Variant } from '@unocss/core' | ||
import { h, variantGetBracket } from '@unocss/preset-mini/utils' | ||
|
||
export const variantHasPseudo: Variant[] = [ | ||
{ | ||
name: 'has', | ||
match(input, ctx) { | ||
const body = variantGetBracket('has-', input, ctx.generator.config.separators) | ||
if (!body) | ||
return | ||
|
||
const [match, reset] = body | ||
const bracketValue = h.bracket(match) | ||
if (!bracketValue) | ||
return | ||
|
||
if (match) { | ||
return { | ||
matcher: reset, | ||
handle: (input, next) => next({ | ||
...input, | ||
selector: `${input.selector || ''}:has(${bracketValue})`, | ||
}), | ||
} | ||
} | ||
}, | ||
}, | ||
{ | ||
name: 'group-has', | ||
match(input, ctx) { | ||
const body = variantGetBracket('group-has-', input, ctx.generator.config.separators) | ||
if (!body) | ||
return | ||
|
||
const [match, reset] = body | ||
const bracketValue = h.bracket(match) | ||
if (!bracketValue) | ||
return | ||
|
||
if (match) { | ||
return { | ||
matcher: reset, | ||
handle: (input, next) => next({ | ||
...input, | ||
selector: `.group:has(${bracketValue}) ${input.selector || ''}`, | ||
}), | ||
} | ||
} | ||
}, | ||
}, | ||
{ | ||
name: 'peer-has', | ||
match(input, ctx) { | ||
const body = variantGetBracket('peer-has-', input, ctx.generator.config.separators) | ||
if (!body) | ||
return | ||
|
||
const [match, reset] = body | ||
const bracketValue = h.bracket(match) | ||
if (!bracketValue) | ||
return | ||
|
||
if (match) { | ||
return { | ||
matcher: reset, | ||
handle: (input, next) => next({ | ||
...input, | ||
selector: `.peer:has(${bracketValue}) ~ ${input.selector || ''}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for |
||
}), | ||
} | ||
} | ||
}, | ||
}, | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
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.
We have an option to toggle
.group
style:unocss/packages/preset-mini/src/_variants/pseudo.ts
Line 254 in 5c9fc99
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 have done this and moved to the
preset-mini
package, had to add some code because the previous implementation might work not perfectly with custom arguments (and I'm kinda confused with it).And implement both four pseudo-class functions with it (so change the pr title