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.

How to alias RGB with custom Alpha?

See original GitHub issue

Style Dictionary v2.10.2

I would like to do the following:

{
  "color": {
    "font": {
      "primary": { "value": "{color.base.grey.90.value}" },
      "secondary": {
        "value": {
          "r": "{color.base.grey.90.value.r}",
          "g": "{color.base.grey.90.value.g}",
          "b": "{color.base.grey.90.value.b}",
          "a": 0.2
        }
      }
    }
  }
}

But I get the following --color-font-secondary: rgba(NaN, NaN, NaN, 0.2);. Am I missing something? Is there a better way to reference a color, but change the opacity?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
henry-wrcommented, Oct 27, 2020

@MrX8503 note with the workaround you described you now have 2 attributes for each colour token: value and rgb , which can get a bit tricky when you need to update it (ensuring both attributes resolve to the same colour).

I had the same workaround and found it inconvenient when I had to update colour tokens, so I did this instead:

{
   "color": {
	"system": {
		"base": {
		  "rgb": "0,62,82",
		  "alpha": "1",
		  "value": "rgba({color.system.base.rgb}, {color.system.base.alpha})"
		},
		"500": {
		  "rgb": "{color.system.base.rgb}",
		  "alpha": "0.9",
		  "value": "rgba({color.system.500.rgb}, {color.system.500.alpha})",
		}
	}
}
2reactions
dbanksdesigncommented, Dec 6, 2020

In the next version of Style Dictionary, 3.0, we are adding the ability to have transitive transforms. This would get around the issue with transforms that @Haemp mentions. Here is an example that shows how to add transparency to colors two different ways. By splitting up the RGB or HSL channels and combining them into a single value, or by defining a custom transitive transform that modifies a color (adding transparency or brightening, darkening, etc.).

To try a pre-release of 3.0 you can install it with:

npm install style-dictionary@next
Read more comments on GitHub >

github_iconTop Results From Across the Web

rgba() and hsla() are legacy functions and aliases in modern ...
The specification introduced two changes: rgb() / hsl() accept alpha values. Color functions accept space-separared values. With rgb() ...
Read more >
rgb() - CSS: Cascading Style Sheets - MDN Web Docs
The rgb() functional notation expresses a color according to its red, green, and blue components. An optional alpha component represents the color's ...
Read more >
Anti-aliased Alpha Test: The Esoteric Alpha To Coverage
You don't need to live with the aliasing of alpha test, the sorting issues of alpha blend, or the cost of a two...
Read more >
What is the difference between rgb() and rgba() opacity?
rgb () and rgba(), and hsl() and hsla() are now aliases of each other (all of them have an optional alpha). And. Also...
Read more >
Convert anti-aliasing on color to anti-alias on transparent
Open your Channels palette and ctrl+click on the RGB channel to load it's selection, then ctrl+shift+i to inverse the selection. Press the " ......
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