vuestic-ui
Version:
Vue 3 UI Framework
64 lines (63 loc) • 1.86 kB
JavaScript
import { a as getValueByKey } from "../utils/value-by-key.mjs";
import { i as isObject } from "../utils/is-object.mjs";
const useSelectableListProps = {
options: { type: Array, default: () => [] },
textBy: { type: [String, Function], default: "text" },
valueBy: { type: [String, Function], default: "" },
trackBy: { type: [String, Function], default: "" },
disabledBy: { type: [String, Function], default: "disabled" },
groupBy: { type: [String, Function], default: "group" }
};
function useSelectableList(props) {
const tryResolveByValue = (value) => {
const options = props.options;
for (let i = 0; i < options.length; i++) {
if (getValue(options[i]) === value) {
return options[i];
}
}
return value;
};
const getOptionProperty = (option, prop) => {
if (!isObject(option)) {
return option;
}
return getValueByKey(option, prop);
};
const getTrackBy = (option) => {
return props.trackBy ? getOptionProperty(option, props.trackBy) : getValue(option);
};
const getDisabled = (option) => {
if (!isObject(option)) {
return false;
}
return getOptionProperty(option, props.disabledBy);
};
const getText = (option) => {
const optionText = getOptionProperty(option, props.textBy);
if (["number", "boolean"].includes(typeof optionText)) {
return String(optionText);
}
return optionText;
};
const getGroupBy = (option) => {
if (!isObject(option)) {
return void 0;
}
return getOptionProperty(option, props.groupBy);
};
const getValue = (option) => getOptionProperty(option, props.valueBy);
return {
tryResolveByValue,
getValue,
getText,
getDisabled,
getTrackBy,
getGroupBy
};
}
export {
useSelectableList as a,
useSelectableListProps as u
};
//# sourceMappingURL=useSelectableList.mjs.map