I think you want a .scss file where you put all your custom color variables and use them to generic CSSclass to apply all over your apps.
Then you need to do this things.
- Uses a theme.scss file which holds current material theme/ dynamic themes scss
@import '~@angular/material/theming';
@import './mytheme-sidemenu.scss';
// Primary theme
@include mat-core();
$mytheme-app-primary: mat-palette($mat-deep-purple, 700, 600);
$mytheme-app-accent: mat-palette($mat-red, A200, 900, A100);
$mytheme-app-warn: mat-palette($mat-deep-orange);
$mytheme-app-theme: mat-light-theme($mytheme-app-primary, $mytheme-app-accent, $mytheme-app-warn);
@include angular-material-theme($mytheme-app-theme);
// Secondary Theme
.mytheme-alt-theme {
$mytheme-alt-primary: mat-palette($mat-teal, 500);
$mytheme-alt-accent: mat-palette($mat-orange, 500);
$mytheme-alt-warn: mat-palette($mat-red);
$mytheme-alt-theme: mat-light-theme($mytheme-alt-primary, $mytheme-alt-accent, $mytheme-alt-warn);
@include angular-material-theme($mytheme-alt-theme);
}
.mytheme-another-alt-theme{
$mytheme-another-alt-primary: mat-palette($mat-blue, 500);
$mytheme-another-alt-accent: mat-palette($mat-yellow, 500);
$mytheme-another-alt-warn: mat-palette($mat-green);
$mytheme-another-alt-theme: mat-light-theme($mytheme-another-alt-primary, $mytheme-another-alt-accent, $mytheme-another-alt-warn);
@include angular-material-theme($mytheme-another-alt-theme);
}
// Using the $theme variable from the pre-built theme you can call the theming function
@include mytheme-sidemenu($mytheme-app-theme);
- Uses separate scss file to hold your custom css class
// Import all the tools needed to customize the theme and extract parts of it
@import "~@angular/material/theming";
// Define a mixin that accepts a theme and outputs the color styles for the component.
@mixin mytheme-sidemenu($theme) {
// Extract whichever individual palettes you need from the theme.
$primary: map-get($theme, primary);
$accent: map-get(
$theme,
accent
); // Use mat-color to extract individual colors from a palette as necessary.
.col-primary {
color: mat-color($primary, 500) !important;
}
.col-accent {
color: mat-color($accent, 300) !important;
}
}
- Now you can use your custom css classes over the app and don't forget to put the scss file link within your angular.json/angular-cli.json
You can also use this classes too:
.col-primary {
& .hue {
&-50 {
color: mat-color($primary, 50) !important;
}
&-100 {
color: mat-color($primary, 100) !important;
}
.
.
.
&-800 {
color: mat-color($primary, 800) !important;
}
}
}
Also, you can see the running Example of this code here