@mixin !default
See original GitHub issueFeature:
It would be nice to be able to use the !default
modifier with mixins, much like with variable assignment… if a mixin of that name was already defined, the declaration would not replace the previous one.
For example:
@mixin foo()
{
display: block;
}
@mixin foo() !default
{
display: inline;
}
.bar { @include foo; }
… would result in .bar { display: block; }
The main place I can think of that would be a great use-case is frameworks like Foundation. If all of Foundation’s mixins were defined with !default
, then the application-specific settings.scss file could override not just variables, but mixins as well, making it a lot easier to customize the output of such frameworks. As it stands now, you can tweak the variables, but mixins are either “accept them as they are or don’t use them”.
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
mixin and @include - Sass
Normally, every argument a mixin declares must be passed when that mixin is included. However, you can make an argument optional by defining...
Read more >Default values for mixins | Sass in the Real World: book 1 of 4
Set default values for mixins. When using mixins that require arguments, it is a best practice to always specify a default value for...
Read more >Simplifying SASS Mixins with Default Values | by Seth Poulin
SASS mixins are blocks of code we can bundle into packages that get unpacked when we call them with the @include function.
Read more >A Practical Tip For Using Sass Default Parameters - CSS-Tricks
You can use Sass default parameters, that is, parameters that have a value even if you don't provide them when the function or...
Read more >Making a Sass mixin with optional arguments - Stack Overflow
Super simple way. Just add a default value of none to $inset - so @ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As far as I know, it’s not even an option since mixins and functions cannot be defined in control directives.
Also, that would be
not
and not!
.Anyway, it would be cool to have the
!default
flag available for mixins and functions as well. 😃I’ve been wanting a feature like this myself. I know there’s been some discussion about namespacing, but I don’t think it would solve this problem. If I like a particular library’s boilerplate except for minor things here and there that are controlled by mixins, being able to have defaultable mixins seems like the most straightforward solution.
What happens if I want to use this mixin instead?
If the file I was importing didn’t include a base-block-styles mixin (maybe it is defined elsewhere in the library), then the user would be forced to create the mixin themselves or do an extra import. I don’t feel this is good for the user.
The only realistic option that is currently available is to check if the mixin exists before defining it:
This seems a lot less elegant than simply making use of a
!default
flag, which users are already familiar with.