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