tdesign-mobile-vue
Version:
tdesign-mobile-vue
86 lines (82 loc) • 3.25 kB
JavaScript
/**
* tdesign v1.9.3
* (c) 2025 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, resolveComponent } from 'vue';
import { CloseIcon } from 'tdesign-icons-vue-next';
import { useTNodeJSX, useContent } from '../hooks/tnode.js';
import config from '../config.js';
import TagProps from './props.js';
import { usePrefixClass } from '../hooks/useClass.js';
import 'lodash-es';
import '../hooks/render-tnode.js';
import '../_common/js/utils/general.js';
import '../config-provider/useConfig.js';
import '../config-provider/context.js';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-f785f3d3.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-0d44b254.js';
import 'dayjs';
var prefix = config.prefix;
var _Tag = defineComponent({
name: "".concat(prefix, "-tag"),
components: {
CloseIcon: CloseIcon
},
props: TagProps,
emits: ["close", "click"],
setup: function setup(props) {
var tagClass = usePrefixClass("tag");
var renderTNodeJSX = useTNodeJSX();
var renderContent = useContent();
var tagStyle = computed(function () {
return props.maxWidth ? {
maxWidth: typeof props.maxWidth === "number" ? "".concat(props.maxWidth, "px") : props.maxWidth
} : {};
});
var tagClasses = computed(function () {
return ["".concat(tagClass.value), "".concat(tagClass.value, "--").concat(props.theme), "".concat(tagClass.value, "--").concat(props.shape), "".concat(tagClass.value, "--").concat(props.variant), "".concat(tagClass.value, "--").concat(props.size), _defineProperty(_defineProperty({}, "".concat(tagClass.value, "--closable"), props.closable), "".concat(tagClass.value, "--disabled"), props.disabled)];
});
var handleClose = function handleClose(e) {
e.stopPropagation();
if (!props.disabled) {
var _props$onClose;
(_props$onClose = props.onClose) === null || _props$onClose === void 0 || _props$onClose.call(props, {
e: e
});
}
};
var handleClick = function handleClick(e) {
if (!props.disabled) {
var _props$onClick;
(_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, {
e: e
});
}
};
return function () {
var tagContent = renderContent("default", "content");
var icon = renderTNodeJSX("icon");
return createVNode("span", {
"class": tagClasses.value,
"style": tagStyle.value,
"aria-disabled": props.disabled,
"role": "button",
"onClick": handleClick
}, [icon && createVNode("span", {
"class": "".concat(tagClass.value, "__icon")
}, [icon]), createVNode("span", {
"class": "".concat(tagClass.value, "__text")
}, [tagContent]), props.closable && createVNode("span", {
"class": "".concat(tagClass.value, "__icon-close"),
"onClick": handleClose
}, [createVNode(resolveComponent("close-icon"), null, null)])]);
};
}
});
export { _Tag as default };
//# sourceMappingURL=tag.js.map