I have several colors in HSL format, this one of them: 284, 3, 30
.
I need to create a Sass mixin for the developers where all they need to do is add or subtract 50% of the Lightness value (30
) in order to achieve the desired color as per our brand guidelines.
What I currently have works to a certain extent:
@mixin smoke($l:30) {
color: hsl(284, 3, $l);
}
So if the developer wants to add 50% to the Lightness (+15), they could do this:
@include smoke(45);
And for the lighter color (-15), they would do this:
@include smoke(15);
The problem with this approach is that the developers HAVE to remember the Lightness values of all the colors (or go back to the guidelines over and over) in order to determine what is the 50% of a particular color that they need to use and then manually add that value to the argument. Makes sense?
What I'm looking for is a way to create a mixin that allows the developers to just reference the color name in the @include
directive and then just type (+50%) or (-50%) in the argument, then when the CSS is compiled it would look like this:
- Darker color:
284, 3, 15
(Lightness has been reduced by 50% of 30). - Lighter color:
284, 3, 45
(Lightness has been increased by 50% of 30).
If I do @include smoke(+50%);
or @include smoke(-50%);
I get totally different colors.
Here's my initial Sass I've been working with:
//Color
@mixin smoke($l:30) {
color: hsl(284, 3, $l);
}
body {
/*DOES WORK BUT NOT IDEAL METHOD*/
/*Light = #746f77*/
@include smoke(45);
/*Dark = #272527*/
@include smoke(15);
/*===========*/
/*DOESN'T WORK BUT IDEAL METHOD*/
/*Light = #746f77*/
@include smoke(-50%);
/*Dark = #272527*/
@include smoke(+50%);
}
https://codepen.io/ricardozea/pen/VgRVbG?editors=0100
Thank you.