UNPKG

tdesign-vue-next

Version:
153 lines (149 loc) 6.39 kB
/** * tdesign v1.11.5 * (c) 2025 tdesign * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-da95471f.mjs'; import { defineComponent, ref, computed, createVNode, h, onBeforeMount, onMounted } from 'vue'; import { InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, HelpCircleFilledIcon, CloseIcon } from 'tdesign-icons-vue-next'; import { Loading } from '../loading/index.mjs'; import { THEME_LIST } from './consts/index.mjs'; import props from './props.mjs'; import { usePrefixClass } from '../hooks/useConfig.mjs'; import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs'; import './utils/index.mjs'; import { u as useTNodeJSX, a as useContent } from '../_chunks/dep-46ec3e86.mjs'; import { isFunction } from 'lodash-es'; import { fadeOut, fadeIn } from './utils/animation.mjs'; import '../_chunks/dep-4ed7019e.mjs'; import '../loading/directive.mjs'; import '../loading/plugin.mjs'; import '../loading/loading.mjs'; import '../_chunks/dep-6d9c1bfc.mjs'; import '../_chunks/dep-9f375e51.mjs'; import '../loading/icon/gradient.mjs'; import '../_chunks/dep-6cfc5734.mjs'; import '../_chunks/dep-3d81ac0a.mjs'; import '../_chunks/dep-03e058e5.mjs'; import '../_chunks/dep-6a79c950.mjs'; import '../utils/dom.mjs'; import '../_chunks/dep-82d2a14f.mjs'; import '../hooks/useTeleport.mjs'; import '../loading/props.mjs'; import '../utils/render-tnode.mjs'; import '../config-provider/hooks/useConfig.mjs'; import '../config-provider/utils/context.mjs'; import '../_chunks/dep-a5ae2f3f.mjs'; import '../_chunks/dep-37fa6ccb.mjs'; import '../_chunks/dep-7fb24b17.mjs'; import '../utils/withInstall.mjs'; import './style/css.mjs'; 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.mjs.map