index.js
5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import _extends from "@babel/runtime/helpers/extends";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
var _this = this;
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import * as React from 'react';
import classNames from 'classnames';
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
import KeyCode from "rc-util/es/KeyCode";
import Tooltip from '../tooltip';
import Button from '../button';
import { convertLegacyProps } from '../button/button';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import { ConfigContext } from '../config-provider';
import { getRenderPropValue } from '../_util/getRenderPropValue';
import { cloneElement } from '../_util/reactNode';
var Popconfirm = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _React$useState = React.useState(props.visible),
_React$useState2 = _slicedToArray(_React$useState, 2),
visible = _React$useState2[0],
setVisible = _React$useState2[1];
React.useEffect(function () {
if ('visible' in props) {
setVisible(props.visible);
}
}, [props.visible]);
React.useEffect(function () {
if ('defaultVisible' in props) {
setVisible(props.defaultVisible);
}
}, [props.defaultVisible]);
var settingVisible = function settingVisible(value, e) {
if (!('visible' in props)) {
setVisible(value);
}
if (props.onVisibleChange) {
props.onVisibleChange(value, e);
}
};
var onConfirm = function onConfirm(e) {
settingVisible(false, e);
if (props.onConfirm) {
props.onConfirm.call(_this, e);
}
};
var onCancel = function onCancel(e) {
settingVisible(false, e);
if (props.onCancel) {
props.onCancel.call(_this, e);
}
};
var _onKeyDown = function onKeyDown(e) {
if (e.keyCode === KeyCode.ESC && visible) {
settingVisible(false, e);
}
};
var onVisibleChange = function onVisibleChange(value) {
var disabled = props.disabled;
if (disabled) {
return;
}
settingVisible(value);
};
var renderOverlay = function renderOverlay(prefixCls, popconfirmLocale) {
var okButtonProps = props.okButtonProps,
cancelButtonProps = props.cancelButtonProps,
title = props.title,
cancelText = props.cancelText,
okText = props.okText,
okType = props.okType,
icon = props.icon;
return /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-inner-content")
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-message")
}, icon, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-message-title")
}, getRenderPropValue(title))), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-buttons")
}, /*#__PURE__*/React.createElement(Button, _extends({
onClick: onCancel,
size: "small"
}, cancelButtonProps), cancelText || popconfirmLocale.cancelText), /*#__PURE__*/React.createElement(Button, _extends({
onClick: onConfirm
}, convertLegacyProps(okType), {
size: "small"
}, okButtonProps), okText || popconfirmLocale.okText)));
};
var _React$useContext = React.useContext(ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls;
var customizePrefixCls = props.prefixCls,
placement = props.placement,
children = props.children,
overlayClassName = props.overlayClassName,
restProps = __rest(props, ["prefixCls", "placement", "children", "overlayClassName"]);
var prefixCls = getPrefixCls('popover', customizePrefixCls);
var prefixClsConfirm = getPrefixCls('popconfirm', customizePrefixCls);
var overlayClassNames = classNames(prefixClsConfirm, overlayClassName);
var overlay = /*#__PURE__*/React.createElement(LocaleReceiver, {
componentName: "Popconfirm",
defaultLocale: defaultLocale.Popconfirm
}, function (popconfirmLocale) {
return renderOverlay(prefixCls, popconfirmLocale);
});
return /*#__PURE__*/React.createElement(Tooltip, _extends({}, restProps, {
prefixCls: prefixCls,
placement: placement,
onVisibleChange: onVisibleChange,
visible: visible,
overlay: overlay,
overlayClassName: overlayClassNames,
ref: ref
}), cloneElement(children, {
onKeyDown: function onKeyDown(e) {
var _a, _b;
if ( /*#__PURE__*/React.isValidElement(children)) {
(_b = children === null || children === void 0 ? void 0 : (_a = children.props).onKeyDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
}
_onKeyDown(e);
}
}));
});
Popconfirm.defaultProps = {
transitionName: 'zoom-big',
placement: 'top',
trigger: 'click',
okType: 'primary',
icon: /*#__PURE__*/React.createElement(ExclamationCircleFilled, null),
disabled: false
};
export default Popconfirm;