@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
53 lines • 2.15 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Controls
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertHexToRgb = convertHexToRgb;
exports.createColorInput = createColorInput;
const core_common_1 = require("@itwin/core-common");
/** @alpha */
function convertHexToRgb(hex) {
// Parse a hex color string formatted as "#FFFFFF"
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? new core_common_1.RgbColor(parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)) : undefined;
}
/** @alpha */
function createColorInput(props) {
const inputDiv = document.createElement("div");
const colorInput = document.createElement("input");
colorInput.type = "color";
colorInput.value = props.value;
colorInput.onchange = () => {
try {
const value = colorInput.value;
props.handler(value);
}
catch {
//
}
};
let colorLabel;
if (undefined !== props.label) {
colorLabel = document.createElement("label");
colorLabel.innerText = `${props.label} `;
inputDiv.appendChild(colorLabel);
}
inputDiv.appendChild(colorInput);
if (undefined !== props.display)
inputDiv.style.display = props.display;
if (undefined !== props.id)
colorInput.id = props.id;
if (undefined !== props.tooltip)
colorInput.title = props.tooltip;
if (undefined !== props.disabled)
colorInput.disabled = props.disabled;
if (undefined !== props.parent)
props.parent.appendChild(inputDiv);
return undefined !== colorLabel ? { div: inputDiv, input: colorInput, label: colorLabel } : { div: inputDiv, input: colorInput };
}
//# sourceMappingURL=ColorInput.js.map