I'm trying to get the values and keys out of a nested map in Sass (using libsass, specifically).
I'm successfully looping through the parent map, but I need to get the values and keys for each item in each child map.
This is all on Sassmeister, which is probably the easiest place to see it: http://sassmeister.com/gist/04ba839b0edff4b84a93
My map:
$grids: (
2: (
$med-2: 2,
),
3: (
$med-2: 2,
$max-width: 3
),
4: (
$med-2: 2,
$med-3: 3,
$max-width: 4
),
5: (
$med-2: 2,
$med-3: 3,
$large-1: 4,
$max-width: 5
),
6: (
$med-2: 2,
$med-3: 3,
$large-1: 5,
$max-width: 6
)
);
My mixin:
@mixin media-grid($base-class: "media-grid") {
.#{$base-class} {
border: 1px solid black;
}
@each $cols, $bp in $grids {
.#{$base-class}--#{$cols} li {
@for $i from 1 through length($bp) {
@media ( min-width: map-deep-get($grids, $cols, $i) ) {
// min-width: Should be the key. $i is certainly incorrect.
max-width: 100/$cols + %;
// Instead of $cols, should divide by the value
}
}
}
}
}
For reference: also part of this, but functioning correctly:
@function map-deep-get($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}