postcss / postcss-dark-theme-class

PostCSS plugin to make dark/light theme switcher by copying styles from media query to special class
MIT License
160 stars 16 forks source link

Add light-dark() support #26

Closed VladBrok closed 8 months ago

VladBrok commented 8 months ago

Closes #25

If we try to convert code from this:

a {
  color: light-dark(black, white);
}

To this:

:where(html.is-light) a {
  color: black;
}
:where(html.is-dark) a {
  color: white;
}

Then it will not respect the user's preferred color scheme specified via system settings. So we also need to use prefers-color-scheme media query. This plugin already can transform prefers-color-scheme, so if we convert this:

a {
  color: light-dark(black, white);
}

To this:

@media (prefers-color-scheme: dark) {
  a {
    color: white;
  }
}

@media (prefers-color-scheme: light) {
  a {
    color: black;
  }
}

then the current plugin code will run and we will get the following:

@media (prefers-color-scheme: dark) {
  :where(html:not(.is-light)) a {
    color: white;
  }
}
:where(html.is-dark) a {
  color: white;
}

@media (prefers-color-scheme: light) {
  :where(html:not(.is-dark)) a {
    color: black;
  }
}
:where(html.is-light) a {
  color: black;
}
ai commented 8 months ago

Thanks!

Do you have Twitter and Mastodon to mention you?

VladBrok commented 8 months ago

Thanks!

Do you have Twitter and Mastodon to mention you?

yes, I have Twitter: https://twitter.com/VladBrok99