Skip to content

Commit e32751c

Browse files
committed
handle @variant inside @custom-variant's
1 parent ad0a167 commit e32751c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/tailwindcss/src/compat/plugin-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function buildPluginApi({
154154

155155
// CSS-in-JS object
156156
else if (typeof variant === 'object') {
157-
designSystem.variants.fromAst(name, objectToAst(variant))
157+
designSystem.variants.fromAst(name, objectToAst(variant), designSystem)
158158
}
159159
},
160160
matchVariant(name, fn, options) {

packages/tailwindcss/src/variants.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ export class Variants {
8383
})
8484
}
8585

86-
fromAst(name: string, ast: AstNode[]) {
86+
fromAst(name: string, ast: AstNode[], designSystem: DesignSystem) {
8787
let selectors: string[] = []
8888

89+
let usesAtVariant = false
8990
walk(ast, (node) => {
9091
if (node.kind === 'rule') {
9192
selectors.push(node.selector)
93+
} else if (node.kind === 'at-rule' && node.name === '@variant') {
94+
usesAtVariant = true
9295
} else if (node.kind === 'at-rule' && node.name !== '@slot') {
9396
selectors.push(`${node.name} ${node.params}`)
9497
}
@@ -98,12 +101,11 @@ export class Variants {
98101
name,
99102
(r) => {
100103
let body = structuredClone(ast)
104+
if (usesAtVariant) substituteAtVariant(body, designSystem)
101105
substituteAtSlot(body, r.nodes)
102106
r.nodes = body
103107
},
104-
{
105-
compounds: compoundsForSelectors(selectors),
106-
},
108+
{ compounds: compoundsForSelectors(selectors) },
107109
)
108110
}
109111

0 commit comments

Comments
 (0)