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 kelvin in Color constructor #149

Closed
RyanMcDonald opened this issue Dec 8, 2020 · 2 comments
Closed

Allow kelvin in Color constructor #149

RyanMcDonald opened this issue Dec 8, 2020 · 2 comments

Comments

@RyanMcDonald
Copy link

I've created a color temperature picker React component that wraps iro, and my React component would be used something like this:

const [kelvin, setKelvin] = useState(6500);
<ColorTemperaturePicker color={kelvin} onChange={setKelvin} />

In my ColorTemperaturePicker implementation, it's just slightly inconvenient to have to convert my kelvin value back to RGB so that iro.Color can use it:

// color comes from component props
new iro.ColorPicker(el, {
  color: iro.Color.kelvinToRgb(color), // <--
});

// Update iro's color every time the color prop changes
useEffect(() => {
  const updatedColor = iro.Color.kelvinToRgb(color); // <--
  colorPicker.current.color.set(updatedColor);
}, [color]);

Is there any reason the iro.Color constructor can't accept kelvin format as well?

@jaames
Copy link
Owner

jaames commented Dec 8, 2020

Ah, this is a silly oversight on my behalf, sorry about that.

It should be relatively trivial to add support for specifying the initial color as an object like {kelvin: 9000}, I'll take a look at it whenever I have time :)

@jaames jaames closed this as completed in 5261cbd Mar 27, 2021
@jaames
Copy link
Owner

jaames commented Mar 27, 2021

Sorry for taking so long to get to this!

The option to pass a kelvin object as a color value will be added in the next release (v 5.5.0)

Example:

colorPicker.color.set({ kelvin: 6600 });

Thanks for the suggestion!

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

2 participants