index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use client";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import * as React from 'react';
  11. import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
  12. import classNames from 'classnames';
  13. import useMergedState from "rc-util/es/hooks/useMergedState";
  14. import omit from "rc-util/es/omit";
  15. import { useComponentConfig } from '../config-provider/context';
  16. import Popover from '../popover';
  17. import PurePanel, { Overlay } from './PurePanel';
  18. import useStyle from './style';
  19. const InternalPopconfirm = /*#__PURE__*/React.forwardRef((props, ref) => {
  20. var _a, _b;
  21. const {
  22. prefixCls: customizePrefixCls,
  23. placement = 'top',
  24. trigger = 'click',
  25. okType = 'primary',
  26. icon = /*#__PURE__*/React.createElement(ExclamationCircleFilled, null),
  27. children,
  28. overlayClassName,
  29. onOpenChange,
  30. onVisibleChange,
  31. overlayStyle,
  32. styles,
  33. classNames: popconfirmClassNames
  34. } = props,
  35. restProps = __rest(props, ["prefixCls", "placement", "trigger", "okType", "icon", "children", "overlayClassName", "onOpenChange", "onVisibleChange", "overlayStyle", "styles", "classNames"]);
  36. const {
  37. getPrefixCls,
  38. className: contextClassName,
  39. style: contextStyle,
  40. classNames: contextClassNames,
  41. styles: contextStyles
  42. } = useComponentConfig('popconfirm');
  43. const [open, setOpen] = useMergedState(false, {
  44. value: (_a = props.open) !== null && _a !== void 0 ? _a : props.visible,
  45. defaultValue: (_b = props.defaultOpen) !== null && _b !== void 0 ? _b : props.defaultVisible
  46. });
  47. const settingOpen = (value, e) => {
  48. setOpen(value, true);
  49. onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(value);
  50. onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(value, e);
  51. };
  52. const close = e => {
  53. settingOpen(false, e);
  54. };
  55. const onConfirm = e => {
  56. var _a;
  57. return (_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(this, e);
  58. };
  59. const onCancel = e => {
  60. var _a;
  61. settingOpen(false, e);
  62. (_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(this, e);
  63. };
  64. const onInternalOpenChange = (value, e) => {
  65. const {
  66. disabled = false
  67. } = props;
  68. if (disabled) {
  69. return;
  70. }
  71. settingOpen(value, e);
  72. };
  73. const prefixCls = getPrefixCls('popconfirm', customizePrefixCls);
  74. const rootClassNames = classNames(prefixCls, contextClassName, overlayClassName, contextClassNames.root, popconfirmClassNames === null || popconfirmClassNames === void 0 ? void 0 : popconfirmClassNames.root);
  75. const bodyClassNames = classNames(contextClassNames.body, popconfirmClassNames === null || popconfirmClassNames === void 0 ? void 0 : popconfirmClassNames.body);
  76. const [wrapCSSVar] = useStyle(prefixCls);
  77. return wrapCSSVar(/*#__PURE__*/React.createElement(Popover, Object.assign({}, omit(restProps, ['title']), {
  78. trigger: trigger,
  79. placement: placement,
  80. onOpenChange: onInternalOpenChange,
  81. open: open,
  82. ref: ref,
  83. classNames: {
  84. root: rootClassNames,
  85. body: bodyClassNames
  86. },
  87. styles: {
  88. root: Object.assign(Object.assign(Object.assign(Object.assign({}, contextStyles.root), contextStyle), overlayStyle), styles === null || styles === void 0 ? void 0 : styles.root),
  89. body: Object.assign(Object.assign({}, contextStyles.body), styles === null || styles === void 0 ? void 0 : styles.body)
  90. },
  91. content: /*#__PURE__*/React.createElement(Overlay, Object.assign({
  92. okType: okType,
  93. icon: icon
  94. }, props, {
  95. prefixCls: prefixCls,
  96. close: close,
  97. onConfirm: onConfirm,
  98. onCancel: onCancel
  99. })),
  100. "data-popover-inject": true
  101. }), children));
  102. });
  103. const Popconfirm = InternalPopconfirm;
  104. // We don't care debug panel
  105. /* istanbul ignore next */
  106. Popconfirm._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
  107. if (process.env.NODE_ENV !== 'production') {
  108. Popconfirm.displayName = 'Popconfirm';
  109. }
  110. export default Popconfirm;