birdpaper-ui
Version:
一个通用的 vue3 UI组件库。A common vue3 UI component library.
31 lines (30 loc) • 898 B
JavaScript
import { reactive, ref, computed, Comment } from "vue";
import { SelectOption } from "./type.js";
import { getAllElements } from "../../utils/dom.js";
const useSelect = (slots) => {
const currentSelect = reactive(new SelectOption());
const isFocus = ref(false);
const valueMap = computed(() => {
var _a, _b, _c;
try {
let obj = {};
const children = getAllElements((_a = slots.default) == null ? void 0 : _a.call(slots), true).filter((item) => item.type !== Comment) ?? [];
for (const item of children) {
if (item.type["name"] === "BpOption") {
obj[item.props.value] = item.props.label || ((_c = (_b = item.children)["default"]) == null ? void 0 : _c.call(_b)[0].children);
}
}
return obj;
} catch (error) {
return {};
}
});
return {
isFocus,
currentSelect,
valueMap
};
};
export {
useSelect
};