Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 90773f0

Browse files
committed
docs(theme): clarify how to map the old foreground expressions
update links to opacity requirements for icons fix lint errors
1 parent 9956fe9 commit 90773f0

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/core/services/theming/theming.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,26 @@ function detectDisabledThemes($mdThemingProvider) {
134134
* {{primary-contrast}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured contrast (ie. text) color shades set for each hue
135135
* {{primary-contrast-0.7}} - Apply 0.7 opacity to each of the above rules
136136
* {{primary-contrast-divider}} - Apply divider opacity to contrast color
137-
* {{background-default-contrast}} - Apply primary text color for contrasting with default background
138-
* {{background-50-contrast-icon}} - Apply contrast color for icon on background's shade 50 hue
139137
*
138+
* Foreground expansion: Applies rgba to black/white foreground text
139+
*
140+
* Old Foreground Expressions:
141+
* {{foreground-1}} - used for primary text
142+
* {{foreground-2}} - used for secondary text/divider
143+
* {{foreground-3}} - used for disabled text
144+
* {{foreground-4}} - used for dividers
145+
*
146+
* New Foreground Expressions:
147+
*
148+
* Apply primary text color for contrasting with default background
149+
* {{background-default-contrast}} - default opacity
150+
* {{background-default-contrast-secondary}} - opacity for secondary text
151+
* {{background-default-contrast-hint}} - opacity for hints and placeholders
152+
* {{background-default-contrast-disabled}} - opacity for disabled text
153+
* {{background-default-contrast-divider}} - opacity for dividers
154+
*
155+
* Apply contrast color for specific shades
156+
* {{background-50-contrast-icon}} - Apply contrast color for icon on background's shade 50 hue
140157
*/
141158

142159
// In memory generated CSS rules; registered by theme.name
@@ -190,10 +207,8 @@ var DARK_DEFAULT_HUES = {
190207
}
191208
};
192209

193-
// TODO these references no longer exist with the MD spec update of 2018.
194-
// use inactive icon opacity from https://material.google.com/style/color.html#color-text-background-colors
195-
// not inactive icon opacity from https://material.google.com/style/icons.html#icons-system-icons
196-
210+
// Icon opacity values (active/inactive) from
211+
// https://material.io/archive/guidelines/style/icons.html#icons-system-icons
197212
var DARK_CONTRAST_OPACITY = {
198213
'icon': 0.54,
199214
'secondary': 0.54,
@@ -210,6 +225,8 @@ var LIGHT_CONTRAST_OPACITY = {
210225
'divider': 0.12
211226
};
212227

228+
// Icon opacity values (active/inactive) from
229+
// https://material.io/archive/guidelines/style/icons.html#icons-system-icons
213230
var STRONG_LIGHT_CONTRAST_OPACITY = {
214231
'icon': 1.0,
215232
'secondary': 0.7,
@@ -1009,16 +1026,16 @@ function parseRules(theme, colorType, rules) {
10091026
return theme.foregroundShadow;
10101027
} else if (theme.foregroundPalette[hue]) {
10111028
// Use user defined palette number (ie: foreground-2)
1012-
return rgba( colorToRgbaArray( theme.foregroundPalette[hue] ) );
1029+
return rgba(colorToRgbaArray(theme.foregroundPalette[hue]));
10131030
} else if (theme.foregroundPalette['1']){
1014-
return rgba( colorToRgbaArray( theme.foregroundPalette['1'] ) );
1031+
return rgba(colorToRgbaArray(theme.foregroundPalette['1']));
10151032
}
10161033
// Default to background-default-contrast-{opacity}
10171034
colorType = 'background';
10181035
contrast = 'contrast';
10191036
if (!opacity && hue) {
10201037
// Convert references to legacy hues to opacities (i.e. foreground-4 to *-divider)
1021-
switch(hue) {
1038+
switch (hue) {
10221039
// hue-1 uses default opacity
10231040
case '2':
10241041
opacity = 'secondary';
@@ -1206,7 +1223,7 @@ function generateAllThemes($injector, $mdTheming) {
12061223
return 'light';
12071224
}
12081225
function getContrastColor(contrastType) {
1209-
switch(contrastType) {
1226+
switch (contrastType) {
12101227
default:
12111228
case 'strongLight':
12121229
return STRONG_LIGHT_CONTRAST_COLOR;
@@ -1217,7 +1234,7 @@ function generateAllThemes($injector, $mdTheming) {
12171234
}
12181235
}
12191236
function getOpacityValues(contrastType) {
1220-
switch(contrastType) {
1237+
switch (contrastType) {
12211238
default:
12221239
case 'strongLight':
12231240
return STRONG_LIGHT_CONTRAST_OPACITY;

0 commit comments

Comments
 (0)