@wfrog/vc
Version:
vue3 组件库 vc
131 lines (126 loc) • 4.28 kB
JavaScript
import { defineComponent, computed, createElementBlock, createBlock, openBlock, normalizeStyle, normalizeClass, unref, createElementVNode, createCommentVNode, renderSlot, withModifiers, withCtx, createVNode, Transition } from 'vue';
import { E as ElIcon } from './m2vp1CCf.mjs';
import { Close } from '@element-plus/icons-vue';
import { c as buildProps, u as useNamespace } from './E_WRn0OP.mjs';
import { c as componentSizes } from './CS4VKsqy.mjs';
import { _ as _export_sfc, w as withInstall } from './D389hx_T.mjs';
import { c as useFormSize } from './BOAz6rgm.mjs';
const tagProps = buildProps({
type: {
type: String,
values: ["primary", "success", "info", "warning", "danger"],
default: "primary"
},
closable: Boolean,
disableTransitions: Boolean,
hit: Boolean,
color: String,
size: {
type: String,
values: componentSizes
},
effect: {
type: String,
values: ["dark", "light", "plain"],
default: "light"
},
round: Boolean
});
const tagEmits = {
close: (evt) => evt instanceof MouseEvent,
click: (evt) => evt instanceof MouseEvent
};
const __default__ = defineComponent({
name: "ElTag"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: tagProps,
emits: tagEmits,
setup(__props, { emit }) {
const props = __props;
const tagSize = useFormSize();
const ns = useNamespace("tag");
const containerKls = computed(() => {
const { type, hit, effect, closable, round } = props;
return [
ns.b(),
ns.is("closable", closable),
ns.m(type || "primary"),
ns.m(tagSize.value),
ns.m(effect),
ns.is("hit", hit),
ns.is("round", round)
];
});
const handleClose = (event) => {
emit("close", event);
};
const handleClick = (event) => {
emit("click", event);
};
const handleVNodeMounted = (vnode) => {
var _a, _b, _c;
if ((_c = (_b = (_a = vnode == null ? void 0 : vnode.component) == null ? void 0 : _a.subTree) == null ? void 0 : _b.component) == null ? void 0 : _c.bum) {
vnode.component.subTree.component.bum = null;
}
};
return (_ctx, _cache) => {
return _ctx.disableTransitions ? (openBlock(), createElementBlock("span", {
key: 0,
class: normalizeClass(unref(containerKls)),
style: normalizeStyle({ backgroundColor: _ctx.color }),
onClick: handleClick
}, [
createElementVNode("span", {
class: normalizeClass(unref(ns).e("content"))
}, [
renderSlot(_ctx.$slots, "default")
], 2),
_ctx.closable ? (openBlock(), createBlock(unref(ElIcon), {
key: 0,
class: normalizeClass(unref(ns).e("close")),
onClick: withModifiers(handleClose, ["stop"])
}, {
default: withCtx(() => [
createVNode(unref(Close))
]),
_: 1
}, 8, ["class", "onClick"])) : createCommentVNode("v-if", true)
], 6)) : (openBlock(), createBlock(Transition, {
key: 1,
name: `${unref(ns).namespace.value}-zoom-in-center`,
appear: "",
onVnodeMounted: handleVNodeMounted
}, {
default: withCtx(() => [
createElementVNode("span", {
class: normalizeClass(unref(containerKls)),
style: normalizeStyle({ backgroundColor: _ctx.color }),
onClick: handleClick
}, [
createElementVNode("span", {
class: normalizeClass(unref(ns).e("content"))
}, [
renderSlot(_ctx.$slots, "default")
], 2),
_ctx.closable ? (openBlock(), createBlock(unref(ElIcon), {
key: 0,
class: normalizeClass(unref(ns).e("close")),
onClick: withModifiers(handleClose, ["stop"])
}, {
default: withCtx(() => [
createVNode(unref(Close))
]),
_: 1
}, 8, ["class", "onClick"])) : createCommentVNode("v-if", true)
], 6)
]),
_: 3
}, 8, ["name"]));
};
}
});
var Tag = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "tag.vue"]]);
const ElTag = withInstall(Tag);
export { ElTag as E, tagProps as t };