Im having difficulties in understanding SCSS Variable Argument. as it shown here, it's pretty easy to understand that you can add more than one argument.
But I don't understand how can I do that with Maps.
For example:
I have this map:
$spacing: (
none: 0px,
micro: 2px,
tiny: 4px,
);
And Im writing a function to control the spacing: (Most probably its super wrong)
@function spacing($value...) {
$chosen-spacing: null;
@if length($value) == 1 {
@if map-has-key($spacing, $value) {
@return map-get($spacing, $value);
}@else {
@error "'#{$value}' doesn't exist in 'spacing map'";
@return null;
}
}@else {
@each $v in $value {
@if map-has-key($spacing, $value) {
$chosen-spacing: map-get($spacing, $value);
}@else {
@error "'#{$value}' doesn't exist in 'spacing map'";
@return null;
}
}
@return $chosen-spacing;
}
}
What I want is to be able to call the function as:
.blabla {
padding: spacing(none);
margin: spacing (micro, tiny);
}
And the output to be:
.blabla {
padding: 0px;
margin: 2px 4px;
}
Without the Map, it can be done easily, but with Map how can I do it?
Thank you