alert2.mjs 4.2 KB

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