I'm working on building out a set of common SASS mixins. Some of these mixins have 5-10 variables, all with default values. I'd like a way to check whether a user has input values - not the variable contents, but whether there has been an actual user input. For example, in the following mixin:
@mixin backdrop($color: #000) {
background-color: $color;
}
If a user, in their own code, calls:
@include backdrop(#000);
There should be no warning. Even though they have input the same value as the default, there is still a user input, so @warn
is not required. However, if the user calls:
@include backdrop;
There should be a warning, to ensure the user knows about the possible variables.
This is a lot more useful for mixins with more variables. For example, let's say I have a standard button for my site:
@mixin button($background: #222, $textcolor: #fff, $corner-round: 5px) {
background-color: $background;
color: $textcolor;
border-radius: $corner-round;
}
A user could input @include button;
and they'd get a dark grey button with white text and 5px rounded corners. Often, if someone is using a mixin like this, which they didn't write themselves, they might assume - seeing @include button;
used elsewhere in the code - that there were no variables. And I know best practice is to check an unfamiliar mixin for variables - but not everyone does this. So they might go in and type:
@include button;
background-color: #444;
to get a lighter grey button. I'd like to be able to warn a user who calls the mixin and provides no variables that, "Hey, there's some variables provided that you might want to use!" - that way, if they want to override the defaults, they can do it with as few lines of code as possible.
Does anyone know if this kind of user-input check is possible with SASS?