Skip to content

Commit

Permalink
fix hue when contrast
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Sep 26, 2018
1 parent e9f21e3 commit d931d19
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/angular-scss-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const EXPRESSION_REGEX = /(?:'|"|'\\'){{\s*([a-zA-Z]+)-(A?\d+|hue-[0-3]|shadow|d

const LIGHT_DEFAULT_HUES = {
'accent': {
'default': 'A200',
'default': '500', // previously A200, but doesn't look good with palette generator
'hue-1': 'A100',
'hue-2': 'A400',
'hue-3': 'A700'
Expand Down Expand Up @@ -60,16 +60,19 @@ module.exports = class AngularScssFilter extends Filter {
}

replaceExpression(match, colorType, hue, opacity, contrast) {
// normalize `color` as `default`
hue = hue === 'color' ? 'default' : hue;
contrast = hue === 'contrast' || contrast;

// specifying `color` or `contrast` means we want the default palette color
hue = hue === 'color' || hue === 'contrast' ? 'default' : hue;

// try to look up the default hue on LIGHT_DEFAULT_HUES or default to `500`
if (LIGHT_DEFAULT_HUES[colorType] && LIGHT_DEFAULT_HUES[colorType][hue]) {
hue = LIGHT_DEFAULT_HUES[colorType][hue];
} else if (hue === 'default') {
hue = '500';
}

let colorFunction = hue === 'contrast' || contrast ? 'paper-contrast-color' : 'paper-color';
let colorFunction = contrast ? 'paper-contrast-color' : 'paper-color';
let params = [`$${colorType}`];

params.push(`"${hue}"`);
Expand All @@ -82,14 +85,15 @@ module.exports = class AngularScssFilter extends Filter {
}

replaceExpressionCssVar(match, colorType, hue, opacity, contrast) {
// normalize `color` into `default`
hue = hue === 'color' ? 'default' : hue;

contrast = hue === 'contrast' || contrast;

// specifying `color` or `contrast` means we want the default palette color
hue = hue === 'color' || hue === 'contrast' ? 'default' : hue;

// try to look up the default hue on LIGHT_DEFAULT_HUES or default to `500`
if (LIGHT_DEFAULT_HUES[colorType] && LIGHT_DEFAULT_HUES[colorType][hue]) {
hue = LIGHT_DEFAULT_HUES[colorType][hue];
} else if (hue === 'default' || hue === 'contrast') {
} else if (hue === 'default') {
hue = '500';
}

Expand Down

0 comments on commit d931d19

Please sign in to comment.