type CallbackSubmit = (data: ColorUtil.RGBA) => void;
+const enum Channel {
+ R,
+ G,
+ B,
+}
+
interface ColorPickerOptions {
callbackSubmit: CallbackSubmit;
}
class UiColorPicker implements DialogCallbackObject {
protected alphaInput: HTMLInputElement | null = null;
+ private readonly channels = new Map<Channel, HTMLInputElement>();
protected colorInput: HTMLInputElement | null = null;
protected colorTextInput: HTMLInputElement | null = null;
protected readonly element: HTMLElement;
<dl>
<dt>${Language.get("wcf.style.colorPicker.color")}</dt>
<dd>
- <input type="color">
+ <div class="inputAddon colorPickerChannel">
+ <span class="inputPrefix">R</span>
+ <input type="number" min="0" max="255" data-channel="r">
+ </div>
+ <div class="inputAddon colorPickerChannel">
+ <span class="inputPrefix">G</span>
+ <input type="number" min="0" max="255" data-channel="g">
+ </div>
+ <div class="inputAddon colorPickerChannel">
+ <span class="inputPrefix">B</span>
+ <input type="number" min="0" max="255" data-channel="b">
+ </div>
</dd>
</dl>
<dl>
</div>`,
options: {
onSetup: (content) => {
- this.colorInput = content.querySelector("input[type=color]") as HTMLInputElement;
- this.colorInput.addEventListener("input", () => this.updateColor());
+ this.channels.set(Channel.R, content.querySelector('input[data-channel="r"]') as HTMLInputElement);
+ this.channels.set(Channel.G, content.querySelector('input[data-channel="g"]') as HTMLInputElement);
+ this.channels.set(Channel.B, content.querySelector('input[data-channel="b"]') as HTMLInputElement);
+ this.channels.forEach((input) => {
+ input.addEventListener("input", () => this.updateColor());
+ });
+
this.alphaInput = content.querySelector("input[type=range]") as HTMLInputElement;
this.alphaInput.addEventListener("input", () => this.updateColor());
* @since 5.5
*/
protected getColor(): ColorUtil.RGBA {
- const color = this.colorInput!.value;
- const alpha = this.alphaInput!.value;
-
- return { ...(ColorUtil.hexToRgb(color) as ColorUtil.RGB), a: +alpha };
+ return {
+ r: parseInt(this.channels.get(Channel.R)!.value, 10),
+ g: parseInt(this.channels.get(Channel.G)!.value, 10),
+ b: parseInt(this.channels.get(Channel.B)!.value, 10),
+ a: parseInt(this.alphaInput!.value, 10),
+ };
}
/**
color = ColorUtil.stringToRgba(color);
}
- this.colorInput!.value = `#${ColorUtil.rgbToHex(color.r, color.g, color.b)}`;
+ this.channels.get(Channel.R)!.value = color.r.toString();
+ this.channels.get(Channel.G)!.value = color.g.toString();
+ this.channels.get(Channel.B)!.value = color.b.toString();
this.alphaInput!.value = color.a.toString();
this.newColor!.style.backgroundColor = ColorUtil.rgbaToString(color);
*/
constructor(element, options) {
this.alphaInput = null;
+ this.channels = new Map();
this.colorInput = null;
this.colorTextInput = null;
this.newColor = null;
<dl>
<dt>${Language.get("wcf.style.colorPicker.color")}</dt>
<dd>
- <input type="color">
+ <div class="inputAddon colorPickerChannel">
+ <span class="inputPrefix">R</span>
+ <input type="number" min="0" max="255" data-channel="r">
+ </div>
+ <div class="inputAddon colorPickerChannel">
+ <span class="inputPrefix">G</span>
+ <input type="number" min="0" max="255" data-channel="g">
+ </div>
+ <div class="inputAddon colorPickerChannel">
+ <span class="inputPrefix">B</span>
+ <input type="number" min="0" max="255" data-channel="b">
+ </div>
</dd>
</dl>
<dl>
</div>`,
options: {
onSetup: (content) => {
- this.colorInput = content.querySelector("input[type=color]");
- this.colorInput.addEventListener("input", () => this.updateColor());
+ this.channels.set(0 /* R */, content.querySelector('input[data-channel="r"]'));
+ this.channels.set(1 /* G */, content.querySelector('input[data-channel="g"]'));
+ this.channels.set(2 /* B */, content.querySelector('input[data-channel="b"]'));
+ this.channels.forEach((input) => {
+ input.addEventListener("input", () => this.updateColor());
+ });
this.alphaInput = content.querySelector("input[type=range]");
this.alphaInput.addEventListener("input", () => this.updateColor());
this.newColor = content.querySelector(".colorPickerColorNew > span");
* @since 5.5
*/
getColor() {
- const color = this.colorInput.value;
- const alpha = this.alphaInput.value;
- return Object.assign(Object.assign({}, ColorUtil.hexToRgb(color)), { a: +alpha });
+ return {
+ r: parseInt(this.channels.get(0 /* R */).value, 10),
+ g: parseInt(this.channels.get(1 /* G */).value, 10),
+ b: parseInt(this.channels.get(2 /* B */).value, 10),
+ a: parseInt(this.alphaInput.value, 10),
+ };
}
/**
* Opens the color picker after clicking on the picker button.
if (typeof color === "string") {
color = ColorUtil.stringToRgba(color);
}
- this.colorInput.value = `#${ColorUtil.rgbToHex(color.r, color.g, color.b)}`;
+ this.channels.get(0 /* R */).value = color.r.toString();
+ this.channels.get(1 /* G */).value = color.g.toString();
+ this.channels.get(2 /* B */).value = color.b.toString();
this.alphaInput.value = color.a.toString();
this.newColor.style.backgroundColor = ColorUtil.rgbaToString(color);
this.colorTextInput.value = ColorUtil.rgbaToHex(color);