Last active
December 20, 2016 16:10
-
-
Save silvandiepen/f9da3fb4706657feb09551d9a0e4bf33 to your computer and use it in GitHub Desktop.
Example for using color lists in sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using colors in the scss | |
body{ background: color(White); | |
// Give the p elements a black text color | |
p{ color: color(Black); } | |
// Set a half transparent green background | |
ul{ background-color: color(Green,.5); | |
li{ | |
//automatically create all classes from social with their colors | |
@each $color in $social-colors{ | |
&.#{nth($color,1){ color: nth($color,2); }} | |
// Orrr use the color function. By giving the third argument another than the default color-set | |
&.#{nth($color,1){ color: color(nth($color,1),1,$social-colors); }} | |
} | |
} | |
} | |
// This one will give a warning in the console. | |
div{ color: color(Purplish); } | |
// This one wont: | |
div{ color: color(Purplish,1,$colors,false); } | |
// This one will just give a boolean (true or false) back if the color exists | |
div{ color: color(Purplish,1,$colors,false,true); } | |
// this can be used when making another list of elements, and check if this value also has a color. You can create the class, or just not.. | |
// example: | |
$animals: "dog","cat","horse","Frog"; | |
$animal-colors: {"dog": brown, "cat": orange, "frog": green } | |
@each $animal in $animals{ | |
@if color($animal,1,$animal-colors,false,true); | |
.#{$animal} { background-color: color($animal,1,$animal-colors) } | |
} | |
} | |
// will generate: | |
.dog{ background-color: brown; } | |
.cat{ background-color: orange; } | |
.frog{ background-color: green; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@function color($value, $rgba: false, $colorset: $colors, $warning: true, $boolean: false){ | |
$color: map-get($colorset, $value); | |
@if $warning == true{ | |
@if $color == null{ | |
@warn 'color: "#{$value}" doesn\'t exist'; | |
} | |
} | |
@if $boolean == true{ | |
@if $color == null{ | |
@return false; | |
} @else { @return true; } | |
} @else { | |
@if $rgba != false{ | |
@return rgba($color,$rgba); | |
} @else{ | |
@return $color; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$colors:( | |
"Black": #252324, | |
"White": #ffffff, | |
"Creme": #dadbcf, | |
"Red": #ee5858, | |
"Green": #5ec369, | |
"Blue": #509ad1, | |
"Turquoise": #50cfd1, | |
"Purple": #8d50d1, | |
"Yellow": #d8ba48 | |
); | |
$social-colors: ( | |
"500px": #ff4c4c, | |
"behance": #1769ff, | |
"dribbble": #ea4c89, | |
"facebook": #3b5998, | |
"flickr": #ff0084, | |
"foursquare": #0072b1, | |
"github": #0f0d0e, | |
"googleplus": #dd4b39, | |
"twitter": #00aced, | |
"linkedin": #007bb6, | |
"instagram": #517fa4, | |
"pinterest": #cb2027, | |
"redbubble": #fe0000, | |
"skype": #12A5F4, | |
"snapchat": #fffc00, | |
"soundcloud": #ff7700, | |
"society6": #000000, | |
"spotify": #2ebd59, | |
"tumblr": #32506d, | |
"vimeo": #aad450, | |
"vine": #00bf8f, | |
"vkontakte": #45668e, | |
"youtube": #bb0000, | |
"wordpress": #21759b | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment