ceb2faf6791798aff93c52b7ff158e273ffc830c4a7f739f37512dda0b52a437643296eb6731f5b95c228332e9f415b7639a50716220acd54701951eab7dab 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { defineComponent, useSlots, ref, computed, toRef, openBlock, createBlock, Transition, unref, withCtx, withDirectives, createElementVNode, normalizeClass, renderSlot, resolveDynamicComponent, createCommentVNode, createElementBlock, createTextVNode, toDisplayString, Fragment, createVNode, vShow } from 'vue';
  2. import { ElIcon } from '../../icon/index.mjs';
  3. import { alertProps, alertEmits } from './alert2.mjs';
  4. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  5. import { useDelayedToggle } from '../../../hooks/use-delayed-toggle/index.mjs';
  6. import { TypeComponentsMap, TypeComponents } from '../../../utils/vue/icon.mjs';
  7. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  8. import { isUndefined } from '../../../utils/types.mjs';
  9. import { isClient } from '@vueuse/core';
  10. const __default__ = defineComponent({
  11. name: "ElAlert"
  12. });
  13. const _sfc_main = /* @__PURE__ */ defineComponent({
  14. ...__default__,
  15. props: alertProps,
  16. emits: alertEmits,
  17. setup(__props, { emit }) {
  18. const props = __props;
  19. const { Close } = TypeComponents;
  20. const slots = useSlots();
  21. const ns = useNamespace("alert");
  22. const visible = ref(isUndefined(props.showAfter));
  23. const iconComponent = computed(() => TypeComponentsMap[props.type]);
  24. const hasDesc = computed(() => !!(props.description || slots.default));
  25. const open = () => {
  26. visible.value = true;
  27. emit("open");
  28. };
  29. const close = (event) => {
  30. visible.value = false;
  31. emit("close", event);
  32. };
  33. const { onOpen, onClose } = useDelayedToggle({
  34. showAfter: toRef(props, "showAfter", 0),
  35. hideAfter: toRef(props, "hideAfter"),
  36. autoClose: toRef(props, "autoClose"),
  37. open,
  38. close
  39. });
  40. if (isClient) {
  41. onOpen();
  42. }
  43. return (_ctx, _cache) => {
  44. return openBlock(), createBlock(Transition, {
  45. name: unref(ns).b("fade"),
  46. persisted: ""
  47. }, {
  48. default: withCtx(() => [
  49. withDirectives(createElementVNode("div", {
  50. class: normalizeClass([unref(ns).b(), unref(ns).m(_ctx.type), unref(ns).is("center", _ctx.center), unref(ns).is(_ctx.effect)]),
  51. role: "alert"
  52. }, [
  53. _ctx.showIcon && (_ctx.$slots.icon || unref(iconComponent)) ? (openBlock(), createBlock(unref(ElIcon), {
  54. key: 0,
  55. class: normalizeClass([unref(ns).e("icon"), { [unref(ns).is("big")]: unref(hasDesc) }])
  56. }, {
  57. default: withCtx(() => [
  58. renderSlot(_ctx.$slots, "icon", {}, () => [
  59. (openBlock(), createBlock(resolveDynamicComponent(unref(iconComponent))))
  60. ])
  61. ]),
  62. _: 3
  63. }, 8, ["class"])) : createCommentVNode("v-if", true),
  64. createElementVNode("div", {
  65. class: normalizeClass(unref(ns).e("content"))
  66. }, [
  67. _ctx.title || _ctx.$slots.title ? (openBlock(), createElementBlock("span", {
  68. key: 0,
  69. class: normalizeClass([unref(ns).e("title"), { "with-description": unref(hasDesc) }])
  70. }, [
  71. renderSlot(_ctx.$slots, "title", {}, () => [
  72. createTextVNode(toDisplayString(_ctx.title), 1)
  73. ])
  74. ], 2)) : createCommentVNode("v-if", true),
  75. unref(hasDesc) ? (openBlock(), createElementBlock("p", {
  76. key: 1,
  77. class: normalizeClass(unref(ns).e("description"))
  78. }, [
  79. renderSlot(_ctx.$slots, "default", {}, () => [
  80. createTextVNode(toDisplayString(_ctx.description), 1)
  81. ])
  82. ], 2)) : createCommentVNode("v-if", true),
  83. _ctx.closable ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
  84. _ctx.closeText ? (openBlock(), createElementBlock("div", {
  85. key: 0,
  86. class: normalizeClass([unref(ns).e("close-btn"), unref(ns).is("customed")]),
  87. onClick: close
  88. }, toDisplayString(_ctx.closeText), 3)) : (openBlock(), createBlock(unref(ElIcon), {
  89. key: 1,
  90. class: normalizeClass(unref(ns).e("close-btn")),
  91. onClick: unref(onClose)
  92. }, {
  93. default: withCtx(() => [
  94. createVNode(unref(Close))
  95. ]),
  96. _: 1
  97. }, 8, ["class", "onClick"]))
  98. ], 64)) : createCommentVNode("v-if", true)
  99. ], 2)
  100. ], 2), [
  101. [vShow, visible.value]
  102. ])
  103. ]),
  104. _: 3
  105. }, 8, ["name"]);
  106. };
  107. }
  108. });
  109. var Alert = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "alert.vue"]]);
  110. export { Alert as default };
  111. //# sourceMappingURL=alert.mjs.map