Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
Match color prop to browser colors/hex/rgb aswell as color vars

Alright, so I'm working on a custom vue component and one of its props is a color.

I would like to be able to match this color to all possible use cases. The ones I can think of are

  • Predefined browser colors like white, black, etc.
  • Hex/RGB color codes (or others that browser parses).
  • Custom color variables (such as var(--pa-primary-accent)

For the first 2 cases, just passing the color and using it would work, however for the third, if the user just passes in pa-primary-accent then I have to append it with the var(--${color}). How would you have something that is fully compaitable with both cases?

This is an excerpt of the code:

// Current implementation, breaks if user passes `white` for example.
computed: {
    style () {
      return `
      background-color: var(--${this.bgColor});
      `
    },
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So an approach to fixing this as proposed by @vrugtehagel is to use fallbacks, I have done this for all my color related CSS values and it worked fine.

Example: background-color: var(--${this.bgColor}, ${this.bgColor});

Bear in mind this will always prioritize the custom -- prefixed values if a normal value with the same name is valid.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda