|
82 | 82 | @return $theme;
|
83 | 83 | }
|
84 | 84 |
|
| 85 | +// Creates a backwards compatible theme. Previously in Angular Material, theme objects |
| 86 | +// contained the color configuration directly. With the recent refactoring of the theming |
| 87 | +// system to allow for density and typography configurations, this is no longer the case. |
| 88 | +// To ensure that constructed themes which will be passed to custom theme mixins do not break, |
| 89 | +// we copy the color configuration and put its properties at the top-level of the theme object. |
| 90 | +// Here is an example of a pattern that should still work until it's officially marked as a |
| 91 | +// breaking change: |
| 92 | +// |
| 93 | +// @mixin my-custom-component-theme($theme) { |
| 94 | +// .my-comp { |
| 95 | +// background-color: mat-color(map_get($theme, primary)); |
| 96 | +// } |
| 97 | +// } |
| 98 | +// |
| 99 | +// Note that the `$theme.primary` key does usually not exist since the color configuration |
| 100 | +// is stored in `$theme.color` which contains a property for `primary`. This method copies |
| 101 | +// the map from `$theme.color` to `$theme` for backwards compatibility. |
| 102 | +@function _mat-create-backwards-compatibility-theme($theme) { |
| 103 | + @if not map_get($theme, color) { |
| 104 | + @return $theme; |
| 105 | + } |
| 106 | + $color: map_get($theme, color); |
| 107 | + @return map_merge($theme, $color); |
| 108 | +} |
| 109 | + |
85 | 110 | // Whether the specified object is a color configuration. This function is needed for backwards
|
86 | 111 | // compatibility of individual component theme mixins, because developers could pass in a color
|
87 | 112 | // configuration instead of a theme container object to a theme mixin.
|
|
134 | 159 | // If the legacy pattern is used, we generate a container object only with a light-themed
|
135 | 160 | // configuration for the `color` theming part.
|
136 | 161 | @if $accent != null {
|
137 |
| - @return _mat-validate-theme(( |
| 162 | + @return _mat-create-backwards-compatibility-theme(_mat-validate-theme(( |
138 | 163 | color: _mat-create-light-color-config($config-or-primary, $accent, $warn),
|
139 |
| - )); |
| 164 | + ))); |
140 | 165 | }
|
141 | 166 | // If the map pattern is used (1), we just pass-through the configurations for individual
|
142 | 167 | // parts of the theming system, but update the `color` configuration if set. As explained
|
|
149 | 174 | $warn: map_get($color-settings, warn);
|
150 | 175 | $result: map_merge($result, (color: _mat-create-light-color-config($primary, $accent, $warn)));
|
151 | 176 | }
|
152 |
| - @return _mat-validate-theme($result); |
| 177 | + @return _mat-create-backwards-compatibility-theme(_mat-validate-theme($result)); |
153 | 178 | }
|
154 | 179 |
|
155 | 180 | // Creates a container object for a dark theme to be given to individual component theme mixins.
|
|
168 | 193 | // If the legacy pattern is used, we generate a container object only with a dark-themed
|
169 | 194 | // configuration for the `color` theming part.
|
170 | 195 | @if $accent != null {
|
171 |
| - @return _mat-validate-theme(( |
| 196 | + @return _mat-create-backwards-compatibility-theme(_mat-validate-theme(( |
172 | 197 | color: _mat-create-dark-color-config($config-or-primary, $accent, $warn),
|
173 |
| - )); |
| 198 | + ))); |
174 | 199 | }
|
175 | 200 | // If the map pattern is used (1), we just pass-through the configurations for individual
|
176 | 201 | // parts of the theming system, but update the `color` configuration if set. As explained
|
|
183 | 208 | $warn: map_get($color-settings, warn);
|
184 | 209 | $result: map_merge($result, (color: _mat-create-dark-color-config($primary, $accent, $warn)));
|
185 | 210 | }
|
186 |
| - @return _mat-validate-theme($result); |
| 211 | + @return _mat-create-backwards-compatibility-theme(_mat-validate-theme($result)); |
187 | 212 | }
|
188 | 213 |
|
189 | 214 | @function mat-get-color-config($theme, $default: null) {
|
|
0 commit comments