Passing arguments from a mixin to a content block
See original GitHub issueMixin content is great and has done wonders for code implementing wrapper and context abstractions. However, there is often some setup done in the mixin and that setup needs to be available to the content when it is included. The current strategy is to use global variables, which works, but is obviously not ideal.
I’d like to introduce a way for mixins to include their content block and to pass arguments to the content.
Calling the content with arguments
In order to pass arguments to content blocks an argument list can be passed to the content directive. This accepts positional and keyword arguments for passing to a content block. Variable argument semantics are allowed.
@mixin accepts-content {
@for $i from 1 to 5 {
@content ($i, 360deg * $i / 5);
}
}
Receiving arguments within a content block
A content block receives arguments using a new directive called @receive
. The directive allows an argument list declaration that is the same as for functions and mixins. Positional arguments, default values, and variable arguments are all allowed.
@include accepts-content {
@receive ($number, $hue);
.color-#{$number} {
background-color: hsl($hue, 75%, 90%);
}
}
Issue Analytics
- State:
- Created 10 years ago
- Reactions:77
- Comments:124 (19 by maintainers)
Top GitHub Comments
Please, stop
+1
ing in comments, use thumb up on already posted comments instead or provide meaningful comments, otherwise devs will definitely lock down this issue and we won’t be able to comment it and make new proposals any further.I think there are little chances we’ll see any new features untill Dart version of Sass will be completely finished.
I’ve written up a proposal for this feature. I’ll leave it open for comments for two weeks, then mark it accepted if nothing has come up.