Skip to content

Commit

Permalink
fix: update try-darken and try-lighten to work based on theme luminocity
Browse files Browse the repository at this point in the history
  • Loading branch information
joneff committed Jul 24, 2021
1 parent 735e671 commit a87d80e
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions packages/default/scss/core/functions/_colors.scss
Expand Up @@ -354,48 +354,42 @@ $yiq-light: if(
@return color-level( $color, 1 * $level );
}

@function try-shade($color, $level: 1) {
$dark-theme: if(variable-exists(is-dark-theme), $is-dark-theme, false);
@function try-shade( $color, $level: 1 ) {
$dark-theme: if(variable-exists(dark-theme), $dark-theme, false);

@if $dark-theme {
@return tint($color, $level);
@return tint( $color, $level );
}

@return shade($color, $level);
@return shade( $color, $level );
}
@function try-tint($color, $level: 1) {
$dark-theme: if(variable-exists(is-dark-theme), $is-dark-theme, false);
$dark-theme: if(variable-exists(dark-theme), $dark-theme, false);

@if $dark-theme {
@return shade($color, $level);
@return shade( $color, $level );
}

@return tint($color, $level);
@return tint( $color, $level );
}


@function try-darken( $color, $amount, $threshold: black ) {
$amount: if(unitless($amount), $amount, ($amount / 1%));
@function try-darken( $color, $amount ) {
$dark-theme: if(variable-exists(dark-theme), $dark-theme, false);

$result: darken( $color, $amount );
$alt-result: darken( $color, ($amount - 1) );

@if ($result == $threshold) and ($alt-result == $threshold) {
@if $dark-theme {
@return lighten( $color, $amount );
}
@return $result;
@return darken( $color, $amount );
}

@function try-lighten( $color, $amount, $threshold: white ) {
$amount: if(unitless($amount), $amount, ($amount / 1%));
@function try-lighten( $color, $amount ) {
$dark-theme: if(variable-exists(dark-theme), $dark-theme, false);

$result: lighten( $color, $amount );
$alt-result: lighten( $color, ($amount - 1) );

@if ($result == $threshold) and ($alt-result == $threshold) {
@if $dark-theme {
@return darken( $color, $amount );
}
@return $result;
@return lighten( $color, $amount );
}


Expand Down

0 comments on commit a87d80e

Please sign in to comment.