bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
80 lines (79 loc) • 2.59 kB
JavaScript
import { f as formSelectKey } from "./keys-CQKrwmvN.mjs";
import { t as useDefaults } from "./useDefaults-BKgBaqOV.mjs";
import { n as get } from "./object-CHQkkner.mjs";
import { computed, createElementBlock, defineComponent, inject, mergeProps, openBlock, renderSlot, toValue, unref } from "vue";
//#region src/components/BFormSelect/BFormSelectOption.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = [
"value",
"disabled",
"selected"
];
//#endregion
//#region src/components/BFormSelect/BFormSelectOption.vue
var BFormSelectOption_default = /* @__PURE__ */ defineComponent({
__name: "BFormSelectOption",
props: {
disabled: {
type: Boolean,
default: false
},
value: { default: void 0 }
},
setup(__props) {
const props = useDefaults(__props, "BFormSelectOption");
const formSelectContext = inject(formSelectKey, null);
const isSelected = computed(() => {
if (!formSelectContext) return false;
return formSelectContext.modelValue.value === props.value;
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("option", mergeProps({
value: unref(props).value,
disabled: unref(props).disabled,
selected: isSelected.value
}, _ctx.$attrs), [renderSlot(_ctx.$slots, "default")], 16, _hoisted_1);
};
}
});
//#endregion
//#region src/composables/useFormSelect.ts
var useFormSelect = (options, props) => {
const isComplex = (option) => typeof option === "object" && option !== null && "options" in option;
const normalizeOption = (option) => {
const propsValue = toValue(props);
if (typeof option === "string") return {
value: option,
text: option
};
if (typeof option === "number") return {
value: option,
text: `${option}`
};
if (option instanceof Date) return {
value: option,
text: option.toLocaleString()
};
const value = get(option, propsValue.valueField);
const text = get(option, propsValue.textField);
const disabled = get(option, propsValue.disabledField);
const opts = propsValue.optionsField ? get(option, propsValue.optionsField) : void 0;
if (opts !== void 0) return {
label: get(option, propsValue.labelField) || text,
options: opts
};
return {
...typeof option === "object" ? option : void 0,
value,
text,
disabled
};
};
const normalizeOptions = (opts) => opts.map((option) => normalizeOption(option));
return {
normalizedOptions: computed(() => normalizeOptions(toValue(options))),
isComplex
};
};
//#endregion
export { BFormSelectOption_default as n, useFormSelect as t };
//# sourceMappingURL=useFormSelect-BYhUZcK5.mjs.map