Looking at the Angular Material documentation, they recommend using a -theme
file per component to manage applying any theme-related styles to a specific class.
From my perspective, some downsides to this approach are:
- quite verbose
- splits up the style into two different locations
- all your frontend devs need to understand how Angular Material colours work
- makes it harder to change values (e.g. we might've been using
mat-color($primary, 200)
for border colours and now want to change it tomat-color($primary, 300)
. This will have been repeated all throughout the codebase.
Given a consistent design language, there will only be a subset of colors that will be used (e.g. 4 colors from the primary palette, 3 from the accent palette, a few different foreground / background colors, etc).
Given the above, doesn't it make more sense to have a _colors.scss
that defines the exact colors using the theme rather than hoping developers extract the correct value from the theme each time?
e.g. maybe something like:
$clr-primary-default: mat-color($primary);
$clr-primary-contrast: mat-color($primary, default-contrast);
$clr-primary-light: mat-color($primary, lighter);
$clr-primary-dark: mat-color($primary, darker);
$clr-accent-default: mat-color($accent);
$clr-accent-light: mat-color($accent, lighter);
$clr-accent-dark: mat-color($accent, darker);
$clr-default-text: mat-color($foreground);
$clr-secondary-text: mat-color($foreground, secondary-text);
//etc
Then rather than creating a separate -theme
file for each component that requires specific colors, I can simply import the colors.scss
file and use the variables directly in the *.component.scss
file.
Just wanting to validate that the above is sound and that I'm not missing anything obvious that's going to cause pain down the track?
The other tricky part is how to actually define these in a separate colors
file efficiently given the file will need access to the theme data.