@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
76 lines • 2.73 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRadioBox = createRadioBox;
/** @alpha */
function createRadioBox(props) {
const div = document.createElement("div");
let label;
if (undefined !== props.name) {
label = document.createElement("label");
label.htmlFor = props.id;
label.innerText = props.name;
div.appendChild(label);
}
const form = document.createElement("form");
form.id = props.id;
const radioBoxes = [];
for (const entry of props.entries) {
const input = document.createElement("input");
input.type = "radio";
input.name = props.name ? props.name : props.id;
input.value = (undefined !== entry.value) ? entry.value.toString() : "";
const inputLabel = document.createElement("label");
inputLabel.innerText = entry.label;
inputLabel.onclick = () => {
try {
input.checked = true;
const value = input.value;
props.handler(value, form);
}
catch {
//
}
};
input.onchange = () => {
try {
const value = input.value;
props.handler(value, form);
}
catch {
//
}
};
if (props.defaultValue === entry.value) {
input.checked = true;
}
radioBoxes.push(input);
if (props.vertical) {
const container = document.createElement("div");
container.appendChild(input);
container.appendChild(inputLabel);
form.appendChild(container);
}
else {
form.appendChild(input);
form.appendChild(inputLabel);
}
}
div.appendChild(form);
if (undefined !== props.parent)
props.parent.appendChild(div);
const setValue = (value) => {
const stringValue = value.toString();
const validValue = radioBoxes.map((input) => input.value).includes(stringValue);
if (validValue) {
radioBoxes.forEach((input) => input.checked = input.value === stringValue);
props.handler(stringValue, form);
}
return validValue;
};
return { div, label, setValue, form };
}
//# sourceMappingURL=RadioBox.js.map