0

Existe uma maneira de usar a função lookup para aplicar hash objects dentro de um for?

Estou usando dessa forma:

$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 Resposta 1

0

Encontrei um método usando através da interpolation, no caso eu modifiquei for para enviar um valor e inserir no mixin type:

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

Agora o Código final ficou assim:

$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

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .