setColor(colorString: string | HslaColor) {
const colord = new Colord(colorString);
const { h, s, l, a } = colord.toHsl();
this.hue = h;
this.saturation = s;
this.lightness = l;
this.alpha = this.opacity ? a * 100 : 100;
const hslaColor = colorString as HslaColor;
// Workaround as hue isn't correct after changing hue slider, but Colord parse hue value as zero when color is black.
if (hslaColor && hslaColor.h) {
this.hue = hslaColor.h;
}
this._colord = colord;
...
}
Hue value from HslaColor object is e.g. 191, but after parsing in to Colord instance and use toHsl() it returns a hue of 0.
I added a workaround if the parameter is an HslaColor object and then use in this h property instead, which has the value 191.
We have something like this in a color picker wheere hue value is changed from a hue slider:
Inside
setColor()
function:Hue value from
HslaColor
object is e.g. 191, but after parsing in toColord
instance and usetoHsl()
it returns a hue of0
. I added a workaround if the parameter is anHslaColor
object and then use in thish
property instead, which has the value191
.