0

i am trying create mixin. Something like this

 @mixin localesRule($class, $cssProp, $value) {
        .#{$class:lang(pt)}, //...other locales { 
            $cssProp: $value;
        }
    }

But got error... Can someone help me? It is possible to do this?

Valeriy Donika
  • 408
  • 1
  • 5
  • 15

2 Answers2

1
@mixin localesRule($class, $cssProp, $value) {
  #{$class}:lang(pt), #{$class}:lang(pl), #{$class}:lang(sk), #{$class}:lang(mx), #{$class}:lang(pt-BR) {
    #{$cssProp}: $value;
  }
}

.foo {
  &-button {
    @include localesRule('&', padding-right, 0);
  }
}

output:

.foo-button:lang(pt), .foo-button:lang(pl), .foo-button:lang(sk), .foo-button:lang(mx), .foo-button:lang(pt-BR) {
  padding-right: 0;
}
mwl
  • 1,448
  • 14
  • 18
  • ` @mixin localesRule($class, $cssProp, $value) { .#{$class}:lang(pt), .#{$class}:lang(pl), .#{$class}:lang(sk), .#{$class}:lang(mx), .#{$class}:lang(pt-BR) { #{$cssProp}: $value; } }` and then : `&-button { font-size: 12px; other rules... /*&:lang(pt), &:lang(pl), &:lang(br), &:lang(sk), &:lang(mx), &:lang(pt-BR) { padding-right: 0; }*/ @include localesRule(&, padding-right, 0); }` and no output :| – Valeriy Donika Aug 16 '18 at 18:15
  • 1
    look at it now - this is what you mean? – mwl Aug 17 '18 at 07:20
0

Don't know what you exactly expect, here are a few basic examples in SCSS. Let's assume you have a class like this.

.login {}

Now create a mixin you want to use in the class.

@mixin main-button($parent-selector, $property, $selector, $size-value) {
    #{$parent-selector}__img {
        width: 100px;
        #{$property}: left;
    }

    #{$selector} {
        background: none;
    }

    &__button {
        font-size: $size-value;
    };
}

Use the mixin in the class.

.login {
    @include main-button(&, float, "text", 14px);
}

The output should be like this.

.login {
    .login__img {
        width: 100px;
        float: left;
    }

    .text {
        background: none;
    }

    .login__button {
        font-size: 14px;
    }
}