Skip to content

Commit

Permalink
Allow @variant to be used at the top-level
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
thecrypticace committed Jan 31, 2025
1 parent 88c8906 commit 598e76e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,38 @@ describe('@variant', () => {
background: white;
}
}
@variant hover {
@variant landscape {
.btn2 {
color: red;
}
}
}
@variant hover {
.foo {
color: red;
}
@variant landscape {
.bar {
color: blue;
}
}
.baz {
@variant portrait {
color: green;
}
}
}
@media something {
@variant landscape {
@page {
color: red;
}
}
}
`,
[],
),
Expand All @@ -3410,6 +3442,38 @@ describe('@variant', () => {
.btn {
background: #fff;
}
}
@media (hover: hover) {
@media (orientation: landscape) {
:scope:hover .btn2 {
color: red;
}
}
:scope:hover .foo {
color: red;
}
@media (orientation: landscape) {
:scope:hover .bar {
color: #00f;
}
}
@media (orientation: portrait) {
:scope:hover .baz {
color: green;
}
}
}
@media something {
@media (orientation: landscape) {
@page {
color: red;
}
}
}"
`)
})
Expand Down
12 changes: 12 additions & 0 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ async function parseCss(
return WalkAction.Stop
}
})

// No `@slot` found, so this is still a regular `@variant` at-rule
if (node.name === '@variant') {
variantNodes.push(node)
}
}
}

Expand Down Expand Up @@ -428,6 +433,13 @@ async function parseCss(
replaceWith(node.nodes)
}

walk(node.nodes, (node) => {
if (node.kind !== 'at-rule') return
if (node.name !== '@variant') return

variantNodes.push(node)
})

return WalkAction.Skip
}

Expand Down

0 comments on commit 598e76e

Please sign in to comment.