kwikid-components-react
Version:
KwikID's Component Library in React
34 lines (33 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.transformOptions = exports.findOptionWidthValueOrLabel = void 0;
var _kwikidToolkit = require("kwikid-toolkit");
const transformOptions = options => {
const transformedOptions = options.map(item => {
if (typeof item === "string" || typeof item === "number" || typeof item === "boolean") {
return {
label: item,
value: item,
disabled: false,
description: "",
key: item.toString().split(" ").join("_").toLocaleLowerCase()
};
}
return {
...item,
label: item !== null && item !== void 0 && item.label ? item.label : item.value,
value: item !== null && item !== void 0 && item.value ? item.value : item.label,
disabled: item && item.disabled ? item.disabled : false,
description: item && item.description ? item.description : "",
key: item && item.key ? item.key : item.label.toString().split(" ").join("_").toLocaleLowerCase()
};
});
return (0, _kwikidToolkit.getObjectDeepCopy)(transformedOptions);
};
exports.transformOptions = transformOptions;
const findOptionWidthValueOrLabel = (options, value) => {
return transformOptions(options).find(option => (option === null || option === void 0 ? void 0 : option.value) === value);
};
exports.findOptionWidthValueOrLabel = findOptionWidthValueOrLabel;