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

Commit c4f9f50

Browse files
rschmuklerjelbourn
authored andcommitted
feat(theming): add hue-specific contrast support
1 parent 26dbbf8 commit c4f9f50

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/components/calendar/calendar-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
.md-calendar-date:focus.md-calendar-selected-date {
3333
.md-calendar-date-selection-indicator {
3434
background-color: '{{primary-500}}'; // blue-500
35-
color: '{{primary-contrast}}'; // SHOULD BE WHITE (ish)
35+
color: '{{primary-500-contrast}}'; // SHOULD BE WHITE (ish)
3636
}
3737
}

src/core/services/theming/theming.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ angular.module('material.core.theming', ['material.core.theming.palette'])
3232
*
3333
* {{primary-100}} - grab shade 100 from the primary palette
3434
* {{primary-100-0.7}} - grab shade 100, apply opacity of 0.7
35+
* {{primary-100-contrast}} - grab shade 100's contrast color
3536
* {{primary-hue-1}} - grab the shade assigned to hue-1 from the primary palette
3637
* {{primary-hue-1-0.7}} - apply 0.7 opacity to primary-hue-1
3738
* {{primary-color}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured shades set for each hue
@@ -404,13 +405,13 @@ function parseRules(theme, colorType, rules) {
404405
var themeNameRegex = new RegExp('.md-' + theme.name + '-theme', 'g');
405406
// Matches '{{ primary-color }}', etc
406407
var hueRegex = new RegExp('(\'|")?{{\\s*(' + colorType + ')-(color|contrast)-?(\\d\\.?\\d*)?\\s*}}(\"|\')?','g');
407-
var simpleVariableRegex = /'?"?\{\{\s*([a-zA-Z]+)-(A?\d+|hue\-[0-3]|shadow)-?(\d\.?\d*)?\s*\}\}'?"?/g;
408+
var simpleVariableRegex = /'?"?\{\{\s*([a-zA-Z]+)-(A?\d+|hue\-[0-3]|shadow)-?(\d\.?\d*)?(contrast)?\s*\}\}'?"?/g;
408409
var palette = PALETTES[color.name];
409410

410411
// find and replace simple variables where we use a specific hue, not an entire palette
411412
// eg. "{{primary-100}}"
412413
//\(' + THEME_COLOR_TYPES.join('\|') + '\)'
413-
rules = rules.replace(simpleVariableRegex, function(match, colorType, hue, opacity) {
414+
rules = rules.replace(simpleVariableRegex, function(match, colorType, hue, opacity, contrast) {
414415
if (colorType === 'foreground') {
415416
if (hue == 'shadow') {
416417
return theme.foregroundShadow;
@@ -421,7 +422,7 @@ function parseRules(theme, colorType, rules) {
421422
if (hue.indexOf('hue') === 0) {
422423
hue = theme.colors[colorType].hues[hue];
423424
}
424-
return rgba( (PALETTES[ theme.colors[colorType].name ][hue] || '').value, opacity );
425+
return rgba( (PALETTES[ theme.colors[colorType].name ][hue] || '')[contrast ? 'contrast' : 'value'], opacity );
425426
});
426427

427428
// For each type, generate rules for each hue (ie. default, md-hue-1, md-hue-2, md-hue-3)

0 commit comments

Comments
 (0)