Skip to content

Commit

Permalink
Fix to respect !important
Browse files Browse the repository at this point in the history
  • Loading branch information
yuheiy committed Apr 20, 2024
1 parent aaee7ba commit ee66b3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function addColorSchemeMedia(isDark, propValue, declaration, postcss) {
postcss.rule({
nodes: [
postcss.decl({
important: declaration.important,
prop: declaration.prop,
value: propValue
})
Expand Down
24 changes: 24 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,30 @@ html:where(.is-light) {
)
})

test('transforms light-dark() with !important', () => {
run(
`html {
border: 1px solid light-dark(white, black) !important
}`,
`@media (prefers-color-scheme:dark) {
html:where(:not(.is-light)) {
border: 1px solid black !important
}
}
html:where(.is-dark) {
border: 1px solid black !important
}
@media (prefers-color-scheme:light) {
html:where(:not(.is-dark)) {
border: 1px solid white !important
}
}
html:where(.is-light) {
border: 1px solid white !important
}`
)
})

test('transforms nested light-dark()', () => {
run(
`html {
Expand Down

0 comments on commit ee66b3f

Please sign in to comment.