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 100 forks source link

Allow *Color to accept css variables, not only hex-colors #69

Open dmytro-lymarenko opened 4 years ago

dmytro-lymarenko commented 4 years ago

Allow offColor, onColor, offHandleColor and onHandleColor to accept css variables, not only hex-colors.

In our project we use css vars to handle themes and we use them to customize components. But react-switch component doesn't allow to do this.

I would like to use switch component like this:

<Switch
    checked={value}
    onChange={onChange}
    onColor="var(--switch-on-color)"
    offColor="var(--switch-off-color)"
/>
DiegoDevBittencourt commented 4 years ago

Same here, I only use variable to customize my components color, I would really like this feature.

MrWillian commented 4 years ago

UP! I would also like this feature.

sec0ndhand commented 4 years ago

As long as your variable is a hex value, you can pull the value from JS.

        window
        .getComputedStyle(document.documentElement)
        .getPropertyValue('--switch-on-color')
        .trim()
markusenglund commented 3 years ago

As @sec0ndhand mentioned you could extract the hex values from the CSS variables and then input them as props.

The question is whether this should be done inside the library for convenience sake and I'm leaning towards no. A couple of problems come to mind: