user1082754
user1082754

Reputation:

Return variables from mixin with Stylus

Is it possible to apply variables to the local scope from a mixin or function? For example:

.hello-world
    get-variables(bar);
    content: $foo;

Will output to:

.hello-world
    content: 'bar';

Because the get-variables mixin applied a variable named $foo to the local scope.

Is this possible in Stylus? If not, is it possible with Sass?

Upvotes: 1

Views: 1069

Answers (1)

limitlessloop
limitlessloop

Reputation: 1474

At the time of writing I don't think it's possible to return variables from a mixin or function in Stylus.

For example:

val = green

foo()
    val = red
    return val

.foo
    foo()
    color val

Returns:

.foo {
    color: green;
}

In SASS however this:

$val: green

@mixin foo 
    $val: red

.foo
    @include foo
    color: $val

Will return:

.foo {
    color: red;
}

In Stylus however you can assign the result of a function to a variable which may or may not give you the result you are looking for.

val = foo()
content val

Upvotes: 1

Related Questions