How to Generate Placeholders in Stylus

女生的网名这么多〃 提交于 2019-12-08 03:14:56

问题


I'm looking to generate placeholders and variables that can change depending on configured proportions such as the following:

  • $small-margin-top
  • $large-margin-top
  • $small-padding-bottom

Where each placeholder applies the corresponding, generated variable to the rule:

$small-margin-top
    margin-top $marginsmall

$large-margin-top
    margin-top $marginLarge

$small-padding-bottom
    margin-bottom $marginSmall

I have statically defined the variables for now:

/* Margin */
$margin = 1rem
$marginsmall = $margin / $multiplier
$marginlarge = $margin * $multiplierLarge
$marginmini = $marginSmall / $multiplierLarge

But I get an error:

TypeError: expected "name" to be a string, but got ident:marginmini

properties = margin padding

proportions = mini small medium large

directions = top left bottom right

for property in properties
    for proportion in proportions
            for direction in directions
                ${property}-{direction}-{proportion}
                    {property}-{direction} lookup(property + proportion)

How can I generate placeholders for my proportions variable, such that the generated placeholders may be extended later (@extend $margin-large)?


EDIT: here is the working solution


回答1:


The lookup bif accepts a string, and you are passing an ident (margin, padding, etc. without quotes). You can convert them to string by using concatenation. Also, you miss a $ sign:

properties = margin padding

proportions = mini small medium large

directions = top left bottom right

for property in properties
    for proportion in proportions
        for direction in directions
            ${proportion}-{property}-{direction}
                {property}-{direction} lookup('$' + property + proportion)


来源:https://stackoverflow.com/questions/25375087/how-to-generate-placeholders-in-stylus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!