UNPKG

vxe-pc-ui

Version:
98 lines (97 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _vue = require("vue"); var _xeUtils = _interopRequireDefault(require("xe-utils")); var _ui = require("../../ui"); var _vn = require("../../ui/src/vn"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _default = exports.default = (0, _vue.defineComponent)({ name: 'VxeTag', props: { status: String, title: [String, Number], icon: String, content: [String, Number], size: { type: String, default: () => (0, _ui.getConfig)().tag.size || (0, _ui.getConfig)().size } }, emits: ['click'], setup(props, context) { const { slots, emit } = context; const xID = _xeUtils.default.uniqueId(); const { computeSize } = (0, _ui.useSize)(props); const refElem = (0, _vue.ref)(); const reactData = (0, _vue.reactive)({}); const refMaps = { refElem }; const computeMaps = {}; const $xeTag = { xID, props, context, reactData, getRefMaps: () => refMaps, getComputeMaps: () => computeMaps }; const dispatchEvent = (type, params, evnt) => { emit(type, (0, _ui.createEvent)(evnt, { $tag: $xeTag }, params)); }; const tagMethods = { dispatchEvent }; const tagPrivateMethods = {}; const clickEvent = evnt => { dispatchEvent('click', {}, evnt); }; Object.assign($xeTag, tagMethods, tagPrivateMethods); const renderContent = () => { const { icon, content } = props; const defaultSlot = slots.default; const iconSlot = slots.icon; return [iconSlot || icon ? (0, _vue.h)('span', { class: 'vxe-tag--icon' }, iconSlot ? (0, _vn.getSlotVNs)(iconSlot({})) : [(0, _vue.h)('i', { class: icon })]) : (0, _vue.createCommentVNode)(), (0, _vue.h)('span', { class: 'vxe-tag--content' }, defaultSlot ? defaultSlot({}) : _xeUtils.default.toValueString(content))]; }; const renderVN = () => { const { status, title } = props; const vSize = computeSize.value; return (0, _vue.h)('span', { ref: refElem, class: ['vxe-tag', { [`size--${vSize}`]: vSize, [`theme--${status}`]: status }], title, onClick: clickEvent }, renderContent()); }; $xeTag.renderVN = renderVN; return $xeTag; }, render() { return this.renderVN(); } });