modifiers()
provides a shorthand for quickly defining ABEM modifiers based on sass maps.
.example {
@include modifiers((1rem, small .75rem, large 1.5rem)) using ($size) {
font-size: $size;
}
}
is equivalent to
.example {
font-size: 1rem;
&.-small {
font-size: .75rem;
}
&.-large {
font-size: 1.5rem;
}
}
You can also pass in a default map for modifiers to work off of:
$sizes: (
sm: 1rem,
md: 1.5rem,
lg: 2rem
);
.example {
@include modifiers((sm, md), $sizes) using ($size) {
font-size: $size;
}
}
Each item within the first argument to modifiers is parsed like this:
small .75rem
) then the first part is used as the modifier name and the second is used as the value;sm
) then they key is used as the modifier name and the value from the default map is used; and lastlyLastly, note that the way Sass works, these two lines are equivalent:
@include modifiers((sm, md), $sizes) using ($size) {
@include modifiers(sm md, $sizes) using ($size) {
You only need to include the second set of parenthesis if you’re going to pass in a pair of values.