UNPKG

tdesign-vue

Version:
156 lines (152 loc) 6.19 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _typeof from '@babel/runtime/helpers/typeof'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { CloseIcon } from 'tdesign-icons-vue'; import tinyColor from 'tinycolor2'; import { isString } from 'lodash-es'; import props from './props.js'; import mixins from '../utils/mixins.js'; import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.js'; import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js'; import { emitEvent } from '../utils/event.js'; import 'vue'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-ba613a02.js'; import '../_chunks/dep-fdb1b253.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; import '@babel/runtime/helpers/slicedToArray'; import '@babel/runtime/helpers/readOnlyError'; import '@vue/composition-api'; import '../utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _Tag = mixins(getConfigReceiverMixins("tag"), getGlobalIconMixins()).extend({ name: "TTag", props: _objectSpread({}, props), computed: { tagClass: function tagClass() { return ["".concat(this.componentName), "".concat(this.componentName, "--").concat(this.theme), "".concat(this.componentName, "--").concat(this.variant), this.shape !== "square" && "".concat(this.componentName, "--").concat(this.shape), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, this.commonSizeClassName[this.size], this.size !== "medium"), "".concat(this.componentName, "--ellipsis"), this.maxWidth), "".concat(this.componentName, "--close"), this.closable), "".concat(this.classPrefix, "-is-disabled"), this.disabled), "".concat(this.componentName, "--disabled"), this.disabled)]; }, textStyle: function textStyle() { if (this.maxWidth) { return { maxWidth: isNaN(Number(this.maxWidth)) ? this.maxWidth : "".concat(this.maxWidth, "px") }; } return {}; }, tagStyle: function tagStyle() { if (this.color) { return this.getTagColorStyle(); } return {}; } }, methods: { handleClose: function handleClose(e) { if (this.disabled) return; if (e) e.stopPropagation(); emitEvent(this, "close", { e: e }); }, handleClick: function handleClick(e) { if (this.disabled) return; emitEvent(this, "click", { e: e }); }, getCloseIcon: function getCloseIcon() { var _this = this; var h = this.$createElement; if (!this.closable) return null; var iconClassName = "".concat(this.classPrefix, "-tag__icon-close"); if (this.global.closeIcon) { return this.global.closeIcon(function (component, b) { var tProps = _typeof(b) === "object" && "attrs" in b ? b.attrs : {}; return _this.$createElement(component, { props: _objectSpread({}, tProps), "class": iconClassName, nativeOn: { click: _this.handleClose } }); }); } var _this$useGlobalIcon = this.useGlobalIcon({ CloseIcon: CloseIcon }), CloseIcon$1 = _this$useGlobalIcon.CloseIcon; return h(CloseIcon$1, { "nativeOn": { "click": this.handleClose }, "class": iconClassName }); }, getTagColorStyle: function getTagColorStyle() { var _this2 = this; var luminance = tinyColor(this.color).getLuminance(); var style = { color: luminance > 0.5 ? "black" : "white" }; if (this.variant === "outline" || this.variant === "light-outline") { style.borderColor = this.color; } if (this.variant !== "outline") { var getLightestShade = function getLightestShade() { var _tinycolor$toRgb = tinyColor(_this2.color).toRgb(), r = _tinycolor$toRgb.r, g = _tinycolor$toRgb.g, b = _tinycolor$toRgb.b; return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", 0.1)"); }; style.backgroundColor = this.variant === "dark" ? this.color : getLightestShade(); } if (this.variant !== "dark") { style.color = this.color; } return style; }, renderTitle: function renderTitle(tagContent) { var vProps = this.$vnode.componentOptions.propsData || {}; if (Reflect.has(vProps, "title")) { return vProps.title || void 0; } if (tagContent) { return tagContent; } return void 0; } }, render: function render() { var h = arguments[0]; var closeIcon = this.getCloseIcon(); var tagContent = renderContent(this, "default", "content"); var title = this.renderTitle(isString(tagContent) ? tagContent : ""); var icon = renderTNodeJSX(this, "icon"); return h("div", { "class": this.tagClass, "on": { "click": this.handleClick }, "style": this.tagStyle }, [icon, h("span", { "class": this.maxWidth ? "".concat(this.componentName, "--text") : void 0, "style": this.textStyle, "attrs": { "title": title } }, [tagContent]), !this.disabled ? closeIcon : void 0]); } }); export { _Tag as default }; //# sourceMappingURL=tag.js.map