@@ -9,57 +9,65 @@ Below are examples of patterns that generate duplicative theme styles:
99** Example #1 **
1010
1111``` scss
12- $light-theme : mat-light-theme ((color : ...));
13- $dark-theme : mat-dark-theme ((color : ...));
12+ @use ' ~@angular/material' as mat ;
13+
14+ $light-theme : mat .define-light-theme ((color : ...));
15+ $dark-theme : mat .define-dark-theme ((color : ...));
1416
1517// Generates styles for all systems configured in the theme. In this case, color styles
1618// and default density styles are generated. Density is in themes by default.
17- @include angular-material-theme ($light-theme );
19+ @include mat . all-component-themes ($light-theme );
1820
1921.dark-theme {
2022 // Generates styles for all systems configured in the theme. In this case, color styles
2123 // and the default density styles are generated. **Note** that this is a problem because it
2224 // means that density styles are generated *again*, even though only the color should change.
23- @include angular-material-theme ($dark-theme );
25+ @include mat . all-component-themes ($dark-theme );
2426}
2527```
2628
2729To fix this, you can use the dedicated mixin for color styles for the ` .dark-theme `
28- selector. Replace the ` angular-material-theme ` mixin and include the dark theme using the
29- ` angular-material-color ` mixin. For example:
30+ selector. Replace the ` all-component-themes ` mixin and include the dark theme using the
31+ ` all-component-colors ` mixin. For example:
3032
3133``` scss
34+ @use ' ~@angular/material' as mat ;
35+
3236...
33- @include angular-material-theme ($light-theme );
37+ @include mat . all-component-themes ($light-theme );
3438
3539.dark-theme {
3640 // This mixin only generates the color styles now.
37- @include angular-material-color ($dark-theme );
41+ @include mat . all-component-colors ($dark-theme );
3842}
3943```
4044
41- Typography can also be configured via Sass mixin; see ` angular-material-typography ` .
45+ Typography can also be configured via Sass mixin; see ` all-component-typographies ` .
4246
4347** Example #2 **
4448
4549Theme styles could also be duplicated if individual theme mixins are used. For example:
4650
4751``` scss
48- @include angular-material-theme ($my-theme );
52+ @use ' ~@angular/material' as mat ;
53+
54+ @include mat .all-component-themes ($my-theme );
4955
5056.my-custom-dark-button {
5157 // This will also generate the default density styles again.
52- @include mat- button-theme ($my-theme );
58+ @include mat . button-theme ($my-theme );
5359}
5460```
5561
5662To avoid this duplication of styles, use the dedicated mixin for the color system and
5763extract the configuration for the color system from the theme.
5864
5965``` scss
66+ @use ' ~@angular/material' as mat ;
67+
6068.my-custom-dark-button {
6169 // This will only generate the color styles for `mat-button`.
62- @include mat- button-color ($my-theme );
70+ @include mat . button-color ($my-theme );
6371}
6472```
6573
@@ -69,10 +77,12 @@ If your application intentionally duplicates styles, a global Sass variable can
6977set to disable duplication warnings from Angular Material. For example:
7078
7179``` scss
72- $mat-theme-ignore-duplication-warnings : true;
80+ @use ' ~@angular/material' as mat ;
81+
82+ mat .$theme-ignore-duplication-warnings : true;
7383
7484// Include themes as usual.
75- @include angular-material-theme ($light-theme );
85+ @include mat . all-component-themes ($light-theme );
7686
7787...
7888```
0 commit comments