webgpu-app/select.js

56 lines
1.3 KiB
JavaScript

const controlGrid = document.getElementById("control-parent");
class Select {
constructor(label, options)
{
const parent = controlGrid;
const labelE = document.createElement("label");
labelE.innerHTML = label;
const inputE = document.createElement("select");
inputE.className = "span-2";
for (let i = 0; i < options.length; i++) {
const option = options[i];
const optionE = document.createElement("option");
optionE.setAttribute("value", i);
optionE.innerHTML = option;
inputE.appendChild(optionE);
}
const rowE = document.createElement("row");
const sepE = document.createElement("row-separator");
rowE.appendChild(labelE);
rowE.appendChild(inputE);
parent.appendChild(rowE);
parent.appendChild(sepE);
this.input = inputE;
this.options = options;
this.lastValue = undefined;
const storageValue = localStorage.getItem(this.label);
if (storageValue !== null) {
this.input.value = storageValue;
}
this.update();
}
update()
{
const rawValue = parseInt(this.input.value);
if (rawValue !== this.lastValue) {
this.lastValue = rawValue;
localStorage.setItem(this.label, rawValue);
}
return rawValue;
}
};
export { Select };