0

I try to pass all my workflow from Sass to Stylus, but I can not convert a function.

Here is the function in sass

    @mixin setIconInclude($icon) {
      @each $s in $ws_icon-list {
            @if nth($s, 1) == $icon {
                  content: nth($s, 2);
            }
      }
}

I tried this in Stylus but it does not work

setIconInclude($icon)
  for $s in $ws_icon-list
    if foo $s 0 == icon
      content foo $s 1

Edit:

I have a list of icons that I define in another file.

$ws_icon-list =       "iconName1"   "\f105",
                  "iconName2"   "\e81f",
                  "iconName3"   "\e820"

With the function I'm trying to achieve, I'd like to be able to access it (the SASS function works) in Stylus but I can not understand the syntax.

$icon is the first param of the icon I want to use as defined in the list.

glennsl
  • 28,186
  • 12
  • 57
  • 75
Jeremy
  • 1,756
  • 3
  • 21
  • 45
  • Try to be more specific about "not work". Can you give a specific example input, with expected and actual output? – IMSoP Feb 11 '17 at 13:38

1 Answers1

1

You can use $s[0] and $s[1] instead of nth($s, 1) and nth($s, 2), because Stylus lists are zero-based:

$ws_icon-list =   "iconName1"   "\f105",
              "iconName2"   "\e81f",
              "iconName3"   "\e820"

setIconInclude($icon)
  for $s in $ws_icon-list
    if $s[0] == $icon
      content: $s[1]

body
  setIconInclude('iconName1')
Panya
  • 2,679
  • 2
  • 18
  • 17
  • Thank you very much! I got to something similar in my other tests but it did not work. With your solution, it's great! thank you very much – Jeremy Feb 12 '17 at 10:50