ConfirmDialog.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  2. import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
  3. import { createVNode as _createVNode } from "vue";
  4. import classNames from '../_util/classNames';
  5. import Dialog from './Modal';
  6. import ActionButton from '../_util/ActionButton';
  7. import { defineComponent } from 'vue';
  8. import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
  9. import { getTransitionName } from '../_util/transition';
  10. function renderSomeContent(someContent) {
  11. if (typeof someContent === 'function') {
  12. return someContent();
  13. }
  14. return someContent;
  15. }
  16. export default defineComponent({
  17. name: 'ConfirmDialog',
  18. inheritAttrs: false,
  19. props: ['icon', 'onCancel', 'onOk', 'close', 'closable', 'zIndex', 'afterClose', 'visible', 'keyboard', 'centered', 'getContainer', 'maskStyle', 'okButtonProps', 'cancelButtonProps', 'okType', 'prefixCls', 'okCancel', 'width', 'mask', 'maskClosable', 'okText', 'cancelText', 'autoFocusButton', 'transitionName', 'maskTransitionName', 'type', 'title', 'content', 'direction', 'rootPrefixCls', 'bodyStyle', 'closeIcon', 'modalRender', 'focusTriggerAfterClose', 'wrapClassName'],
  20. setup: function setup(props, _ref) {
  21. var attrs = _ref.attrs;
  22. var _useLocaleReceiver = useLocaleReceiver('Modal'),
  23. _useLocaleReceiver2 = _slicedToArray(_useLocaleReceiver, 1),
  24. locale = _useLocaleReceiver2[0];
  25. return function () {
  26. var icon = props.icon,
  27. onCancel = props.onCancel,
  28. onOk = props.onOk,
  29. close = props.close,
  30. _props$closable = props.closable,
  31. closable = _props$closable === void 0 ? false : _props$closable,
  32. zIndex = props.zIndex,
  33. afterClose = props.afterClose,
  34. visible = props.visible,
  35. keyboard = props.keyboard,
  36. centered = props.centered,
  37. getContainer = props.getContainer,
  38. maskStyle = props.maskStyle,
  39. okButtonProps = props.okButtonProps,
  40. cancelButtonProps = props.cancelButtonProps,
  41. _props$okCancel = props.okCancel,
  42. okCancel = _props$okCancel === void 0 ? true : _props$okCancel,
  43. _props$width = props.width,
  44. width = _props$width === void 0 ? 416 : _props$width,
  45. _props$mask = props.mask,
  46. mask = _props$mask === void 0 ? true : _props$mask,
  47. _props$maskClosable = props.maskClosable,
  48. maskClosable = _props$maskClosable === void 0 ? false : _props$maskClosable,
  49. type = props.type,
  50. title = props.title,
  51. content = props.content,
  52. direction = props.direction,
  53. closeIcon = props.closeIcon,
  54. modalRender = props.modalRender,
  55. focusTriggerAfterClose = props.focusTriggerAfterClose,
  56. rootPrefixCls = props.rootPrefixCls,
  57. bodyStyle = props.bodyStyle,
  58. wrapClassName = props.wrapClassName;
  59. var okType = props.okType || 'primary';
  60. var prefixCls = props.prefixCls || 'ant-modal';
  61. var contentPrefixCls = "".concat(prefixCls, "-confirm");
  62. var style = attrs.style || {};
  63. var okText = renderSomeContent(props.okText) || (okCancel ? locale.value.okText : locale.value.justOkText);
  64. var cancelText = renderSomeContent(props.cancelText) || locale.value.cancelText;
  65. var autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
  66. var classString = classNames(contentPrefixCls, "".concat(contentPrefixCls, "-").concat(type), "".concat(prefixCls, "-").concat(type), _defineProperty({}, "".concat(contentPrefixCls, "-rtl"), direction === 'rtl'), attrs.class);
  67. var cancelButton = okCancel && _createVNode(ActionButton, {
  68. "actionFn": onCancel,
  69. "close": close,
  70. "autofocus": autoFocusButton === 'cancel',
  71. "buttonProps": cancelButtonProps,
  72. "prefixCls": "".concat(rootPrefixCls, "-btn")
  73. }, {
  74. default: function _default() {
  75. return [cancelText];
  76. }
  77. });
  78. return _createVNode(Dialog, {
  79. "prefixCls": prefixCls,
  80. "class": classString,
  81. "wrapClassName": classNames(_defineProperty({}, "".concat(contentPrefixCls, "-centered"), !!centered), wrapClassName),
  82. "onCancel": function onCancel(e) {
  83. return close({
  84. triggerCancel: true
  85. }, e);
  86. },
  87. "visible": visible,
  88. "title": "",
  89. "footer": "",
  90. "transitionName": getTransitionName(rootPrefixCls, 'zoom', props.transitionName),
  91. "maskTransitionName": getTransitionName(rootPrefixCls, 'fade', props.maskTransitionName),
  92. "mask": mask,
  93. "maskClosable": maskClosable,
  94. "maskStyle": maskStyle,
  95. "style": style,
  96. "bodyStyle": bodyStyle,
  97. "width": width,
  98. "zIndex": zIndex,
  99. "afterClose": afterClose,
  100. "keyboard": keyboard,
  101. "centered": centered,
  102. "getContainer": getContainer,
  103. "closable": closable,
  104. "closeIcon": closeIcon,
  105. "modalRender": modalRender,
  106. "focusTriggerAfterClose": focusTriggerAfterClose
  107. }, {
  108. default: function _default() {
  109. return [_createVNode("div", {
  110. "class": "".concat(contentPrefixCls, "-body-wrapper")
  111. }, [_createVNode("div", {
  112. "class": "".concat(contentPrefixCls, "-body")
  113. }, [renderSomeContent(icon), title === undefined ? null : _createVNode("span", {
  114. "class": "".concat(contentPrefixCls, "-title")
  115. }, [renderSomeContent(title)]), _createVNode("div", {
  116. "class": "".concat(contentPrefixCls, "-content")
  117. }, [renderSomeContent(content)])]), _createVNode("div", {
  118. "class": "".concat(contentPrefixCls, "-btns")
  119. }, [cancelButton, _createVNode(ActionButton, {
  120. "type": okType,
  121. "actionFn": onOk,
  122. "close": close,
  123. "autofocus": autoFocusButton === 'ok',
  124. "buttonProps": okButtonProps,
  125. "prefixCls": "".concat(rootPrefixCls, "-btn")
  126. }, {
  127. default: function _default() {
  128. return [okText];
  129. }
  130. })])])];
  131. }
  132. });
  133. };
  134. }
  135. });