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

Handle Color Problem when using RGB #97

Closed aquilesalacruz closed 3 years ago

aquilesalacruz commented 3 years ago

For some reason if I use rgb(255, 255, 255) as the onHandleColor or offHandleColor it's taken as transparent on the initial render. This does not happen if I use #FFF as the value instead.

cotwitch commented 1 year ago

@aquilesalacruz This component supports only (3 or 6) hex-color (no transparency at all).

So, you could use following snippets to be able to use RGB values ;)

function valToHex(c) {
  return (c).toString(16).padStart(2, '0');
}
function rgbToHex(r, g, b) {
  return `#${valToHex(r)}${valToHex(g)}${valToHex(b)}`;
}

<Switch onColor={rgbToHex(255,0,0)} />