Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #50 from IBM-Design/hotfix/color-tint-shade
Browse files Browse the repository at this point in the history
Hotfix/color tint shade
  • Loading branch information
seejamescode authored Jan 12, 2017
2 parents 4688180 + 03e673e commit 4f71406
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 27 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ Returns the specified color from the specified color palette
//////////////////////////////////////////////////

background: color('blue', 80); // #1d3649
background: color('blue', 8); // #1d3649
background: color('blue', 'core'); // #4178be
background: color('blue'); // #4178be
-- with an alpha
background: color('blue', 80, $alpha: 0.5); // rgba(29, 54, 73, 0.5)
Expand All @@ -106,7 +104,6 @@ Returns a color the specified amount of steps lighter than the given color in th
//////////////////////////////////////////////////

background: color-tint(color('blue', 80), 20); // #325c80
background: color-tint(color('blue', 80), 2); // #325c80
background: color-tint(color('blue', 80), 23); // #325c80
background: color-tint(color('blue', 80), 25); // #4178be
background: color-tint(color('blue', 80), 100); // #c0e6ff
Expand All @@ -129,7 +126,6 @@ Returns a color the specified amount of steps darker than the given color in the
//////////////////////////////////////////////////

background: color-shade(color('blue', 30), 20); // #4178be
background: color-shade(color('blue', 30), 2); // #4178be
background: color-shade(color('blue', 30), 23); // #4178be
background: color-shade(color('blue', 30), 25); // #325c80
background: color-shade(color('blue', 30), 100); // #010205
Expand Down
60 changes: 49 additions & 11 deletions _ibm-colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,34 @@
@return rgba($grd, $alpha);
}

@warn 'Color palette "#{$palette}" not found';
$error-message: 'Color palette "#{$palette}" not found';
@if not $found-index {
@if feature-exists(at-error) {
@error $error-message;
}
@else {
@warn $error-message;
}
}

@return false;
}

//////////////////////////////
// Tint and Shade Functions
//////////////////////////////
$singles: 'neutral-white', 'cool-white', 'warm-white';
// Internal helper: finds the palette and key of a color
@function _ibm-find-color($color) {
$found-index: false;
$found-palette: false;
@each $palette, $vals in $__ibm-color-palettes {
@if not $found-index {
@each $key, $clr in $vals {
@if $color == $clr and $key != 'core' {
$found-index: $key;
$found-palette: $palette;
}
@if $color == $clr and $key != 'core' {
$found-index: $key;
$found-palette: $palette;
}
}
}
}
Expand All @@ -84,7 +94,7 @@

// Internal helper: transforms amount into base 10, rounding
@function _ibm-round-tint-shade($amount) {
@if $amount < 10 {
@if $amount < 1 {
$amount: $amount * 10;
}

Expand All @@ -110,9 +120,23 @@
$palette: map-get($key, 'palette');
$move: _ibm-round-tint-shade($amount);

$index: $index - $move;
@if ($index < 10) {
$index: 10;
@if index($singles, $palette) {
$index: $index - ($move / 10);
@if $index < 1 {
$index: 1;
}
}
@else if $palette == 'black' {
$index: 100;
}
@else if $palette == 'white' {
$index: 0;
}
@else {
$index: $index - $move;
@if $index < 10 {
$index: 1;
}
}

@return color($palette, $index);
Expand All @@ -130,10 +154,24 @@
$palette: map-get($key, 'palette');
$move: _ibm-round-tint-shade($amount);

$index: $index + $move;
@if ($index > 100) {
@if index($singles, $palette) {
$index: $index - ($move / 10);
@if $index > 4 {
$index: 4;
}
}
@else if $palette == 'black' {
$index: 100;
}
@else if $palette == 'white' {
$index: 0;
}
@else {
$index: $index + $move;
@if ($index > 90) {
$index: 90;
}
}

@return color($palette, $index);
}
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,7 @@ gulp.task('templates', ['partials'], () =>

gulp.task('build', [ 'package', 'ase', 'clr', 'sketchpalette' ]);

gulp.task('test', ['build']);

/*--- default task ----------------------------------------------------------*/
gulp.task('default', [ 'build' ]);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"through2-spy": "^2.0.0"
},
"version": "2.0.2"
}
}
60 changes: 49 additions & 11 deletions source/templates/partials/color-functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,34 @@
@return rgba($grd, $alpha);
}

@warn 'Color palette "#{$palette}" not found';
$error-message: 'Color palette "#{$palette}" not found';
@if not $found-index {
@if feature-exists(at-error) {
@error $error-message;
}
@else {
@warn $error-message;
}
}

@return false;
}

//////////////////////////////
// Tint and Shade Functions
//////////////////////////////
$singles: 'neutral-white', 'cool-white', 'warm-white';
// Internal helper: finds the palette and key of a color
@function _ibm-find-color($color) {
$found-index: false;
$found-palette: false;
@each $palette, $vals in $__ibm-color-palettes {
@if not $found-index {
@each $key, $clr in $vals {
@if $color == $clr and $key != 'core' {
$found-index: $key;
$found-palette: $palette;
}
@if $color == $clr and $key != 'core' {
$found-index: $key;
$found-palette: $palette;
}
}
}
}
Expand All @@ -77,7 +87,7 @@

// Internal helper: transforms amount into base 10, rounding
@function _ibm-round-tint-shade($amount) {
@if $amount < 10 {
@if $amount < 1 {
$amount: $amount * 10;
}

Expand All @@ -103,9 +113,23 @@
$palette: map-get($key, 'palette');
$move: _ibm-round-tint-shade($amount);

$index: $index - $move;
@if ($index < 10) {
$index: 10;
@if index($singles, $palette) {
$index: $index - ($move / 10);
@if $index < 1 {
$index: 1;
}
}
@else if $palette == 'black' {
$index: 100;
}
@else if $palette == 'white' {
$index: 0;
}
@else {
$index: $index - $move;
@if $index < 10 {
$index: 1;
}
}

@return color($palette, $index);
Expand All @@ -123,10 +147,24 @@
$palette: map-get($key, 'palette');
$move: _ibm-round-tint-shade($amount);

$index: $index + $move;
@if ($index > 100) {
@if index($singles, $palette) {
$index: $index - ($move / 10);
@if $index > 4 {
$index: 4;
}
}
@else if $palette == 'black' {
$index: 100;
}
@else if $palette == 'white' {
$index: 0;
}
@else {
$index: $index + $move;
@if ($index > 90) {
$index: 90;
}
}

@return color($palette, $index);
}
Expand Down

0 comments on commit 4f71406

Please sign in to comment.