Skip to content

Commit

Permalink
Update field_color.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
THEb0nny committed Mar 20, 2024
1 parent ec13cf1 commit 83c0e91
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fieldeditors/field_color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ const pxtblockly = pxt.blocks.requirePxtBlockly()
const Blockly = pxt.blocks.requireBlockly();

export interface FieldColorEnumOptions {
blocksInfo: string;
className?: string;
}

export class FieldColorEnum extends pxtblockly.FieldColorNumber {

public isFieldCustom_ = true;

private paramsData: any[];

constructor(text: string, params: FieldColorEnumOptions, opt_validator?: FieldValidator) {
super(text, params, opt_validator);
super(text, params as any, opt_validator);

this.paramsData = params["data"];
}
Expand Down Expand Up @@ -49,7 +50,9 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber {

showEditor_() {
super.showEditor_();
const colorCells = document.querySelectorAll('.legoColorPicker td');
// Due to FieldColorNumber not being set to className in latest update
//const colorCells = document.querySelectorAll('.legoColorPicker td');
const colorCells = document.querySelectorAll('.blocklyColourTable td');
colorCells.forEach((cell) => {
const titleName = this.mapColour(cell.getAttribute("title"));
const index = this.paramsData.findIndex(item => item[1] === titleName);
Expand All @@ -66,6 +69,8 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber {
const colour = this.mapColour(this.value_);
if (!opt_asHex && colour.indexOf('#') > -1) {
return `0x${colour.replace(/^#/, '')}`;
} else if (opt_asHex) {
return this.value_;
}
return colour;
}
Expand Down

0 comments on commit 83c0e91

Please sign in to comment.