@opensig/opendesign
Version:
74 lines (73 loc) • 2.58 kB
JavaScript
import { defineComponent, ref, computed, createElementBlock, createCommentVNode, openBlock, normalizeStyle, normalizeClass, unref, createElementVNode, renderSlot, createVNode } from "vue";
import { getRoundClass } from "../_utils/style-class.mjs";
import { tagProps } from "./types.mjs";
import { IconClose } from "../_utils/icons.mjs";
import { isFunction } from "../_utils/is.mjs";
const _hoisted_1 = {
key: 0,
class: "o-tag-icon"
};
const _hoisted_2 = { class: "o-tag-label" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "OTag",
props: tagProps,
emits: ["update:visible", "close"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const round = getRoundClass(props, "tag");
const innerIsVisible = ref(props.visible ?? props.defaultVisible);
const isVisible = computed(() => props.visible ?? innerIsVisible.value);
const onClose = async (ev) => {
ev.stopPropagation();
if (isFunction(props.beforeClose)) {
const rlt = await props.beforeClose();
if (rlt) {
innerIsVisible.value = false;
emits("update:visible", innerIsVisible.value);
emits("close", ev);
return;
}
}
innerIsVisible.value = false;
emits("update:visible", innerIsVisible.value);
emits("close", ev);
};
return (_ctx, _cache) => {
return isVisible.value ? (openBlock(), createElementBlock(
"span",
{
key: 0,
class: normalizeClass(["o-tag", [
`o-tag-${props.variant}`,
`o-tag-${props.color}`,
`o-tag-${props.size}`,
unref(round).class.value,
{ "o-tag-closable": props.closable, "o-tag-interactive": props.interactive || props.closable }
]]),
style: normalizeStyle(unref(round).style.value)
},
[
_ctx.$slots.icon ? (openBlock(), createElementBlock("span", _hoisted_1, [
renderSlot(_ctx.$slots, "icon")
])) : createCommentVNode("v-if", true),
createElementVNode("span", _hoisted_2, [
renderSlot(_ctx.$slots, "default")
]),
props.closable ? (openBlock(), createElementBlock("span", {
key: 1,
class: "o-tag-close",
onClick: onClose
}, [
createVNode(unref(IconClose))
])) : createCommentVNode("v-if", true)
],
6
/* CLASS, STYLE */
)) : createCommentVNode("v-if", true);
};
}
});
export {
_sfc_main as default
};