Question about SCSS map
How to make loop with
@each or some think else or join to foo-bar=>bar-foo:123 with map-get.--colors-blue-100: #ff0000--colors-blue-200: #ff0505@function map-deep-get($map, $keys...) {
$scope: $map; $i: 1;
@while (type-of($scope) == map) and ($i <= length($keys)) {
$scope: map-get($scope, nth($keys, $i));
$i: $i + 1;
}
@return $scope;
}
$test:(
foo:(
bar: foo1,
foo-bar: (
bar-foo: 123,
),
),
);
:root {
--s : #{map-deep-get($test, "foo", "bar")}; /* foo1 */
--t : #{map-deep-get($test, "foo", "foo-bar", "bar-foo")}; /* 123 */
}$colors:(
blue:(
100: #ff0000,
200: #ff0505
),
);$colors:(
blue:(
100: #ff0000,
200: #ff0505
),
red:(
100: #123456,
200: #987654
)
);
:root{
@each $color, $set in $colors{
@each $number, $hex in $set{
--colors-#{$color}-#{$number}: #{$hex}
}
}
}:root {
--colors-blue-100: #ff0000 ;
--colors-blue-200: #ff0505 ;
--colors-red-100: #123456 ;
--colors-red-200: #987654 ;
}