@opensig/opendesign
Version:
81 lines (80 loc) • 2.68 kB
JavaScript
;
const vue = require("vue");
const index = require("../popup/index.js");
const types = require("./types.js");
const provide = require("./provide.js");
const is = require("../_utils/is.js");
const vueUtils = require("../_utils/vue-utils.js");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "ODropdown",
props: types.dropdownProps,
emits: ["update:visible", "visible-change"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const dropdownRef = vue.ref();
const isVisible = vue.ref(props.visible ?? props.defaultVisible);
vue.watch(
() => props.visible,
(val) => {
if (!is.isUndefined(val)) {
isVisible.value = val;
}
}
);
const updateVisible = (val) => {
isVisible.value = val;
emits("update:visible", val);
emits("visible-change", val);
};
vue.watch(isVisible, (val) => {
updateVisible(val);
});
vue.provide(provide.dropdownInjectKey, { updateVisible });
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock(
"div",
{
ref_key: "dropdownRef",
ref: dropdownRef,
class: "o-dropdown"
},
[
vue.renderSlot(_ctx.$slots, "default"),
vue.createVNode(vue.unref(index.OPopup), {
visible: isVisible.value,
"onUpdate:visible": _cache[0] || (_cache[0] = ($event) => isVisible.value = $event),
transition: props.transition,
"unmount-on-hide": props.unmountOnHide,
position: props.optionPosition,
wrapper: props.optionsWrapper,
target: dropdownRef.value,
trigger: props.trigger,
offset: 4,
"adjust-min-width": props.optionWidthMode === "min-width",
"adjust-width": props.optionWidthMode === "width"
}, {
default: vue.withCtx(() => [
vue.createElementVNode(
"ul",
{
class: vue.normalizeClass(["o-dropdown-list", vue.unref(vueUtils.mergeClass)(`o-dropdown-list-${props.size}`, props.optionWrapClass)])
},
[
vue.renderSlot(_ctx.$slots, "dropdown")
],
2
/* CLASS */
)
]),
_: 3
/* FORWARDED */
}, 8, ["visible", "transition", "unmount-on-hide", "position", "wrapper", "target", "trigger", "adjust-min-width", "adjust-width"])
],
512
/* NEED_PATCH */
);
};
}
});
module.exports = _sfc_main;