markusenglund / react-switch

A draggable toggle-switch component for React. Check out the demo at:
https://react-switch.netlify.com/
MIT License
1.33k stars 101 forks source link

Add support for hex colors with alpha values #99

Open jackstenglein opened 2 years ago

jackstenglein commented 2 years ago

Allows colors to be specified in #rrggbbaa format as well as the currently-supported formats.

markusenglund commented 2 years ago

Hi @jackstenglein, thanks for the PR.

IE11 doesn't have support for 8-digit hex values, so this has to be written in a way that regular hex-values don't get converted to 8-digit values.

I'm not opposed to adding this since it's such a small thing, but could you try to convince me why alpha values is something people would want? I don't recall anyone asking for it previously.

jackstenglein commented 2 years ago

@markusenglund Thanks for the quick response. I'll rewrite this to avoid breaking IE11. As for why this is useful, I can only speak for myself. I personally want this change because the designs I am implementing call for me to use an off-green color at a 30% opacity. Without this PR, passing my 8-digit hex causes the switch to have the incorrect colors. While I can manually convert my 8-digit hex to a 6-digit hex, this only works if I know the background color that the switch will be sitting on. This therefore requires me to manually go through my designs, find each place the switch is used, and manually calculate the 6-digit hex depending on the background color behind the switch. Personally I would prefer to just pass the 8-digit hex. Of course, if you know a better way to do what I am describing, then I am happy to close this PR and do that instead.

markusenglund commented 2 years ago

Alright. I'd be happy to merge this if you rewrite it to support IE. Keep in mind that it'll probably be a few months until I do a new release on NPM.