MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / buildColorControl

Function buildColorControl

packages/sdk-playground/src/main.ts:409–430  ·  view source on GitHub ↗
(row: HTMLElement, prop: string, currentVal: string)

Source from the content-addressed store, hash-verified

407}
408
409function 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.
433function trySetValue(picker: HTMLInputElement, value: string) {

Callers 1

makeStyleRowFunction · 0.85

Calls 2

trySetValueFunction · 0.85
commitStyleFunction · 0.85

Tested by

no test coverage detected