2017-09-03 304 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 
    } 
}