В SCSS нет имен динамических переменных, но вместо этого можно использовать Map :
$success: green;
$warning: yellow;
$danger: red;
$information: steelblue;
@mixin theme ($color) {
&:checked {
background: $color;
}
}
$themes: (
success $success,
warning $warning,
danger $danger,
information $information
);
@each $theme, $color in $themes {
.checkbox-#{$theme} {
@include theme($color);
}
}
Для полноты картины, если вы используете действительно старую версию SCSS, которая их не поддерживает, вы можете использовать вложенные списки и nth
функция.
...
$themes: (
(success $success),
(warning $warning),
(danger $danger),
(information $information)
);
@each $pair in $themes {
$theme: nth($pair, 1);
$color: nth($pair, 2);
.checkbox-#{$theme} {
@include theme($color);
}
}
Оба будут выдавать одинаковый вывод:
.checkbox-success:checked {
background: green;
}
.checkbox-warning:checked {
background: yellow;
}
.checkbox-danger:checked {
background: red;
}
.checkbox-information:checked {
background: steelblue;
}