Ser-Gen
Ser-Gen

Reputation: 85

How to make a mixin with the same name as the value of a variable?

I have variable and need to construct mixin with its value:

$param = 'color';

{$param}() {
  color: green;
}

.foo {
  color: red;
}

It's renders as

color() {
  color: #008000;
}
.foo {
  color: #f00;
}

But I need

.foo {
  color: #008000;
}

Maybe, I don't know, how to do it right.
How can I get it?

Upvotes: 1

Views: 423

Answers (1)

Ser-Gen
Ser-Gen

Reputation: 85

I have got answer from maintainer of Stylus:

You can do this with define bif and anonymous functions:

$param = 'color'

define($param, @() {
  color green
})

.foo
  color red

Upvotes: 2

Related Questions