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

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

Open
dmytro-lymarenko opened this issue Mar 16, 2020 · 4 comments
Open

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

dmytro-lymarenko opened this issue Mar 16, 2020 · 4 comments

Comments

@dmytro-lymarenko
Copy link

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
Copy link

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

@MrWillian
Copy link

UP! I would also like this feature.

@sec0ndhand
Copy link

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
Copy link
Owner

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:

  • The library user might not have put their CSS variables on :root, in which case @sec0ndhand's snippet will fail.
  • The CSS variables might not be available when the component is first rendered which could be very difficult for the library user to debug.

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

No branches or pull requests

5 participants