webgpu-app/text-input.js

51 lines
1.1 KiB
JavaScript

const controlGrid = document.getElementById("control-parent");
class TextInput {
constructor(label)
{
const parent = controlGrid;
const labelE = document.createElement("label");
labelE.innerHTML = label;
const inputE = document.createElement("input");
inputE.type = "text";
inputE.className = "span-2";
const rowE = document.createElement("row");
const sepE = document.createElement("row-separator");
rowE.appendChild(labelE);
rowE.appendChild(inputE);
parent.appendChild(rowE);
parent.appendChild(sepE);
this.label = label;
this.input = inputE;
this.lastValue = undefined;
const storageValue = localStorage.getItem(this.label);
if (storageValue !== null) {
this.input.value = storageValue;
} else {
this.input.value = "hexagon grid";
}
this.update();
}
update()
{
const rawValue = this.input.value;
if (rawValue !== this.lastValue) {
this.lastValue = rawValue;
localStorage.setItem(this.label, rawValue);
}
return rawValue;
}
};
export { TextInput };