include-media icon indicating copy to clipboard operation
include-media copied to clipboard

allow space near operator

Open yukulele opened this issue 6 years ago • 2 comments

for better readability allow use space near operator

example:

// this works
@include media('height<phone') {}

// and this should work
@include media('height < phone') {}

yukulele avatar Sep 30 '18 17:09 yukulele

this is currently the only thing avoiding me to use this lib for ages.. currently im happy with at-breakpoint .. but this seen a good alternative if wasn't for the forced concatenated strings

milewski avatar Jun 06 '20 05:06 milewski

It looks like you just need to remove the spaces before evaluating the condition.

https://github.com/eduardoboucas/include-media/blob/0ce41aaf01f1eedf20950bf0a30632833126c748/src/_media.scss#L35-L42

=>

  } @else if ($im-media-support and length($conditions) > 0) {
    $condition: str-remove-whitespace(nth($conditions, 1));
    @media #{unquote(parse-expression($condition))} {
      // Recursive call
      @include media(slice($conditions, 2)...) {
        @content;
      }
    }
  }

str-remove-whitespace function is as follows:

@function str-remove-whitespace($str) {
  $index: str-index($str, ' ');

  @while ($index != null) {
    $str: str-slice($str, 0, $index - 1) + str-slice($str, $index + 1);
    $index: str-index($str, ' ');
  }
  @return $str;
}

I want to generate PR, but yarn install does not work on my PC.

  • Error Log
  • OS: Linux black7375 5.7.17-2-MANJARO #1 SMP PREEMPT Sat Aug 22 14:58:17 UTC 2020 x86_64 GNU/Linux

black7375 avatar Sep 02 '20 04:09 black7375