@@ -4,7 +4,9 @@ As explained in the [theming guide](./theming.md), a theme in Angular Material c
4
4
configurations for the ` color ` , ` density ` and ` typography ` systems. As some of these individual
5
5
systems have default configurations, some usage patterns may cause duplication in the CSS output.
6
6
7
- Below is an example of a pattern that generates duplicative theme styles:
7
+ Below are examples of patterns that generate duplicative theme styles:
8
+
9
+ ** Example #1 **
8
10
9
11
``` scss
10
12
$light-theme : mat-light-theme ((color : ...));
@@ -36,7 +38,44 @@ selector. Replace the `angular-material-theme` mixin and include the dark theme
36
38
}
37
39
```
38
40
39
- Typography can also be configured via Sass mixin; see ` angular-material-typography ` .
41
+ Typography can also be configured via Sass mixin; see ` angular-material-typography ` .
42
+
43
+ ** Example #2 **
44
+
45
+ Theme styles could also be duplicated if individual theme mixins are used. For example:
46
+
47
+ ``` scss
48
+ @include angular-material-theme ($my-theme );
49
+
50
+ .my-custom-dark-button {
51
+ // This will also generate the default density styles again.
52
+ @include mat-button-theme ($my-theme );
53
+ }
54
+ ```
55
+
56
+ To avoid this duplication of styles, use the dedicated mixin for the color system and
57
+ extract the configuration for the color system from the theme.
58
+
59
+ ``` scss
60
+ .my-custom-dark-button {
61
+ // This will only generate the color styles for `mat-button`.
62
+ @include mat-button-color (map_get ($my-theme , color ));
63
+ }
64
+ ```
65
+
66
+ Alternatively, a new theme object can be constructed that explicitly disables
67
+ styles from other systems such as ` density ` or ` typography ` :
68
+
69
+ ``` scss
70
+ .my-custom-dark-button {
71
+ $only-color-theme : map_merge ($my-theme , (
72
+ density: null,
73
+ typography: null
74
+ ));
75
+ // This will only generate the color styles for `mat-button`.
76
+ @include mat-button-theme ($only-color-theme );
77
+ }
78
+ ```
40
79
41
80
#### Disabling duplication warnings
42
81
0 commit comments