Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Stylus support arrays of variables?

I can't find in the docs an example of using arrays as variables. It would be obvious though to have arrays support so I suspect I should search for that in a different way.

I have found lists, but not sure if these are intended for the same or similar purpose as arrays and couldn't find syntax and examples.

I have a list of colors

- cards_colors = #E0137E #8431BF #2388C4 #FED462 #EC633B #B3CF32 #2388C4 #EA8527

And I want to assign each color to a respective element in a loop, similar to this:

    for num in (0..10)
        &.card-{num}
            background cards_colors[{num}]
like image 413
Sergei Basharov Avatar asked Jan 11 '23 08:01

Sergei Basharov


2 Answers

using a list works for me:

cards_colors = ( #E0137E #8431BF #2388C4 )

for num in (0..2)
  .card-{num}
    background cards_colors[num]

see demo: http://codepen.io/anon/pen/IeiEw

like image 136
floww Avatar answered Jan 17 '23 14:01

floww


Stylus does support arrays, but it's hard to find in their documentation, even after they revamped it

$arrayName = value0, value1, value2
$arrayName[1] //value1
like image 40
webdevdani Avatar answered Jan 17 '23 14:01

webdevdani