To accomplish my CSS, I use the SCSS framework inuitcss (https://github.com/inuitcss/inuitcss), which provides utilities for responsive spacings that look like this:
.u-1/3@mobile
.u-margin-bottom@mobile
A class like this follows the "mobile first" approach, which means, if there is change in a tablet or desktop state, it needs to be "overwritten" or "cancelled" by the use of another utility class, which looks like this:
.u-1/2@tablet
.u-margin-bottom-none@tablet
I would like to change this behaviour by tying some of those utility classes to their responsive state only, so that a cancellation is not necessary.
Currently, the mixin responsible for the generation of those utility classes looks like this (it uses Sass-mq):
@each $inuit-bp-name, $inuit-bp-value in $mq-breakpoints {
@include mq($from: $inuit-bp-name) {
@include inuit-widths($inuit-fractions, #{$inuit-widths-breakpoint-separator}#{$inuit-bp-name});
}
}
In order to achieve my goal, I would have to adapt the @include mq( function to use a second parameter, which would look like this:
@include mq($from: $inuit-bp-name, $to: [next $inuit-bp-name]) {
And here are my problems:
How do I get the next value in the map?
How would I possibly prevent an error if there is no next value?
I at least managed to get the index value, like this:
@each $inuit-bp-name, $inuit-bp-value in $mq-breakpoints {
$i: index(($mq-breakpoints), ($inuit-bp-name $inuit-bp-value));
@debug "INDEX" $i;
}
For easier testing I prepared a codepen with this code, which can be found here: https://codepen.io/rowild/pen/EOgvKy