简体   繁体   中英

Isolate nested sass map into new map

How can I isolate nested sass map into a new map? For example I have sass map like this:

$susy-setting: (
  s: (
    'columns': 4,
    'gutters': 30px,
  ),

  m: (
    'columns': 8,
    'gutters': 30px,
  ),

  l: (
    'columns': 12,
    'gutters': 30px,
  )
);

Then I need to isolate each map inside after the loop, because my other mixin need map for its parameter.

@each $setting in $susy-setting{
    @include susy-settings-block($setting) { // This mixin need map
        @for $i from 1 through map-get($setting, 'columns') {
            @content;
        }
    }
}

To answer your primary question, you'll need to get both the key and value in your loop: @each $size, $setting in $susy-setting . The $size variable will store the key (eg s , m , l ) while the $setting variable stores the map value assigned to that key.

EDIT: I saw your comment on my gist, which provides a bit more context. Try this:

@mixin susy-settings-block(
  $name, 
  $config: $susy-settings
) {
  // store the old settings
  $global: $susy;

  // Get the new settings by name
  $new: map-get($config, $name);

  // apply the new settings
  $susy: map-merge($susy, $new) !global;

  // allow nested styles, using new settings
  @content;

  // return to the initial settings
  $susy: $global !global;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM