Refactor palette and component styles #5103
Replies: 4 comments 5 replies
-
Implementing this has the potential to abstract the logic into a scss function and once /* While light-dark is not supported */
function light-dark($light, $dark) {
@return var(--post-light-mode, #{$light}) var(--post-dark-mode, #{$dark});
}
@mixin mode($mode: light) {
@if ($mode == light) {
--light-mode: initial;
--dark-mode: ;
} @else {
--light-mode: ;
--dark-mode: initial;
}
}
/* When light dark is supported */
function light-dark($light, $dark) {
@return light-dark(#{$light}, #{$dark});
}
@mixin mode($mode: light) {
color-scheme: $mode;
} |
Beta Was this translation helpful? Give feedback.
-
This approach is interesting, however it does not solve the current issue. The complexity does not lie within the fact that the This forces us to resolve the token value in advance by parsing the palette tokens in a very specific way. It is also the case on this proposed approach: it is still needed to pass the argument to the Therefore, expanding the solution to other backgrounds or containers will necessitate exactly the same changes as with the current solution. Hope that clarifies |
Beta Was this translation helpful? Give feedback.
-
Web component POC: https://codepen.io/tuelsch/pen/dPyqGgd?editors=1100 |
Beta Was this translation helpful? Give feedback.
-
Conclusions
Currently discussed solutions
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Our design system implements palette styles in a custom way. While the current implementation works fine for the current palettes, it's very difficult to enhance or expand the technique for other elements.
We just discovered a new technique how to implement these styles, with an approach very similar to what the native
light-dark()
function would do. Which by the way does not yet supported all browsers we need to.To show how it works, we've created a codepen: https://codepen.io/oliverschuerch/pen/QwWBjxZ
Quick explanation:
We define two different custom-properties which are used to define the current color-scheme,
--light-mode
and--dark-mode
.One of them is holding the value
initial
, the other is set to an empty string. Both will be used to create some kind of OR statment.Because whichever variable is set to
initial
will cause the associated fallback value to be applied, while the variable set to;
is considered to be "defined", but it only adds a whitespace to the final value.Example:
This would meen, we need to implement all of our component tokens the way showed above, which can be done easily, by adapting the output of the existing
tokens.get()
SCSS function.The example shows also, how we can redefine
--light-mode
and--dark-mode
for specific selectors like the.palette-default
,.palette-accent
or something totally independent like.banner
.4 votes ·
Beta Was this translation helpful? Give feedback.
All reactions