xdesign-vue-next
Version:
XDesign Component for vue-next
107 lines (99 loc) • 4.61 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var closeLine = require('../_chunks/dep-ac484abb.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var tag_props = require('./props.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var isString = require('lodash/isString');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/en_US.js');
require('../_chunks/dep-8d10b59f.js');
require('lodash/isArray');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var _Tag = vue.defineComponent({
name: "XTag",
props: tag_props["default"],
setup: function setup(props2) {
var _useConfig = configProvider_useConfig.useConfig("tag"),
tagGlobalConfig = _useConfig.globalConfig;
var COMPONENT_NAME = hooks_useConfig.usePrefixClass("tag");
var renderTNodeJSX = hooks_tnode.useTNodeJSX();
var renderContent = hooks_tnode.useContent();
var _useCommonClassName = hooks_useConfig.useCommonClassName(),
SIZE = _useCommonClassName.SIZE;
var tagClass = vue.computed(function () {
var _ref;
return ["".concat(COMPONENT_NAME.value), "".concat(COMPONENT_NAME.value, "--").concat(props2.theme), "".concat(COMPONENT_NAME.value, "--").concat(props2.variant), (_ref = {}, _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--ellipsis"), props2.maxWidth), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--close"), props2.closable), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--disabled"), props2.disabled), _defineProperty__default["default"](_ref, SIZE.value[props2.size], props2.size !== "medium"), _ref), props2.shape !== "square" && "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)];
});
var tagStyle = vue.computed(function () {
var maxWidth = props2.maxWidth;
return props2.maxWidth ? {
maxWidth: isNaN(Number(maxWidth)) ? String(maxWidth) : "".concat(maxWidth, "px")
} : {};
});
var handleClick = function handleClick(e) {
var _props2$onClick;
if (props2.disabled) return;
(_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, {
e: e
});
};
var getCloseIcon = function getCloseIcon() {
if (!props2.closable) return null;
var iconClassName = "".concat(COMPONENT_NAME.value, "__icon-close");
if (tagGlobalConfig.value.closeIcon) {
return vue.h(tagGlobalConfig.value.closeIcon(vue.h), {
"class": iconClassName
});
}
return vue.createVNode(closeLine.__unplugin_components_2, {
"onClick": function onClick(_ref2) {
var _props2$onClose;
var e = _ref2.e;
e.stopPropagation();
(_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 ? void 0 : _props2$onClose.call(props2, {
e: e
});
},
"class": iconClassName
}, null);
};
return function () {
var closeIcon = getCloseIcon();
var tagContent = renderContent("default", "content");
var icon = renderTNodeJSX("icon");
var title = isString__default["default"](tagContent) ? tagContent : "";
var titleAttribute = title && props2.maxWidth ? title : void 0;
return vue.createVNode("span", {
"class": tagClass.value,
"style": tagStyle.value,
"onClick": handleClick
}, [icon, props2.maxWidth ? vue.createVNode("span", {
"class": _defineProperty__default["default"]({}, "".concat(COMPONENT_NAME.value, "--text"), props2.maxWidth),
"title": titleAttribute
}, [tagContent]) : tagContent, !props2.disabled && closeIcon]);
};
}
});
exports["default"] = _Tag;
//# sourceMappingURL=tag.js.map