| 502 | this.onClick(); |
| 503 | } |
| 504 | watchForChange() {} |
| 505 | submit() {} |
| 506 | } |
| 507 | |
| 508 | export class ColorInput implements OptionsElement<string> { |
| 509 | readonly label: string; |
| 510 | readonly owner: Options; |
| 511 | readonly onSubmit: (str: string) => void; |
| 512 | colorContent: string; |
| 513 | input!: WeakRef<HTMLInputElement>; |
| 514 | value: string; |
| 515 | constructor( |
| 516 | label: string, |
| 517 | onSubmit: (str: string) => void, |
| 518 | owner: Options, |
| 519 | {initColor = "#000000"} = {}, |
| 520 | ) { |
| 521 | this.label = label; |
| 522 | this.colorContent = initColor; |
| 523 | this.value = initColor; |
| 524 | this.owner = owner; |
| 525 | this.onSubmit = onSubmit; |
| 526 | } |
| 527 | generateHTML(): HTMLDivElement { |
| 528 | const div = document.createElement("div"); |
| 529 | const span = document.createElement("span"); |
| 530 | span.textContent = this.label; |
| 531 | div.append(span); |
| 532 | const input = document.createElement("input"); |
| 533 | input.value = this.colorContent; |
| 534 | input.type = "color"; |
| 535 | input.oninput = this.onChange.bind(this); |
| 536 | this.input = new WeakRef(input); |
| 537 | div.append(input); |
| 538 | return div; |
| 539 | } |
| 540 | private onChange() { |
| 541 | this.owner.changed(); |
| 542 | const input = this.input.deref(); |
| 543 | if (input) { |
| 544 | const value = input.value as string; |
| 545 | this.value = value; |
| 546 | this.onchange(value); |
| 547 | this.colorContent = value; |
| 548 | } |
| 549 | } |
| 550 | onchange: (str: string) => void = (_) => {}; |
| 551 | watchForChange(func: (str: string) => void) { |
| 552 | this.onchange = func; |
| 553 | } |