alert2.mjs 4.3 KB

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