Skip to content

Commit

Permalink
Don't change opacity of gradient in opacity-slider as value change an…
Browse files Browse the repository at this point in the history
…d value itself may contain alpha
  • Loading branch information
bjarnef committed Sep 28, 2023
1 parent 35e7860 commit dd34062
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/uui-color-picker/lib/uui-color-picker.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,23 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
return this.uppercase ? string.toUpperCase() : string.toLowerCase();
}

/** Generates a hex string from HSL values. Hue must be 0-360. All other arguments must be 0-100. */
private getHexString(
hue: number,
saturation: number,
lightness: number,
alpha = 100
) {
const color = colord(
`hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha / 100})`
);
if (!color.isValid()) {
return '';
}

return color.toHex();
}

private _syncValues() {
this.inputValue = this.getFormattedValue(this.format);
this.value = this.inputValue;
Expand Down Expand Up @@ -595,7 +612,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
class="opacity-slider"
.value=${Math.round(this.alpha)}
type="opacity"
.color=${this.value}
.color=${this.getHexString(this.hue, this.saturation, this.lightness)}
@change=${this.handleAlphaChange}>
</uui-color-slider>
`
Expand Down

0 comments on commit dd34062

Please sign in to comment.