I have a simple SASS code that may be working like when the user has on his device set preferred color scheme dark the parameters from %dark-theme will extend to <body>
and also when the user has preferred color scheme light the %light-theme will be extended instead of %dark-theme to <body>
.
The same parameters which are used in %dark-theme and %light-theme may be extended on <body>
when <body>
have set id to #switched-dark-mode or #switched-light-mode. This IDs are set by Javascript after user switch the theme color.
Is there any solution to how I can make my SCSS clear and parameters which are used in @extends write only one time and use them in media query and also in ID selector?
MY CODE:
%dark-theme {
background: black;
color: white;
}
%light-theme {
background: white;
color: black;
}
@media (prefers-color-scheme: dark) {
body {
@extend %dark-theme;
}
}
@media (prefers-color-scheme: light) {
body {
@extend %light-theme;
}
}
body {
&#switched-dark-mode {
@extend %dark-theme;
}
&#switched-light-mode {
@extend %light-theme;
}
}