Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/main/src/ColorPicker.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
disabled="{{inputsDisabled}}"
class="ui5-color-picker-hue-slider"
min="0"
max="1530"
max="360"
step="1"
value="{{_hue}}"
accessible-name="{{hueSliderLabel}}"
@ui5-input="{{_handleHueInput}}"
show-tooltip
></ui5-slider>
{{#if _isDefaultPickerMode}}
<ui5-slider
Expand All @@ -33,6 +35,7 @@
value="{{_alpha}}"
accessible-name="{{alphaSliderLabel}}"
@ui5-input="{{_handleAlphaInput}}"
show-tooltip
></ui5-slider>
{{/if}}
</div>
Expand Down
28 changes: 15 additions & 13 deletions packages/main/src/ColorPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,41 +366,43 @@ class ColorPicker extends UI5Element implements IFormInputElement {
}

_setMainColor(hueValue: number) {
if (hueValue <= 255) {
const hueValueMod = hueValue * 4.251;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, assigning to a new variable (hueValueMod) and using it throughout the function, is necessary when you need both the passed param (hueValue) and the modified one (hueValueMod) at the same time. But if you'll only use the modified one, the best would be to just have: hueValue = hueValue * 4.251; and continue using hueValue in the function as before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this magic number existed before, but this refactoring is an opportunity to set it to a constant.


if (hueValueMod <= 255) {
this._mainValue = {
r: 255,
g: hueValue,
g: hueValueMod,
b: 0,
};
} else if (hueValue <= 510) {
} else if (hueValueMod <= 510) {
this._mainValue = {
r: 255 - (hueValue - 255),
r: 255 - (hueValueMod - 255),
g: 255,
b: 0,
};
} else if (hueValue <= 765) {
} else if (hueValueMod <= 765) {
this._mainValue = {
r: 0,
g: 255,
b: hueValue - 510,
b: hueValueMod - 510,
};
} else if (hueValue <= 1020) {
} else if (hueValueMod <= 1020) {
this._mainValue = {
r: 0,
g: 765 - (hueValue - 255),
g: 765 - (hueValueMod - 255),
b: 255,
};
} else if (hueValue <= 1275) {
} else if (hueValueMod <= 1275) {
this._mainValue = {
r: hueValue - 1020,
r: hueValueMod - 1020,
g: 0,
b: 255,
};
} else {
this._mainValue = {
r: 255,
g: 0,
b: 1275 - (hueValue - 255),
b: 1275 - (hueValueMod - 255),
};
}
}
Expand Down Expand Up @@ -436,7 +438,7 @@ class ColorPicker extends UI5Element implements IFormInputElement {
// and HSL format, the color will be parsed to RGB
// 0 ≤ H < 360
// 4.251 because with 4.25 we get out of the colors range.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now obsolete and should be deleted not to cause confusion.

const h = this._hue / 4.251;
const h = this._hue;

// 0 ≤ S ≤ 1
const s = 1 - +(Math.round(parseFloat((y / 256) + "e+2")) + "e-2"); // eslint-disable-line
Expand Down Expand Up @@ -497,7 +499,7 @@ class ColorPicker extends UI5Element implements IFormInputElement {
this._isHueValueChanged = false;
this._hue = this.selectedHue ? this.selectedHue : this._hue;
} else {
this._hue = Math.round(hslColours.h * 4.25);
this._hue = Math.round(hslColours.h);
}

this._setMainColor(this._hue);
Expand Down
4 changes: 2 additions & 2 deletions packages/main/test/specs/ColorPicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("Color Picker general interaction", () => {

await hueSliderHandle.dragAndDrop({ x: 200, y: 0 });

assert.strictEqual(await colorPicker.getAttribute("value"), "rgba(182, 61, 184, 0)", "Color properly changed");
assert.strictEqual(await colorPicker.getAttribute("value"), "rgba(184, 61, 184, 0)", "Color properly changed");
assert.strictEqual(await stepInput.getAttribute("value"), "1", "Change event gets fired on hue slider change");
});

Expand All @@ -75,7 +75,7 @@ describe("Color Picker general interaction", () => {
await colorPicker.scrollIntoView();
await alphaSliderHandle.dragAndDrop({ x: 200, y: 0 });

assert.strictEqual(await colorPicker.getAttribute("value"), "rgba(182, 61, 184, 0.83)", "Alpha value propely changed");
assert.strictEqual(await colorPicker.getAttribute("value"), "rgba(184, 61, 184, 0.83)", "Alpha value propely changed");
assert.strictEqual(await stepInput.getAttribute("value"), "2", "Change event gets fired on alpha slider change");
});

Expand Down