xdesign-vue-next
Version:
XDesign Component for vue-next
98 lines (94 loc) • 4.04 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
import { _ as __unplugin_components_2 } from '../_chunks/dep-ae5efda0.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, h } from 'vue';
import props from './props.js';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.js';
import { useTNodeJSX, useContent } from '../hooks/tnode.js';
import isString from 'lodash/isString';
import { useConfig } from '../config-provider/useConfig.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/en_US.js';
import '../_chunks/dep-3a1cce9f.js';
import 'lodash/isArray';
var _Tag = defineComponent({
name: "XTag",
props: props,
setup: function setup(props2) {
var _useConfig = useConfig("tag"),
tagGlobalConfig = _useConfig.globalConfig;
var COMPONENT_NAME = usePrefixClass("tag");
var renderTNodeJSX = useTNodeJSX();
var renderContent = useContent();
var _useCommonClassName = useCommonClassName(),
SIZE = _useCommonClassName.SIZE;
var tagClass = 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(_ref, "".concat(COMPONENT_NAME.value, "--ellipsis"), props2.maxWidth), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--close"), props2.closable), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--disabled"), props2.disabled), _defineProperty(_ref, SIZE.value[props2.size], props2.size !== "medium"), _ref), props2.shape !== "square" && "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)];
});
var tagStyle = 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 h(tagGlobalConfig.value.closeIcon(h), {
"class": iconClassName
});
}
return createVNode(__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(tagContent) ? tagContent : "";
var titleAttribute = title && props2.maxWidth ? title : void 0;
return createVNode("span", {
"class": tagClass.value,
"style": tagStyle.value,
"onClick": handleClick
}, [icon, props2.maxWidth ? createVNode("span", {
"class": _defineProperty({}, "".concat(COMPONENT_NAME.value, "--text"), props2.maxWidth),
"title": titleAttribute
}, [tagContent]) : tagContent, !props2.disabled && closeIcon]);
};
}
});
export { _Tag as default };
//# sourceMappingURL=tag.js.map