@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
61 lines • 2.34 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.createNumericInput = createNumericInput;
exports.createLabeledNumericInput = createLabeledNumericInput;
/** @alpha */
function createNumericInput(props, useFloat = false) {
const input = document.createElement("input");
input.type = "number";
input.value = props.value.toString();
input.onchange = () => {
try {
const value = useFloat ? parseFloat(input.value) : parseInt(input.value, 10);
if (!Number.isNaN(value))
props.handler(value, input);
}
catch {
//
}
};
if (undefined !== props.id)
input.id = props.id;
if (undefined !== props.display)
input.style.display = props.display;
if (undefined !== props.min)
input.min = props.min.toString();
if (undefined !== props.max)
input.max = props.max.toString();
if (undefined !== props.step)
input.step = props.step.toString();
if (undefined !== props.tooltip)
input.title = props.tooltip;
if (undefined !== props.disabled)
input.disabled = props.disabled;
if (undefined !== props.parent)
props.parent.appendChild(input);
return input;
}
/** @alpha */
function createLabeledNumericInput(props) {
const div = document.createElement("div");
if (props.divDisplay)
div.style.display = props.divDisplay;
const label = document.createElement("label");
label.htmlFor = props.id;
label.innerText = props.name;
div.appendChild(label);
const inputProps = { ...props };
inputProps.parent = div;
inputProps.display = "inline";
const input = createNumericInput(inputProps, true === props.parseAsFloat);
if (undefined !== props.parent)
props.parent.appendChild(div);
if (undefined !== props.tooltip)
div.title = props.tooltip;
return { label, div, input };
}
//# sourceMappingURL=NumericInput.js.map