Does Sass have a switch function?
No there isn't any supported switch statement in sass but if you only need to use the switch statement to tweak a variable, you can use sass maps in a switch statement sort of way.
Using SASS maps in place of a switch statement
$newVar: map-get((
case_1_test_name : case_1_return_value,
case_2_test_name : case_2_return_value,
), $testVar);
So here's an example:
$vehicle: car;
$vehicleSeating: map-get((
car : 4,
bus : 20,
), $vehicle);
//$vehicleSeating = 4
The above example translated into if/else statements:
$vehicle: car;
@if ($vehicle == 'car') {
$vehicleSeating: 4;
} @else if ($vehicle == 'bus'){
$vehicleSeating: 20;
}
//$vehicleSeating = 4
Sass doesn't support Switch Case.
Sass only support four control directives:
@if
@for
@each
@while