How to use Stylus lookup in a hash object

0

Is there a way to use the lookup function to apply hash objects to within for ?

I'm using it this way:

$color= {
  $success: {
    bg: #4caf50,
    ...
  }
  ,
  $error: {
    bg: #f44336,
    ...
  }
  ,
  $warning: {
    bg: #f0ad4e,
    ...
  }
  ,
  $info: {
    bg: #03a9f4,
    ...
  }
}

tag-type= {
  '.success': $success,
  '.error': $error,
  '.warning': $warning,
  '.info': $info
}

.ui-tag
  for tags, value in tag-type
    & { tags }
      teste = lookup('$color.'+value+'.primary')
      foo: teste
      border-color: $color.$info.primary // Exemplo esperado
    
asked by anonymous 17.08.2018 / 16:36

1 answer

0

I found a method using interpolation , in case I modified for to send a value and insert in the mixin type :

baseTag(type)
  if type in $color
    border-color: $color[type].primary
  else error('Not a variable defined by: $color')

Now the final code looks like this:

$color= {
  $success: {
    bg: #4caf50,
  },
  $error: {
    bg: #f44336,
  },
  $warning: {
    bg: #f0ad4e,
  },
  $info: {
    bg: #03a9f4,
  }
}

tag-type= {
  '.success': $success,
  '.error': $error,
  '.warning': $warning,
  '.info': $info
}

.ui-tag
  for tags, value in tag-type
    &{ tags }
      baseTag(value) // com base do value inserir as variáveis $color
    
20.08.2018 / 21:00