Skip to content

Commit

Permalink
Changed: Accepting proper values to css color fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 7, 2022
1 parent 38026f7 commit b077a01
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ export class CssColorPropertyEditor extends PropertyEditor<string> {
return input;
}

protected getDefaultValue() { return '#000'; }
protected getDefaultValue() { return '#FFFFFF'; }

public setInternalValue(value: string) {
// TODO use some Phaser function for this
// TODO validate color names
if (value === null) return;
const hasHash = value.startsWith('#');
const intValue = parseInt(hasHash ? value.substring(1) : value, 16);
if (intValue < 0 || intValue > 0xFFFFFF) return;
if (!hasHash) value = '#' + value.toUpperCase();
this._internalValue = value;
this.input.value = value;
if (!value) return;
if (!isNaN(parseInt(value, 16))) {
value = '#' + value;
}
const s = new Option().style;
s.color = value;
if (s.color !== '') {
this._internalValue = value;
this.input.value = value;
} else {
this.input.value = this._internalValue;
}
}

public updateInternalValue(): string {
Expand Down

0 comments on commit b077a01

Please sign in to comment.