notification2.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var core = require('@vueuse/core');
  5. require('../../../utils/index.js');
  6. require('../../../constants/index.js');
  7. var index$1 = require('../../icon/index.js');
  8. require('../../../hooks/index.js');
  9. var notification = require('./notification.js');
  10. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  11. var index = require('../../../hooks/use-namespace/index.js');
  12. var icon = require('../../../utils/vue/icon.js');
  13. var aria = require('../../../constants/aria.js');
  14. const _hoisted_1 = ["id"];
  15. const _hoisted_2 = ["textContent"];
  16. const _hoisted_3 = { key: 0 };
  17. const _hoisted_4 = ["innerHTML"];
  18. const __default__ = vue.defineComponent({
  19. name: "ElNotification"
  20. });
  21. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  22. ...__default__,
  23. props: notification.notificationProps,
  24. emits: notification.notificationEmits,
  25. setup(__props, { expose }) {
  26. const props = __props;
  27. const ns = index.useNamespace("notification");
  28. const { Close } = icon.CloseComponents;
  29. const visible = vue.ref(false);
  30. let timer = void 0;
  31. const typeClass = vue.computed(() => {
  32. const type = props.type;
  33. return type && icon.TypeComponentsMap[props.type] ? ns.m(type) : "";
  34. });
  35. const iconComponent = vue.computed(() => {
  36. if (!props.type)
  37. return props.icon;
  38. return icon.TypeComponentsMap[props.type] || props.icon;
  39. });
  40. const horizontalClass = vue.computed(() => props.position.endsWith("right") ? "right" : "left");
  41. const verticalProperty = vue.computed(() => props.position.startsWith("top") ? "top" : "bottom");
  42. const positionStyle = vue.computed(() => {
  43. return {
  44. [verticalProperty.value]: `${props.offset}px`,
  45. zIndex: props.zIndex
  46. };
  47. });
  48. function startTimer() {
  49. if (props.duration > 0) {
  50. ;
  51. ({ stop: timer } = core.useTimeoutFn(() => {
  52. if (visible.value)
  53. close();
  54. }, props.duration));
  55. }
  56. }
  57. function clearTimer() {
  58. timer == null ? void 0 : timer();
  59. }
  60. function close() {
  61. visible.value = false;
  62. }
  63. function onKeydown({ code }) {
  64. if (code === aria.EVENT_CODE.delete || code === aria.EVENT_CODE.backspace) {
  65. clearTimer();
  66. } else if (code === aria.EVENT_CODE.esc) {
  67. if (visible.value) {
  68. close();
  69. }
  70. } else {
  71. startTimer();
  72. }
  73. }
  74. vue.onMounted(() => {
  75. startTimer();
  76. visible.value = true;
  77. });
  78. core.useEventListener(document, "keydown", onKeydown);
  79. expose({
  80. visible,
  81. close
  82. });
  83. return (_ctx, _cache) => {
  84. return vue.openBlock(), vue.createBlock(vue.Transition, {
  85. name: vue.unref(ns).b("fade"),
  86. onBeforeLeave: _ctx.onClose,
  87. onAfterLeave: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("destroy")),
  88. persisted: ""
  89. }, {
  90. default: vue.withCtx(() => [
  91. vue.withDirectives(vue.createElementVNode("div", {
  92. id: _ctx.id,
  93. class: vue.normalizeClass([vue.unref(ns).b(), _ctx.customClass, vue.unref(horizontalClass)]),
  94. style: vue.normalizeStyle(vue.unref(positionStyle)),
  95. role: "alert",
  96. onMouseenter: clearTimer,
  97. onMouseleave: startTimer,
  98. onClick: _cache[0] || (_cache[0] = (...args) => _ctx.onClick && _ctx.onClick(...args))
  99. }, [
  100. vue.unref(iconComponent) ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
  101. key: 0,
  102. class: vue.normalizeClass([vue.unref(ns).e("icon"), vue.unref(typeClass)])
  103. }, {
  104. default: vue.withCtx(() => [
  105. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(iconComponent))))
  106. ]),
  107. _: 1
  108. }, 8, ["class"])) : vue.createCommentVNode("v-if", true),
  109. vue.createElementVNode("div", {
  110. class: vue.normalizeClass(vue.unref(ns).e("group"))
  111. }, [
  112. vue.createElementVNode("h2", {
  113. class: vue.normalizeClass(vue.unref(ns).e("title")),
  114. textContent: vue.toDisplayString(_ctx.title)
  115. }, null, 10, _hoisted_2),
  116. vue.withDirectives(vue.createElementVNode("div", {
  117. class: vue.normalizeClass(vue.unref(ns).e("content")),
  118. style: vue.normalizeStyle(!!_ctx.title ? void 0 : { margin: 0 })
  119. }, [
  120. vue.renderSlot(_ctx.$slots, "default", {}, () => [
  121. !_ctx.dangerouslyUseHTMLString ? (vue.openBlock(), vue.createElementBlock("p", _hoisted_3, vue.toDisplayString(_ctx.message), 1)) : (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
  122. vue.createCommentVNode(" Caution here, message could've been compromised, never use user's input as message "),
  123. vue.createElementVNode("p", { innerHTML: _ctx.message }, null, 8, _hoisted_4)
  124. ], 2112))
  125. ])
  126. ], 6), [
  127. [vue.vShow, _ctx.message]
  128. ]),
  129. _ctx.showClose ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
  130. key: 0,
  131. class: vue.normalizeClass(vue.unref(ns).e("closeBtn")),
  132. onClick: vue.withModifiers(close, ["stop"])
  133. }, {
  134. default: vue.withCtx(() => [
  135. vue.createVNode(vue.unref(Close))
  136. ]),
  137. _: 1
  138. }, 8, ["class", "onClick"])) : vue.createCommentVNode("v-if", true)
  139. ], 2)
  140. ], 46, _hoisted_1), [
  141. [vue.vShow, visible.value]
  142. ])
  143. ]),
  144. _: 3
  145. }, 8, ["name", "onBeforeLeave"]);
  146. };
  147. }
  148. });
  149. var NotificationConstructor = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/notification/src/notification.vue"]]);
  150. exports["default"] = NotificationConstructor;
  151. //# sourceMappingURL=notification2.js.map