(row: HTMLElement, prop: string, currentVal: string)
| 407 | } |
| 408 | |
| 409 | function buildColorControl(row: HTMLElement, prop: string, currentVal: string) { |
| 410 | const picker = document.createElement("input"); |
| 411 | picker.type = "color"; |
| 412 | picker.className = "prop-color prop-input"; |
| 413 | const text = document.createElement("input"); |
| 414 | text.type = "text"; |
| 415 | text.className = "prop-input"; |
| 416 | text.style.flex = "1"; |
| 417 | const normalized = currentVal.trim(); |
| 418 | trySetValue(picker, normalized); |
| 419 | text.value = normalized; |
| 420 | picker.addEventListener("input", () => { |
| 421 | text.value = picker.value; |
| 422 | commitStyle(prop, picker.value); |
| 423 | }); |
| 424 | text.addEventListener("blur", () => { |
| 425 | commitStyle(prop, text.value.trim() || null); |
| 426 | trySetValue(picker, text.value); |
| 427 | }); |
| 428 | row.appendChild(picker); |
| 429 | row.appendChild(text); |
| 430 | } |
| 431 | |
| 432 | // Only valid hex colors assign to a <input type=color>; ignore anything else. |
| 433 | function trySetValue(picker: HTMLInputElement, value: string) { |
no test coverage detected