question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add transparency on themed colors (modify alpha channel of color)

See original GitHub issue

🚀 Feature request

Ability to add an alpha value to a color registered in the theme.colors object when using it.

🧱 Problem Statement / Justification

Sometimes we want to apply a color value to a props fo a component (bgColor, bgGradient, color, etc…) by using a color registered in the theme.colors object. However right now (if I’m correct), it is not possible to add or modify an alpha value to that color.

For example:

<Box
  bgColor='green.500' // <- Here we cannot add an alpha value to the color without explicitly using hardwritten RGBA or Hex value
>
</Box>

Adding a opacity props to the Box component doesn’t solve the problem as all the component, including the text, will be transparent.

✅ Proposed solution or API

We could try to format the name of the color with a special delimiter like @ for example to be able to parse the value of the alpha channel. If the color already has an alpha value to it, it overrides the alpha value. For example the string "green.500@0.4" return theme.colors.green[500] with an opacity of 0.4

So something like this can be done :

<Box
  bgGradient='linear(to-b, white, green.500@0.3)'
  >
</Box>

What do you think? Or did I miss something?

Thank you 😄

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

2reactions
la55ucommented, Apr 28, 2021
0reactions
georgebuttercommented, Jul 29, 2021

I think a workaround for some use cases (probably not gradients though) would be to set your colours up using CSS variables in RGBA format.

grey: {
    900: rgba(51, 51, 51, --opacity),
  },

Then use the sx prop to set the var to your desired value on a parent element.

<Box sx={{ "--opacity": 0.5 }}>
  <Heading color="grey.900" size="lg">
    This uses CSS Custom Properties!
  </Heading>
</Box>

I haven’t tested whether this works just putting it out there

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use alpha channels, masks, and mattes in After Effects
Learn about alpha channels that contain transparency information, track mattes, traveling mattes, and feathering masks in After Effects.
Read more >
How to change color of a png image with trasparency using ...
How to edit the color of a png image with transparent background and alpha channel ( transparency ) using Gimp.More useful things on...
Read more >
Transparency and Color - Alpha Multiplication in Resolve/Fusion
Pre-Divide/Post-Multiply: A tiny checkbox helps you avoid dark and jagged edges or bright halos when color correcting images with alpha.
Read more >
jss how to change opacity for a color - Stack Overflow
backgroundColor: theme.colors.red + '00'. This will set alpha channel to 0, thus transparent. You can append any value between '00' to 'ff'.
Read more >
Change Color Associated with Transparency? [closed]
Adding a transparent shader and using the alpha information to control the mix will make the black (0) pixels of the alpha channel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found