|
113 | 113 | @return $theme; |
114 | 114 | } |
115 | 115 |
|
116 | | -// Creates a light-themed color configuration from the specified |
117 | | -// primary, accent and warn palettes. |
118 | | -@function _mat-create-light-color-config($primary, $accent, $warn: null) { |
119 | | - $warn: if($warn != null, $warn, define-palette(palette.$red-palette)); |
120 | | - @return ( |
121 | | - primary: $primary, |
122 | | - accent: $accent, |
123 | | - warn: $warn, |
124 | | - is-dark: false, |
125 | | - foreground: palette.$light-theme-foreground-palette, |
126 | | - background: palette.$light-theme-background-palette, |
127 | | - system: ( |
| 116 | +@function _define-system($primary, $accent, $warn, $is-dark) { |
| 117 | + $system: ( |
| 118 | + primary: map.get($primary, default), |
| 119 | + on-primary: map.get($primary, default-contrast), |
| 120 | + secondary: map.get($accent, default), |
| 121 | + on-secondary: map.get($accent, default-contrast), |
| 122 | + error: map.get($warn, default), |
| 123 | + on-error: map.get($warn, default-contrast), |
| 124 | + shadow: black, |
| 125 | + hover-state-layer-opacity: 0.04, |
| 126 | + focus-state-layer-opacity: 0.12, |
| 127 | + pressed-state-layer-opacity: 0.12, |
| 128 | + ); |
| 129 | + |
| 130 | + @if $is-dark { |
| 131 | + @return map.merge($system, ( |
| 132 | + surface: map.get(palette.$grey-palette, 800), |
| 133 | + surface-variant: #4a4a4a, |
| 134 | + on-surface: white, |
| 135 | + on-surface-variant: rgba(white, 0.7), |
| 136 | + background: #303030, |
| 137 | + inverse-surface: white, |
| 138 | + inverse-on-surface: rgba(black, 0.87), |
| 139 | + outline: rgba(white, 0.12), |
| 140 | + outline-variant: rgba(white, 0.38), |
| 141 | + )); |
| 142 | + } @else { |
| 143 | + @return map.merge($system, ( |
128 | 144 | surface: white, |
129 | 145 | surface-variant: #f6f6f6, |
130 | 146 | on-surface: rgba(black, 0.87), |
|
134 | 150 | inverse-on-surface: white, |
135 | 151 | outline: rgba(black, 0.12), |
136 | 152 | outline-variant: rgba(black, 0.38), |
137 | | - hover-state-layer-opacity: 0.04, |
138 | | - focus-state-layer-opacity: 0.12, |
139 | | - pressed-state-layer-opacity: 0.12, |
140 | | - shadow: black, |
141 | | - primary: map.get($primary, default), |
142 | | - on-primary: map.get($primary, default-contrast), |
143 | | - secondary: map.get($accent, default), |
144 | | - on-secondary: map.get($accent, default-contrast), |
145 | | - error: map.get($warn, default), |
146 | | - on-error: map.get($warn, default-contrast), |
147 | | - ), |
148 | | - ); |
| 153 | + )); |
| 154 | + } |
149 | 155 | } |
150 | 156 |
|
151 | | -// Creates a dark-themed color configuration from the specified |
| 157 | +// Creates a color configuration from the specified |
152 | 158 | // primary, accent and warn palettes. |
153 | | -@function _mat-create-dark-color-config($primary, $accent, $warn: null) { |
| 159 | +@function _mat-create-color-config($primary, $accent, $warn: null, $is-dark) { |
154 | 160 | $warn: if($warn != null, $warn, define-palette(palette.$red-palette)); |
| 161 | + $foreground: |
| 162 | + if($is-dark, palette.$dark-theme-foreground-palette, palette.$light-theme-foreground-palette); |
| 163 | + $background: |
| 164 | + if($is-dark, palette.$dark-theme-background-palette, palette.$light-theme-background-palette); |
| 165 | + |
155 | 166 | @return ( |
156 | 167 | primary: $primary, |
157 | 168 | accent: $accent, |
158 | 169 | warn: $warn, |
159 | | - is-dark: true, |
160 | | - foreground: palette.$dark-theme-foreground-palette, |
161 | | - background: palette.$dark-theme-background-palette, |
162 | | - system: ( |
163 | | - surface: map.get(palette.$grey-palette, 800), |
164 | | - surface-variant: #4a4a4a, |
165 | | - on-surface: white, |
166 | | - on-surface-variant: rgba(white, 0.7), |
167 | | - background: #303030, |
168 | | - inverse-surface: white, |
169 | | - inverse-on-surface: rgba(black, 0.87), |
170 | | - outline: rgba(white, 0.12), |
171 | | - outline-variant: rgba(white, 0.38), |
172 | | - hover-state-layer-opacity: 0.04, |
173 | | - focus-state-layer-opacity: 0.12, |
174 | | - pressed-state-layer-opacity: 0.12, |
175 | | - shadow: black, |
176 | | - primary: map.get($primary, default), |
177 | | - on-primary: map.get($primary, default-contrast), |
178 | | - secondary: map.get($accent, default), |
179 | | - on-secondary: map.get($accent, default-contrast), |
180 | | - error: map.get($warn, default), |
181 | | - on-error: map.get($warn, default-contrast), |
182 | | - ), |
| 170 | + is-dark: $is-dark, |
| 171 | + foreground: $foreground, |
| 172 | + background: $background, |
183 | 173 | ); |
184 | 174 | } |
185 | 175 |
|
186 | | -// TODO: Remove legacy API and rename `$primary` below to `$config`. Currently it cannot be renamed |
187 | | -// as it would break existing apps that set the parameter by name. |
188 | | - |
189 | | -/// Creates a container object for a light theme to be given to individual component theme mixins. |
| 176 | +/// Creates a container object for a theme to be given to individual component theme mixins. |
190 | 177 | /// @param {Map} $primary The theme configuration object. |
191 | 178 | /// @returns {Map} A complete Angular Material theme map. |
192 | | -@function define-light-theme($primary, $accent: null, $warn: define-palette(palette.$red-palette)) { |
| 179 | +@function _define-theme( |
| 180 | + $primary, $accent: null, $warn: define-palette(palette.$red-palette), $is-dark) { |
193 | 181 | // This function creates a container object for the individual component theme mixins. Consumers |
194 | 182 | // can construct such an object by calling this function, or by building the object manually. |
195 | 183 | // There are two possible ways to invoke this function in order to create such an object: |
|
206 | 194 | @if $accent != null { |
207 | 195 | @warn theming.$private-legacy-theme-warning; |
208 | 196 | $theme: _mat-validate-theme( |
209 | | - ( |
210 | | - _is-legacy-theme: true, |
211 | | - color: _mat-create-light-color-config($primary, $accent, $warn), |
212 | | - ) |
| 197 | + ( |
| 198 | + _is-legacy-theme: true, |
| 199 | + color: _mat-create-color-config($primary, $accent, $warn, $is-dark), |
| 200 | + ) |
213 | 201 | ); |
214 | 202 |
|
215 | | - @return _internalize-theme(theming.private-create-backwards-compatibility-theme($theme)); |
| 203 | + $theme: _internalize-theme(theming.private-create-backwards-compatibility-theme($theme)); |
| 204 | + $theme: map.set($theme, _mat-system, _define-system($primary, $accent, $warn, $is-dark)); |
| 205 | + @return $theme; |
216 | 206 | } |
217 | 207 | // If the map pattern is used (1), we just pass-through the configurations for individual |
218 | 208 | // parts of the theming system, but update the `color` configuration if set. As explained |
|
224 | 214 | $accent: map.get($color-settings, accent); |
225 | 215 | $warn: map.get($color-settings, warn); |
226 | 216 | $result: map.merge( |
227 | | - $result, |
228 | | - ( |
229 | | - color: _mat-create-light-color-config($primary, $accent, $warn), |
230 | | - ) |
| 217 | + $result, |
| 218 | + ( |
| 219 | + color: _mat-create-color-config($primary, $accent, $warn, $is-dark), |
| 220 | + ) |
231 | 221 | ); |
232 | 222 | } |
233 | | - @return _internalize-theme( |
234 | | - theming.private-create-backwards-compatibility-theme(_mat-validate-theme($result)) |
| 223 | + $theme: _internalize-theme( |
| 224 | + theming.private-create-backwards-compatibility-theme(_mat-validate-theme($result)) |
235 | 225 | ); |
| 226 | + $primary: map.get($result, primary) or map.get($result, color, primary) or (); |
| 227 | + $accent: map.get($result, accent) or map.get($result, color, accent) or (); |
| 228 | + $warn: map.get($result, warn) or map.get($result, color, warn) or (); |
| 229 | + $theme: map.set($theme, _mat-system, _define-system($primary, $accent, $warn, $is-dark)); |
| 230 | + @return $theme; |
| 231 | +} |
| 232 | + |
| 233 | +// TODO: Remove legacy API and rename `$primary` below to `$config`. Currently it cannot be renamed |
| 234 | +// as it would break existing apps that set the parameter by name. |
| 235 | + |
| 236 | +/// Creates a container object for a light theme to be given to individual component theme mixins. |
| 237 | +/// @param {Map} $primary The theme configuration object. |
| 238 | +/// @returns {Map} A complete Angular Material theme map. |
| 239 | +@function define-light-theme($primary, $accent: null, $warn: define-palette(palette.$red-palette)) { |
| 240 | + @return _define-theme($primary, $accent, $warn, false); |
236 | 241 | } |
237 | 242 |
|
238 | 243 | // TODO: Remove legacy API and rename below `$primary` to `$config`. Currently it cannot be renamed |
|
242 | 247 | /// @param {Map} $primary The theme configuration object. |
243 | 248 | /// @returns {Map} A complete Angular Material theme map. |
244 | 249 | @function define-dark-theme($primary, $accent: null, $warn: define-palette(palette.$red-palette)) { |
245 | | - // This function creates a container object for the individual component theme mixins. Consumers |
246 | | - // can construct such an object by calling this function, or by building the object manually. |
247 | | - // There are two possible ways to invoke this function in order to create such an object: |
248 | | - // |
249 | | - // (1) Passing in a map that holds optional configurations for individual parts of the |
250 | | - // theming system. For `color` configurations, the function only expects the palettes |
251 | | - // for `primary` and `accent` (and optionally `warn`). The function will expand the |
252 | | - // shorthand into an actual configuration that can be consumed in `-color` mixins. |
253 | | - // (2) Legacy pattern: Passing in the palettes as parameters. This is not as flexible |
254 | | - // as passing in a configuration map because only the `color` system can be configured. |
255 | | - // |
256 | | - // If the legacy pattern is used, we generate a container object only with a dark-themed |
257 | | - // configuration for the `color` theming part. |
258 | | - @if $accent != null { |
259 | | - @warn theming.$private-legacy-theme-warning; |
260 | | - $theme: _mat-validate-theme( |
261 | | - ( |
262 | | - _is-legacy-theme: true, |
263 | | - color: _mat-create-dark-color-config($primary, $accent, $warn), |
264 | | - ) |
265 | | - ); |
266 | | - @return _internalize-theme(theming.private-create-backwards-compatibility-theme($theme)); |
267 | | - } |
268 | | - // If the map pattern is used (1), we just pass-through the configurations for individual |
269 | | - // parts of the theming system, but update the `color` configuration if set. As explained |
270 | | - // above, the color shorthand will be expanded to an actual dark-themed color configuration. |
271 | | - $result: $primary; |
272 | | - @if map.get($primary, color) { |
273 | | - $color-settings: map.get($primary, color); |
274 | | - $primary: map.get($color-settings, primary); |
275 | | - $accent: map.get($color-settings, accent); |
276 | | - $warn: map.get($color-settings, warn); |
277 | | - $result: map.merge( |
278 | | - $result, |
279 | | - ( |
280 | | - color: _mat-create-dark-color-config($primary, $accent, $warn), |
281 | | - ) |
282 | | - ); |
283 | | - } |
284 | | - @return _internalize-theme( |
285 | | - theming.private-create-backwards-compatibility-theme(_mat-validate-theme($result)) |
286 | | - ); |
| 250 | + @return _define-theme($primary, $accent, $warn, true); |
287 | 251 | } |
288 | 252 |
|
289 | 253 | /// Gets the color configuration from the given theme or configuration. |
|
0 commit comments