My goal is to generate a SASS map
to store variants of colors that are stored in the following map:
$colors : (
jet : #333333,
wintergreen-dream : #588C73,
eton-blue : #8FC0A9,
sunglow : #FFC33C,
light-kaki : #F2E394,
bege : #FAF3DD
);
So far, I am using a @function
to retrieve these variants:
@function light ($color, $val) { @return lighten($color, $val); }
@function dark ($color, $val) { @return darken($color, $val); }
@function transparent ($color, $val) { @return transparent($color, $val); }
The map I am expecting to be able to generate would look alike the following:
$colors-map : (
eton-blue : (
base : $eton-blue,
light : lighten($eton-blue, 15%),
dark : darken($eton-blue, 15%),
trans : transparent($eton-blue, .5)
),
jet : (
base : $jet,
light : lighten($jet, 15%),
dark : darken($jet, 15%),
trans : transparent($jet, .5)
)
// ...
);
Yet, the loop I've already tried to apply, looks like this:
@for $key, $value in $colors {}
However, I was naive to believe it could work inside of the map itself.
Questions which answers could easier answer this doubt :
- How to add values to a SASS map (function), (key:value) ?
- Basic usage of
map-merge
/map-set
? (@return map-merge($map, $new)
)
Strictly what I am looking for below :
$alternative-colors : (
@each $color, $hex in $colors {
#{$color} : (
light : lighten($color, 25%),
dark : darken($color, 25%)
);
}
);
But yet, it returns following error:
Error: Invalid CSS after \"...tive-colors : (\": expected \")\", was \"@each (...)
Conclusion
Long time have passed, and I it would be nice if I could share my solution with everyone else.
I have created a repo to store the results of this problem solving, https://github.com/vladimirlisovets/SASS-Color-Palettes.
Hope it to be useful to someone either to inspire for something better.
Cheers.