Skip to content

Commit dd34062

Browse files
committed
Don't change opacity of gradient in opacity-slider as value change and value itself may contain alpha
1 parent 35e7860 commit dd34062

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/uui-color-picker/lib/uui-color-picker.element.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,23 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
560560
return this.uppercase ? string.toUpperCase() : string.toLowerCase();
561561
}
562562

563+
/** Generates a hex string from HSL values. Hue must be 0-360. All other arguments must be 0-100. */
564+
private getHexString(
565+
hue: number,
566+
saturation: number,
567+
lightness: number,
568+
alpha = 100
569+
) {
570+
const color = colord(
571+
`hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha / 100})`
572+
);
573+
if (!color.isValid()) {
574+
return '';
575+
}
576+
577+
return color.toHex();
578+
}
579+
563580
private _syncValues() {
564581
this.inputValue = this.getFormattedValue(this.format);
565582
this.value = this.inputValue;
@@ -595,7 +612,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
595612
class="opacity-slider"
596613
.value=${Math.round(this.alpha)}
597614
type="opacity"
598-
.color=${this.value}
615+
.color=${this.getHexString(this.hue, this.saturation, this.lightness)}
599616
@change=${this.handleAlphaChange}>
600617
</uui-color-slider>
601618
`

0 commit comments

Comments
 (0)