Can anyone explain the benefits of the ColorScheme...
# compose
m
Can anyone explain the benefits of the ColorSchemeKeyTokens in Material3. I get the idea of having an enumeration available, and resolving that to something in the current ColorScheme instance. I’m just curious why
ColorSchemeKeyTokens.surface.toColor()
is considered better than just something like:
MaterialTheme.colorScheme.surface
But given that all these key token enumerations are internal, i don’t see a huge benefit to consumers of the material library.
h
They're part of a design system and actually they expose predefined values, you're given an option to provide yours
m
You’re given an option to provide your own by constructing a ColorScheme instance with a function other than something like
lightColorScheme
or
darkColorScheme
. The actual class ColorSchemeKeyTokens is internal to the material3 library, and thus can’t be accessed by consumers. As such it provides little to no benefit outside of the library itself. What i’m curious about is what are the perceived benefits inside of the library. We have our own custom design system, and i was considering whether to implement this pattern or not, or stick with people directly referencing the tokens via the colors class we keep in a composition local
e
They could be useful in non composable contexts
m
I guess if you want to pass a reference to a token around instead of say an actual color value it could prove useful. Personally, i like that fact that all the tokens get enumerated in this way instead of as member properties in the ColorScheme class. Why they are internal I have no idea, when they could be useful to consumers. It’s more discoverable this way. Which is why i’m contemplating adding this pattern to our design system library, and reworking some of the internal code use the token enums rather than directly going through the colors instance.
h
If you have design system that's your own, it's a good practice to provide them too, as I've said they give an option to provide yours with the theme and if you feel like you have lots of components that will be related to them, it's better to have them as defaults