Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!