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