How to use Stylus lookup on an Object hash

Asked

Viewed 11 times

0

There is a way to use the function lookup to apply hash objects within a 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

1 answer

0


I found a method using through interpolation, in case I modified for to send a value and insert into 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 is 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.