SASS හි පරාමිතීන්වල විචල්යයන්
මික්සින් හෝ ශ්රිතයක් ලැබිය යුතු අවස්ථා තිබේ නොදන්නා පරාමිති ගණනක්. මේ සඳහා SASS භාෂාවේ හැකියාව ඇත "විචල්ය පරාමිතීන්" හෝ පරාමිතීන් පසුරුවා යැවීම, එය ශ්රිතයේ අවසානයේ දක්වා ඇත හෝ මික්සින් සහ අනෙකුත් සියල්ල ලැයිස්තුවක් තුළ ඇසුරුම් කරන්න මාරු කරන ලද පරාමිතීන්.
එවැනි පරාමිතීන්ට පසුව ඉලිප්සිය ලකුණක් යෙදිය යුතුය. පහත උදාහරණය සලකා බලමු:
@mixin box-content-padding($padding...) {
-moz-box-content-padding: $padding;
-webkit-box-content-padding: $padding;
}
div {
@include box-content-padding(0px 4px 5px 2px);
}
සංකලනයේ ප්රතිඵලය:
div {
-moz-box-content-padding: 0px 4px 5px 2px;
-webkit-box-content-padding: 0px 4px 5px 2px;
}
විචල්ය ශ්රිතයකට හෝ මික්සින් වෙතද
නම් කරන ලද පරාමිතීන් ලබා දිය හැකිය.
ඒවාට ප්රවේශ වීමට හැකි වන පරිදි
ශ්රිතය භාවිතා කරන්න keywords($args),
එය ඒවා අනුරූපයක් ලෙස ආපසු ලබා දෙයි
නම් (ලකුණකින් තොරව $) අගයන්.
@mixin common-colors($text-color, $background, $shadow) {
color: $text-color;
background-color: $background;
box-shadow: $shadow;
}
$values: white, green, grey;
.primary {
@include common-colors($values...);
}
$value-map: (text-color: black, background: grey, shadow: green);
.secondary {
@include common-colors($value-map...);
}
සංකලනයෙන් පසු අපට පෙනෙන්නේ:
.primary {
color: white;
background-color: green;
box-shadow: grey;
}
.secondary {
color: black;
background-color: grey;
box-shadow: green;
}