tdesign-vue-next
Version:
TDesign Component for vue-next
153 lines (149 loc) • 6.46 kB
JavaScript
/**
* tdesign v1.15.2
* (c) 2025 tdesign
* @license MIT
*/
import { defineComponent, ref, computed, onBeforeMount, onMounted, createVNode, h } from 'vue';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, HelpCircleFilledIcon, CloseIcon } from 'tdesign-icons-vue-next';
import { Loading } from '../loading/index.js';
import { THEME_LIST } from './consts/index.js';
import props from './props.js';
import { isFunction } from 'lodash-es';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-e604a5ce.js';
import { u as useTNodeJSX, a as useContent } from '../_chunks/dep-1d44782f.js';
import { u as usePrefixClass } from '../_chunks/dep-79c44a11.js';
import { u as useGlobalIcon } from '../_chunks/dep-2ac22271.js';
import '@babel/runtime/helpers/slicedToArray';
import '../_chunks/dep-7324137b.js';
import { fadeIn, fadeOut } from './utils/animation.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../_chunks/dep-199af351.js';
import '../loading/icon/gradient.js';
import '../_chunks/dep-3ba91e12.js';
import '../_chunks/dep-a72765fe.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../_chunks/dep-1f7ad104.js';
import '../_chunks/dep-b9ab7399.js';
import '../config-provider/hooks/useConfig.js';
import '../config-provider/utils/context.js';
import '../_chunks/dep-3b49fbbe.js';
import '../_chunks/dep-7fac49fa.js';
import 'dayjs';
import '../loading/props.js';
import '../_chunks/dep-6c13cc0e.js';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/classCallCheck';
import '../_chunks/dep-37a2e7c8.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 _Message = defineComponent({
name: "TMessage",
props: _objectSpread(_objectSpread({}, props), {}, {
placement: String
}),
setup: function setup(props2, _ref) {
var slots = _ref.slots,
expose = _ref.expose;
var COMPONENT_NAME = usePrefixClass("message");
var _useGlobalIcon = useGlobalIcon({
InfoCircleFilledIcon: InfoCircleFilledIcon,
CheckCircleFilledIcon: CheckCircleFilledIcon,
ErrorCircleFilledIcon: ErrorCircleFilledIcon,
HelpCircleFilledIcon: HelpCircleFilledIcon,
CloseIcon: CloseIcon
}),
InfoCircleFilledIcon$1 = _useGlobalIcon.InfoCircleFilledIcon,
CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon,
ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon,
HelpCircleFilledIcon$1 = _useGlobalIcon.HelpCircleFilledIcon,
CloseIcon$1 = _useGlobalIcon.CloseIcon;
var classPrefix = usePrefixClass();
var renderTNode = useTNodeJSX();
var renderContent = useContent();
var msgRef = ref(null);
var timer = ref(null);
var classes = computed(function () {
var status = {};
THEME_LIST.forEach(function (t) {
return status["".concat(classPrefix.value, "-is-").concat(t)] = props2.theme === t;
});
return [COMPONENT_NAME.value, status, _defineProperty({}, "".concat(classPrefix.value, "-is-closable"), props2.closeBtn || slots.closeBtn)];
});
var close = function close(e) {
var _props2$onClose, _props2$onCloseBtnCli;
(_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 || _props2$onClose.call(props2, {
trigger: "close-click",
e: e
});
(_props2$onCloseBtnCli = props2.onCloseBtnClick) === null || _props2$onCloseBtnCli === void 0 || _props2$onCloseBtnCli.call(props2, {
e: e
});
};
var clearTimer = function clearTimer() {
props2.duration && clearTimeout(timer.value);
};
var setTimer = function setTimer() {
if (!props2.duration) {
return;
}
timer.value = Number(setTimeout(function () {
clearTimer();
var msgDom = msgRef.value;
fadeOut(msgDom, props2.placement, function () {
var _props2$onClose2, _props2$onDurationEnd;
(_props2$onClose2 = props2.onClose) === null || _props2$onClose2 === void 0 || _props2$onClose2.call(props2, {
trigger: "duration-end"
});
(_props2$onDurationEnd = props2.onDurationEnd) === null || _props2$onDurationEnd === void 0 || _props2$onDurationEnd.call(props2);
});
}, props2.duration));
};
var renderClose = function renderClose() {
var defaultClose = createVNode(CloseIcon$1, null, null);
return createVNode("span", {
"class": "".concat(COMPONENT_NAME.value, "__close"),
"onClick": close
}, [renderTNode("closeBtn", defaultClose)]);
};
var renderIcon = function renderIcon() {
if (props2.icon === false) return;
if (isFunction(props2.icon)) return props2.icon(h);
if (slots.icon) {
return slots.icon(null);
}
var Icon = {
info: InfoCircleFilledIcon$1,
success: CheckCircleFilledIcon$1,
warning: ErrorCircleFilledIcon$1,
error: ErrorCircleFilledIcon$1,
question: HelpCircleFilledIcon$1,
loading: Loading
}[props2.theme];
return createVNode(Icon, null, null);
};
onBeforeMount(function () {
props2.duration && setTimer();
});
onMounted(function () {
var msgDom = msgRef.value;
fadeIn(msgDom, props2.placement);
});
expose({
close: close
});
return function () {
return createVNode("div", {
"ref": msgRef,
"class": classes.value,
"onMouseenter": clearTimer,
"onMouseleave": setTimer
}, [renderIcon(), renderContent("content", "default"), renderClose()]);
};
}
});
export { _Message as default };
//# sourceMappingURL=message.js.map