UNPKG

tdesign-vue

Version:
98 lines (94 loc) 4.16 kB
/** * tdesign v1.15.0 * (c) 2026 tdesign * @license MIT */ import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import props from './props.js'; import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js'; import { getClassPrefixMixins } from '../config-provider/config-receiver.js'; import mixins from '../utils/mixins.js'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import 'vue'; import '@vue/composition-api'; import 'lodash-es'; 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-e5d497fb.js'; import '../_chunks/dep-1618e1d6.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; 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 classPrefixMixins = getClassPrefixMixins("badge"); var _Badge = mixins(classPrefixMixins).extend({ name: "TBadge", props: _objectSpread({}, props), methods: { getContent: function getContent() { if (typeof this.$scopedSlots.count === "function") { return this.$scopedSlots.count(null); } if (typeof this.count === "function") { return renderTNodeJSX(this, "count"); } if (isNaN(Number(this.count))) { return this.count; } var count = Number(this.count); return count > this.maxCount ? "".concat(this.maxCount, "+") : count; }, isSmall: function isSmall() { return this.size === "small"; }, isZero: function isZero() { var content = this.getContent(); return content === 0 || content === "0"; }, isHidden: function isHidden() { return !this.showZero && this.isZero(); }, getOffset: function getOffset() { if (!this.offset) return {}; var _this$offset = _slicedToArray(this.offset, 2), xOffset = _this$offset[0], yOffset = _this$offset[1]; xOffset = isNaN(Number(xOffset)) ? xOffset : "".concat(xOffset, "px"); yOffset = isNaN(Number(yOffset)) ? yOffset : "".concat(yOffset, "px"); return { xOffset: xOffset, yOffset: yOffset }; } }, render: function render() { var h = arguments[0]; var _this$$props = this.$props, dot = _this$$props.dot, shape = _this$$props.shape, color = _this$$props.color; var content = this.getContent(); var isHidden = this.isHidden(); var children = renderContent(this, "default", "content"); var _this$getOffset = this.getOffset(), xOffset = _this$getOffset.xOffset, yOffset = _this$getOffset.yOffset; var badgeClassNames = [_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(this.componentName, "--dot"), !!dot), "".concat(this.componentName, "--circle"), !dot && shape === "circle"), "".concat(this.componentName, "--round"), shape === "round"), "".concat(this.componentName, "--ribbon"), shape === "ribbon"), "".concat(this.classPrefix, "-size-s"), this.isSmall())]; var inlineStyle = { background: "".concat(color), right: xOffset, top: yOffset }; return h("div", { "class": this.componentName }, [children || null, isHidden ? null : h("sup", { "class": badgeClassNames, "style": inlineStyle }, [dot ? null : content])]); } }); export { _Badge as default }; //# sourceMappingURL=badge.js.map