|
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 | +@function _define-theme($primary, $accent, $warn, $is-dark) { |
225 | 165 | // This function creates a container object for the individual component theme mixins. Consumers |
226 | 166 | // can construct such an object by calling this function, or by building the object manually. |
227 | 167 | // There are two possible ways to invoke this function in order to create such an object: |
|
233 | 173 | // (2) Legacy pattern: Passing in the palettes as parameters. This is not as flexible |
234 | 174 | // as passing in a configuration map because only the `color` system can be configured. |
235 | 175 | // |
236 | | - // If the legacy pattern is used, we generate a container object only with a dark-themed |
| 176 | + // If the legacy pattern is used, we generate a container object only with a light-themed |
237 | 177 | // configuration for the `color` theming part. |
238 | 178 | @if $accent != null { |
239 | 179 | @warn theming.$private-legacy-theme-warning; |
240 | 180 | $theme: _mat-validate-theme( |
241 | | - ( |
242 | | - _is-legacy-theme: true, |
243 | | - color: _mat-create-dark-color-config($primary, $accent, $warn), |
244 | | - ) |
| 181 | + ( |
| 182 | + _is-legacy-theme: true, |
| 183 | + color: _mat-create-color-config($primary, $accent, $warn, $is-dark), |
| 184 | + ) |
245 | 185 | ); |
| 186 | + |
246 | 187 | @return _internalize-theme(theming.private-create-backwards-compatibility-theme($theme)); |
247 | 188 | } |
248 | 189 | // If the map pattern is used (1), we just pass-through the configurations for individual |
249 | 190 | // 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. |
| 191 | + // above, the color shorthand will be expanded to an actual light-themed color configuration. |
251 | 192 | $result: $primary; |
252 | 193 | @if map.get($primary, color) { |
253 | 194 | $color-settings: map.get($primary, color); |
254 | 195 | $primary: map.get($color-settings, primary); |
255 | 196 | $accent: map.get($color-settings, accent); |
256 | | - $warn: map.get($color-settings, warn); |
| 197 | + $warn: map.get($color-settings, warn) or define-palette(palette.$red-palette); |
257 | 198 | $result: map.merge( |
258 | | - $result, |
259 | | - ( |
260 | | - color: _mat-create-dark-color-config($primary, $accent, $warn), |
261 | | - ) |
| 199 | + $result, |
| 200 | + ( |
| 201 | + color: _mat-create-color-config($primary, $accent, $warn, $is-dark), |
| 202 | + ) |
262 | 203 | ); |
263 | 204 | } |
264 | 205 | @return _internalize-theme( |
265 | | - theming.private-create-backwards-compatibility-theme(_mat-validate-theme($result)) |
| 206 | + theming.private-create-backwards-compatibility-theme(_mat-validate-theme($result)) |
266 | 207 | ); |
267 | 208 | } |
268 | 209 |
|
|
0 commit comments