SASS Duplicating/Renaming a class containing map

30 Views Asked by At

I have an existing SASS map that looks like this:

@each $color, $value in $theme-colors {
  .old-name-#{$color} {
      color: $value;
  }
}

I want to keep .old-name in my CSS but create a new alias with new naming. For other areas I'm just using:

.new-name { 
  @extend .old-name;
}

How does it work in the syntax when you want to extend a class with a map? Is something like this possible?

.new-name-#($color) { 
  @extend .old-name-#($color);
}
1

There are 1 best solutions below

0
On

Yes, it is perfectly possible to extends the selectors you created using maps.

@each $color, $value in $theme-colors {
  .old-name-#{$color} {
    color: $value;
  }
}

@each $color, $value in $theme-colors {
  .new-name-#{$color} {
    @extend .old-name-#{$color};
  }
}