bed8f9e7d768f7be28a4806b40b26e150f57bdcaef97f0912c80b587f750b46dcac5985d767a813ebbb8fc17461d6f99d30ff393f95497bf7d0a20dc81d525 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { defineComponent, ref, computed, unref, openBlock, createBlock, mergeProps, withCtx, createVNode, createElementVNode, normalizeClass, normalizeStyle, resolveDynamicComponent, createCommentVNode, createTextVNode, toDisplayString, renderSlot } from 'vue';
  2. import { ElButton } from '../../button/index.mjs';
  3. import { ElIcon } from '../../icon/index.mjs';
  4. import { ElTooltip } from '../../tooltip/index.mjs';
  5. import { popconfirmProps, popconfirmEmits } from './popconfirm.mjs';
  6. import ElFocusTrap from '../../focus-trap/src/focus-trap.mjs';
  7. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  8. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  9. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  10. import { addUnit } from '../../../utils/dom/style.mjs';
  11. const __default__ = defineComponent({
  12. name: "ElPopconfirm"
  13. });
  14. const _sfc_main = /* @__PURE__ */ defineComponent({
  15. ...__default__,
  16. props: popconfirmProps,
  17. emits: popconfirmEmits,
  18. setup(__props, { expose, emit }) {
  19. const props = __props;
  20. const { t } = useLocale();
  21. const ns = useNamespace("popconfirm");
  22. const tooltipRef = ref();
  23. const popperRef = computed(() => {
  24. var _a;
  25. return (_a = unref(tooltipRef)) == null ? void 0 : _a.popperRef;
  26. });
  27. const hidePopper = () => {
  28. var _a, _b;
  29. (_b = (_a = tooltipRef.value) == null ? void 0 : _a.onClose) == null ? void 0 : _b.call(_a);
  30. };
  31. const style = computed(() => {
  32. return {
  33. width: addUnit(props.width)
  34. };
  35. });
  36. const confirm = (e) => {
  37. emit("confirm", e);
  38. hidePopper();
  39. };
  40. const cancel = (e) => {
  41. emit("cancel", e);
  42. hidePopper();
  43. };
  44. const onCloseRequested = (event) => {
  45. if (props.closeOnPressEscape) {
  46. cancel(event);
  47. }
  48. };
  49. const finalConfirmButtonText = computed(() => props.confirmButtonText || t("el.popconfirm.confirmButtonText"));
  50. const finalCancelButtonText = computed(() => props.cancelButtonText || t("el.popconfirm.cancelButtonText"));
  51. expose({
  52. popperRef,
  53. hide: hidePopper
  54. });
  55. return (_ctx, _cache) => {
  56. return openBlock(), createBlock(unref(ElTooltip), mergeProps({
  57. ref_key: "tooltipRef",
  58. ref: tooltipRef,
  59. trigger: "click",
  60. effect: _ctx.effect
  61. }, _ctx.$attrs, {
  62. "popper-class": `${unref(ns).namespace.value}-popover`,
  63. "popper-style": unref(style),
  64. teleported: _ctx.teleported,
  65. "fallback-placements": ["bottom", "top", "right", "left"],
  66. "hide-after": _ctx.hideAfter,
  67. persistent: _ctx.persistent
  68. }), {
  69. content: withCtx(() => [
  70. createVNode(unref(ElFocusTrap), {
  71. loop: "",
  72. trapped: "",
  73. onReleaseRequested: onCloseRequested
  74. }, {
  75. default: withCtx(() => [
  76. createElementVNode("div", {
  77. class: normalizeClass(unref(ns).b())
  78. }, [
  79. createElementVNode("div", {
  80. class: normalizeClass(unref(ns).e("main"))
  81. }, [
  82. !_ctx.hideIcon && _ctx.icon ? (openBlock(), createBlock(unref(ElIcon), {
  83. key: 0,
  84. class: normalizeClass(unref(ns).e("icon")),
  85. style: normalizeStyle({ color: _ctx.iconColor })
  86. }, {
  87. default: withCtx(() => [
  88. (openBlock(), createBlock(resolveDynamicComponent(_ctx.icon)))
  89. ]),
  90. _: 1
  91. }, 8, ["class", "style"])) : createCommentVNode("v-if", true),
  92. createTextVNode(" " + toDisplayString(_ctx.title), 1)
  93. ], 2),
  94. createElementVNode("div", {
  95. class: normalizeClass(unref(ns).e("action"))
  96. }, [
  97. renderSlot(_ctx.$slots, "actions", {
  98. confirm,
  99. cancel
  100. }, () => [
  101. createVNode(unref(ElButton), {
  102. size: "small",
  103. type: _ctx.cancelButtonType === "text" ? "" : _ctx.cancelButtonType,
  104. text: _ctx.cancelButtonType === "text",
  105. onClick: cancel
  106. }, {
  107. default: withCtx(() => [
  108. createTextVNode(toDisplayString(unref(finalCancelButtonText)), 1)
  109. ]),
  110. _: 1
  111. }, 8, ["type", "text"]),
  112. createVNode(unref(ElButton), {
  113. size: "small",
  114. type: _ctx.confirmButtonType === "text" ? "" : _ctx.confirmButtonType,
  115. text: _ctx.confirmButtonType === "text",
  116. onClick: confirm
  117. }, {
  118. default: withCtx(() => [
  119. createTextVNode(toDisplayString(unref(finalConfirmButtonText)), 1)
  120. ]),
  121. _: 1
  122. }, 8, ["type", "text"])
  123. ])
  124. ], 2)
  125. ], 2)
  126. ]),
  127. _: 3
  128. })
  129. ]),
  130. default: withCtx(() => [
  131. _ctx.$slots.reference ? renderSlot(_ctx.$slots, "reference", { key: 0 }) : createCommentVNode("v-if", true)
  132. ]),
  133. _: 3
  134. }, 16, ["effect", "popper-class", "popper-style", "teleported", "hide-after", "persistent"]);
  135. };
  136. }
  137. });
  138. var Popconfirm = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "popconfirm.vue"]]);
  139. export { Popconfirm as default };
  140. //# sourceMappingURL=popconfirm2.mjs.map