UNPKG

@opensig/opendesign

Version:

<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>

75 lines (74 loc) 2.46 kB
import { defineComponent, ref, watch, 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 { isUndefined, 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 isVisible = ref(props.visible ?? props.defaultVisible); watch( () => props.visible, (val) => { if (!isUndefined(val)) { isVisible.value = val; } } ); const onClose = async (ev) => { ev.stopPropagation(); if (isFunction(props.beforeClose)) { const rlt = await props.beforeClose(); if (rlt) { isVisible.value = false; emits("update:visible", isVisible.value); emits("close", ev); return; } } isVisible.value = false; emits("update:visible", isVisible.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]]), 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 };