2017-09-03 123 views
0

我似乎无法在任何地方找到堆栈溢出这个特定问题的答案。Sass @mixin的默认参数

我正在使用Compass,并且正在为box-shadow/text-shadow构建一个@mixin

我想知道是否可以在Sass/SCSS中设置默认参数?

这里是我当前的代码:

@mixin outer-glow($color, $type) { 
    @if $type == 'text' { 
    @include text-shadow(0 0 2px #{$color}); 
    @include text-shadow(0 0 .125rem #{$color}); // 2px 
    } @else { 
    @include box-shadow(0 0 2px #{$color}); 
    @include box-shadow(0 0 .125rem #{$color}); // 2px 
    } 
} 

我想用这个@mixin并将其默认为box-shadow如果$type没有声明:

// declaration 
@include outer-glow($my-color); 
// output 
would compile to box-shadow 

// declaration 
@include outer-glow($my-color, text); 
// output 
would compile to text-shadow 

回答

0

,我发现这个helpful post该回答我的问题。

所以我编辑我@mixin,现在我能够使用它,因为我打算,它默认为box-shadow如果现在参数被分配:

@mixin outer-glow($color, $type: box) { 
    @if $type == 'text' { 
    @include text-shadow(0 0 2px #{$color}); 
    @include text-shadow(0 0 .125rem #{$color}); // 2px 
    } @else { 
    @include box-shadow(0 0 2px #{$color}); 
    @include box-shadow(0 0 .125rem #{$color}); // 2px 
    } 
}