Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to alias RGB with custom Alpha? #479

Closed
MrX8503 opened this issue Oct 19, 2020 · 8 comments
Closed

How to alias RGB with custom Alpha? #479

MrX8503 opened this issue Oct 19, 2020 · 8 comments

Comments

@MrX8503
Copy link

MrX8503 commented Oct 19, 2020

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?

@dbanksdesign
Copy link
Member

Apologies for the delayed response. I'm trying to figure out a way to do this right now and can't get it to work. We are working on the next major release (3.0) that I believe should make this possible. Let me try to get something working and get back to you.

@MrX8503
Copy link
Author

MrX8503 commented Oct 27, 2020

Awesome. Thank you for looking into this.

We needed this working right away, so my workaround is:

{
  "color": {
    "base": {
      "grey": {
        "90": { "value": "#252525", "rgb": "37,37,37" }
      }
    }
  }
}

Not ideal, but works for now until a better solution comes along. Looking fwd to v3. You guys are doing really great work here.

@henry-wr
Copy link

@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})",
		}
	}
}

@MrX8503
Copy link
Author

MrX8503 commented Oct 27, 2020

@henry-wr cool, thanks for the workaround. It's more to write, but less error prone.

@Haemp
Copy link

Haemp commented Dec 5, 2020

@henry-wr that is a very neat approach but will this work with transforms? My understanding is that aliasing applies after transforms in which case you won't be able to transform the composed rgba into any other color representation - is that right?

@dbanksdesign
Copy link
Member

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

@dbanksdesign
Copy link
Member

Just checking in on this, does the example I provided for the upcoming version solve this? Let me know if there are other things I can do to help.

@chazzmoney
Copy link
Collaborator

This is solved as part of 3.0 (#636). Check out the example at https://github.com/amzn/style-dictionary/tree/main/examples/advanced/transitive-transforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants