Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

join a property list by commas using sass

Tags:

sass

mixins

I'm not quite sure of the syntax, but I'm taking a comma separated list of properties $properties and want to join them by a comma, so (background-color, color) becomes background-color .5s, color .5s

@mixin transition($properties, $duration) {
  $props: ();

  @each $prop in $properties {
    $tmp: $prop unquote($duration);
    $props: append($props, $tmp);
  }

  $str: join($props, ',');

  -moz-transition: $str, -moz-transform $duration;
  -webkit-transition: $str, -webkit-transform $duration;
  -o-transition: $str, -o-transform $duration;
  transition: $str, transform $duration;
}

What I'm actually getting is this:

border-color 0.5s background-color 0.5s ",", -moz-transform 0.5s

when it should be:

border-color 0.5s, background-color 0.5s, -moz-transform 0.5s
like image 886
chovy Avatar asked Oct 22 '25 01:10

chovy


1 Answers

You're overcomplicating this just a little bit by using 2 operations for joining (append and join):

@mixin transition($properties, $duration) {
    $props: ();
    $duration: unquote($duration);

    @each $p in $properties {
        $props: append($props, $p $duration, comma);
    }

    -moz-transition: $props, -moz-transform $duration;
    -webkit-transition: $props, -webkit-transform $duration;
    -o-transition: $props, -o-transform $duration;
    transition: $props, transform $duration;
}

.foo {
    @include transition((background-color, color), '.5s');
}

Output:

.foo {
  -moz-transition: background-color .5s, color .5s, -moz-transform .5s;
  -webkit-transition: background-color .5s, color .5s, -webkit-transform .5s;
  -o-transition: background-color .5s, color .5s, -o-transform .5s;
  transition: background-color .5s, color .5s, transform .5s;
}
like image 172
cimmanon Avatar answered Oct 28 '25 19:10

cimmanon