@@ -9,57 +9,65 @@ Below are examples of patterns that generate duplicative theme styles:
9
9
** Example #1 **
10
10
11
11
``` 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 : ...));
14
16
15
17
// Generates styles for all systems configured in the theme. In this case, color styles
16
18
// 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 );
18
20
19
21
.dark-theme {
20
22
// Generates styles for all systems configured in the theme. In this case, color styles
21
23
// and the default density styles are generated. **Note** that this is a problem because it
22
24
// 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 );
24
26
}
25
27
```
26
28
27
29
To 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:
30
32
31
33
``` scss
34
+ @use ' ~@angular/material' as mat ;
35
+
32
36
...
33
- @include angular-material-theme ($light-theme );
37
+ @include mat . all-component-themes ($light-theme );
34
38
35
39
.dark-theme {
36
40
// This mixin only generates the color styles now.
37
- @include angular-material-color ($dark-theme );
41
+ @include mat . all-component-colors ($dark-theme );
38
42
}
39
43
```
40
44
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 ` .
42
46
43
47
** Example #2 **
44
48
45
49
Theme styles could also be duplicated if individual theme mixins are used. For example:
46
50
47
51
``` scss
48
- @include angular-material-theme ($my-theme );
52
+ @use ' ~@angular/material' as mat ;
53
+
54
+ @include mat .all-component-themes ($my-theme );
49
55
50
56
.my-custom-dark-button {
51
57
// This will also generate the default density styles again.
52
- @include mat- button-theme ($my-theme );
58
+ @include mat . button-theme ($my-theme );
53
59
}
54
60
```
55
61
56
62
To avoid this duplication of styles, use the dedicated mixin for the color system and
57
63
extract the configuration for the color system from the theme.
58
64
59
65
``` scss
66
+ @use ' ~@angular/material' as mat ;
67
+
60
68
.my-custom-dark-button {
61
69
// This will only generate the color styles for `mat-button`.
62
- @include mat- button-color ($my-theme );
70
+ @include mat . button-color ($my-theme );
63
71
}
64
72
```
65
73
@@ -69,10 +77,12 @@ If your application intentionally duplicates styles, a global Sass variable can
69
77
set to disable duplication warnings from Angular Material. For example:
70
78
71
79
``` scss
72
- $mat-theme-ignore-duplication-warnings : true;
80
+ @use ' ~@angular/material' as mat ;
81
+
82
+ mat .$theme-ignore-duplication-warnings : true;
73
83
74
84
// Include themes as usual.
75
- @include angular-material-theme ($light-theme );
85
+ @include mat . all-component-themes ($light-theme );
76
86
77
87
...
78
88
```
0 commit comments