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

Commit 4e3f7a7

Browse files
committed
fix(theming): dark contrast used incorrectly when only contrastStrongLightColors defined
- if `contrastStrongLightColors` is defined and `contrastLightColors` is not, `getContrastType()` was incorrectly picking `dark` instead of `strongLight` - remove all of the duplicate `contrastLightColors` entries that had to remain before, due to this bug - improve JSDoc - checkbox's checkmark should always match the background color and never depend on the contrast of the accent color - remove duplicate theme style generation for checkbox and button
1 parent 3a291ac commit 4e3f7a7

File tree

5 files changed

+23
-40
lines changed

5 files changed

+23
-40
lines changed

src/components/button/button-theme.scss

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@
5252
}
5353
}
5454
}
55-
&.md-fab {
56-
background-color: '{{accent-color}}';
57-
color: '{{accent-contrast}}';
58-
&:not([disabled]) {
59-
.md-icon {
60-
color: '{{accent-contrast}}';
61-
}
62-
&:hover {
63-
background-color: '{{accent-A700}}';
64-
}
65-
&.md-focused {
66-
background-color: '{{accent-A700}}';
67-
}
68-
}
69-
}
7055

7156
&.md-raised {
7257
color: '{{background-900}}';

src/components/button/demoBasicUsage/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ section .md-button {
1313
bottom: 5px;
1414
left: 7px;
1515
font-size: 14px;
16-
color: rgba(0, 0, 0, 0.54);
1716
}

src/components/checkbox/checkbox-theme.scss

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ md-checkbox.md-THEME_NAME-theme {
2828
}
2929

3030
&.md-checked .md-icon:after {
31-
border-color: '{{accent-contrast-0.87}}';
31+
border-color: '{{background-default}}';
3232
}
3333

3434
&:not([disabled]) {
@@ -60,10 +60,6 @@ md-checkbox.md-THEME_NAME-theme {
6060
&.md-checked.md-focused:not([disabled]) .md-container:before {
6161
background-color: '{{warn-color-0.26}}';
6262
}
63-
64-
&.md-checked .md-icon:after {
65-
border-color: '{{background-200}}';
66-
}
6763
}
6864
}
6965

@@ -76,17 +72,8 @@ md-checkbox.md-THEME_NAME-theme {
7672
background-color: '{{foreground-3}}';
7773
}
7874

79-
&.md-checked .md-icon:after {
80-
border-color: '{{background-200}}';
81-
}
82-
83-
.md-icon:after {
84-
border-color: '{{foreground-3}}';
85-
}
86-
8775
.md-label {
8876
color: '{{foreground-3}}';
8977
}
9078
}
91-
9279
}

src/core/services/theming/theme.palette.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ angular.module('material.core.theming.palette', [])
136136
'contrastDefaultColor': 'dark',
137137
// Dark on 700 does not meet the minimum 4.5 contrast ratio (at 4.07),
138138
// but it's worse with a white foreground (3.85).
139-
'contrastLightColors': '800 900 A700',
140139
'contrastStrongLightColors': '800 900 A700'
141140
},
142141
'cyan': {
@@ -157,7 +156,6 @@ angular.module('material.core.theming.palette', [])
157156
'contrastDefaultColor': 'dark',
158157
// Dark on 700 does not meet the minimum 4.5 contrast ratio (at 4.47),
159158
// but it's worse with a white foreground (3.5).
160-
'contrastLightColors': '800 900',
161159
'contrastStrongLightColors': '800 900'
162160
},
163161
'teal': {
@@ -180,7 +178,6 @@ angular.module('material.core.theming.palette', [])
180178
// but it's worse with a white foreground (3.67).
181179
// White on 600 does not meet the minimum 4.5 contrast ratio (at 4.31),
182180
// but it's worse with a dark foreground (3.64).
183-
'contrastLightColors': '600 700 800 900',
184181
'contrastStrongLightColors': '600 700 800 900'
185182
},
186183
'green': {
@@ -201,7 +198,6 @@ angular.module('material.core.theming.palette', [])
201198
'contrastDefaultColor': 'dark',
202199
// White on 700 does not meet the minimum 4.5 contrast ratio (at 4.11),
203200
// but it's worse with a dark foreground (3.81).
204-
'contrastLightColors': '700 800 900',
205201
'contrastStrongLightColors': '700 800 900'
206202
},
207203
'light-green': {
@@ -220,7 +216,6 @@ angular.module('material.core.theming.palette', [])
220216
'A400': '#76ff03',
221217
'A700': '#64dd17',
222218
'contrastDefaultColor': 'dark',
223-
'contrastLightColors': '800 900',
224219
'contrastStrongLightColors': '800 900'
225220
},
226221
'lime': {
@@ -239,7 +234,6 @@ angular.module('material.core.theming.palette', [])
239234
'A400': '#c6ff00',
240235
'A700': '#aeea00',
241236
'contrastDefaultColor': 'dark',
242-
'contrastLightColors': '900',
243237
'contrastStrongLightColors': '900'
244238
},
245239
'yellow': {
@@ -292,7 +286,6 @@ angular.module('material.core.theming.palette', [])
292286
'A400': '#ff9100',
293287
'A700': '#ff6d00',
294288
'contrastDefaultColor': 'dark',
295-
'contrastLightColors': '900',
296289
'contrastStrongLightColors': '900'
297290
},
298291
'deep-orange': {
@@ -315,7 +308,7 @@ angular.module('material.core.theming.palette', [])
315308
// but it's worse with a white foreground (3.91).
316309
// White on 800 does not meet the minimum 4.5 contrast ratio (at 4.43),
317310
// but it's worse with a dark foreground (3.54).
318-
'contrastLightColors': '800 900 A400 A700',
311+
'contrastStrongLightColors': '800 900 A400 A700',
319312
},
320313
'brown': {
321314
'50': '#efebe9',
@@ -352,7 +345,7 @@ angular.module('material.core.theming.palette', [])
352345
'A400': '#303030',
353346
'A700': '#616161',
354347
'contrastDefaultColor': 'dark',
355-
'contrastLightColors': '600 700 800 900 A200 A400 A700',
348+
'contrastLightColors': '700 800 900 A200 A400 A700',
356349
'contrastStrongLightColors': '600'
357350
},
358351
'blue-grey': {

src/core/services/theming/theming.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,25 @@ function generateAllThemes($injector, $mdTheming) {
12171217
delete palette.contrastStrongLightColors;
12181218
delete palette.contrastDarkColors;
12191219

1220+
/**
1221+
* @param {string} hueName
1222+
* @return {'dark'|'light'|'strongLight'}
1223+
*/
12201224
function getContrastType(hueName) {
1221-
if (defaultContrast === 'light' ? darkColors.indexOf(hueName) !== -1 : lightColors.indexOf(hueName) === -1) {
1225+
if (defaultContrast === 'light' ? darkColors.indexOf(hueName) !== -1 :
1226+
(lightColors.indexOf(hueName) === -1 && strongLightColors.indexOf(hueName) === -1)) {
12221227
return 'dark';
12231228
}
12241229
if (strongLightColors.indexOf(hueName) !== -1) {
12251230
return 'strongLight';
12261231
}
12271232
return 'light';
12281233
}
1234+
1235+
/**
1236+
* @param {'dark'|'light'|'strongLight'} contrastType
1237+
* @return {[number, number, number]} [red, green, blue] array
1238+
*/
12291239
function getContrastColor(contrastType) {
12301240
switch (contrastType) {
12311241
default:
@@ -1237,6 +1247,11 @@ function generateAllThemes($injector, $mdTheming) {
12371247
return DARK_CONTRAST_COLOR;
12381248
}
12391249
}
1250+
1251+
/**
1252+
* @param {'dark'|'light'|'strongLight'} contrastType
1253+
* @return {{secondary: number, divider: number, hint: number, icon: number, disabled: number}}
1254+
*/
12401255
function getOpacityValues(contrastType) {
12411256
switch (contrastType) {
12421257
default:
@@ -1313,6 +1328,10 @@ function checkValidPalette(theme, colorType) {
13131328
}
13141329
}
13151330

1331+
/**
1332+
* @param {string} clr rbg or rgba color
1333+
* @return {number[]|undefined} [red, green, blue] array if it can be computed
1334+
*/
13161335
function colorToRgbaArray(clr) {
13171336
if (angular.isArray(clr) && clr.length === 3) return clr;
13181337
if (/^rgb/.test(clr)) {

0 commit comments

Comments
 (0)