Prepocessor (Less) - Variable @Arguments

Asked

Viewed 49 times

3

Assuming I have the following mixin with following arguments:

.font-style(@size: 1.2em, @style: 100, @leading:1.4em, @color: #efefed)

Now I want to play this mixin passing the arguments I define to a specific class. Ex:

.myClass{ .font-style(2.2em,...) }

Doubt: If I only want to modify the argument @size and @color, I would need to repeat the default (@Arguments) on account of the Ex order:

.font-style( @==a -> "mudei valor", @==b "default", @==c "default", @==d -> "mudei valor )

Or have a different way that you can use the default ones without repeating and change what I really need?

1 answer

1

Yes, when creating your mixin with parameters using the "@Arguments" variable you must specify a default value for each of them.

So when calling your mixin you don’t need to pass the values in a special order and even omit the defaults. Ex:

Set Mixin

.font-style(@size: 1.2em, @style: 100, @leading:1.4em, @color: #efefed);

Call Mixin

.myClass{ .font-style(2.2em,2.4em) }

Note omission of other parameters.

Optional parameters (not explicit value) need to be passed when there is a call. Ex:

.font-style(@size: @size, @color: @color);

Sources:
https://github.com/SomMeri/less4j/wiki/Less-Language-Mixins#Explicit-Parameters https://stackoverflow.com/questions/17116082/less-mixin-with-optional-parameters https://stackoverflow.com/questions/10837085/less-css-with-optional-parameters

Browser other questions tagged

You are not signed in. Login or sign up in order to post.