question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing arguments from a mixin to a content block

See original GitHub issue

Mixin 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:closed
  • Created 10 years ago
  • Reactions:77
  • Comments:124 (19 by maintainers)

github_iconTop GitHub Comments

11reactions
ArmorDarkscommented, Dec 9, 2016

Please, stop +1ing 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.

10reactions
nex3commented, Oct 15, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing arguments from a mixin to a content block
I want to create a custom mixin that will inherit a layout passed from susy-breakpoint() using a custom map. Example: Defining a 4...
Read more >
SASS Passing Content Block to Mixin - Coding Ninjas
The content block user can accept arguments by using the @include directive. The argument list for a content block works similar to mixin's...
Read more >
How to Use Mixins in Sass and Pass Arguments – With Code ...
First we define a mixin using the @mixin at-rule. · Then we give it a name – choose whatever you think will fit...
Read more >
Passing Content Blocks to a Mixin - Sass
Sass - Passing Content Blocks to a Mixin, Block of styles is passed to the mixin for the placement inside the styles. In...
Read more >
SASS Passing Content Block to a Mixin - javatpoint
The content blocks are passed to the mixin for the placement inside the styles. This functionality is added in Sass version 3.2. Styles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found