H3lltronik
H3lltronik

Reputation: 886

Is it posible to dynamically invoke a mixin in Sass?

Is it posible to invoke a mixin doing something like this?

@mixin font-mixin ($mixinName, $color) {
    @include #{$mixinName};
    color: $color;
}

I mean I tried that, it does not work but,is there any way to do something like this? I want to dynamically call a mixin providing the name of the mixin I need to invoke as parameter of another mixin since it will help reducing a lot of code in my project

Upvotes: 1

Views: 349

Answers (1)

Gh05d
Gh05d

Reputation: 9002

You can't do this directly, but you can work around it. You could do kind of a switch statement:

@mixin breakpoint($mixin) {
  @if $mixin == mixin1 {
    @include mixin1;
  }

  @if $mixin == mixin2 {
    @include mixin2;
  }
}

Upvotes: 1

Related Questions