baseui
Version:
A React Component library implementing the Base design language
49 lines (46 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.expandValue = void 0;
exports.normalizeOptions = normalizeOptions;
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
function groupedOptionsToArray(groupedOptions) {
return Object.keys(groupedOptions).reduce((arr, optgroup) => {
const optgroupOptions = groupedOptions[optgroup];
return arr.concat(
// @ts-ignore
optgroupOptions.map(option => {
return {
...option,
__optgroup: optgroup
};
}));
}, []);
}
function normalizeOptions(options) {
if (options) {
if (Array.isArray(options)) {
return options;
} else {
return groupedOptionsToArray(options);
}
}
return [];
}
const expandValue = (value, props) => {
if (!props.options) return value;
const normalizedOptions = normalizeOptions(props.options);
for (let i = 0; i < normalizedOptions.length; i++) {
// @ts-ignore
if (String(normalizedOptions[i][props.valueKey]) === String(value[props.valueKey])) {
return normalizedOptions[i];
}
}
return value;
};
exports.expandValue = expandValue;