csstools / postcss-advanced-variables

Use Sass-like variables, conditionals, and iterators in CSS
Creative Commons Zero v1.0 Universal
127 stars 33 forks source link

@elseif is supported? #67

Open kono-paku opened 5 years ago

kono-paku commented 5 years ago

Hi, I found out the similar issue below. https://github.com/jonathantneal/postcss-advanced-variables/issues/8

But it appears that @if and @else works fine, not @elseif. Is there anyone to checkout this issue.

$theme-type: test1;

@if $theme-type == test1 {
  background: #000000;
} @else if $theme-type == test2 {
  background: #DDDDDD;
}  @else {
  background: #FAFAFA;
}

By the way, this plugin is so great. Thanks for providing the great plugin!

maxmilton commented 5 years ago

There's no mention of @elseif in the docs or tests, so no, it's not supported. You can of course use nested @if conditionals:

@if $theme-type == test1 {
  background: #000000;
} @else {
  @if $theme-type == test2 {
    background: #DDDDDD;
  }  @else {
    background: #FAFAFA;
  }
}
kono-paku commented 5 years ago

A nested clause deteriorates legibility of source code. I wrote down the souce below which is a bit weird but easy to understand.

@if $theme-type == test1 {
  background: #000000;
}

@if $theme-type == test2 {
  background: #DDDDDD;
}

@if $theme-type == test3 {
  background: #FAFAFA;
}
kono-paku commented 5 years ago

I would be nice if there is @elseif keyword.