index.js
6.03 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _ExclamationCircleFilled = _interopRequireDefault(require("@ant-design/icons/ExclamationCircleFilled"));
var _KeyCode = _interopRequireDefault(require("rc-util/lib/KeyCode"));
var _tooltip = _interopRequireDefault(require("../tooltip"));
var _button = _interopRequireDefault(require("../button"));
var _button2 = require("../button/button");
var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));
var _default2 = _interopRequireDefault(require("../locale/default"));
var _configProvider = require("../config-provider");
var _getRenderPropValue = require("../_util/getRenderPropValue");
var _reactNode = require("../_util/reactNode");
var _this = void 0;
var __rest = void 0 && (void 0).__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;
};
var Popconfirm = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _React$useState = React.useState(props.visible),
_React$useState2 = (0, _slicedToArray2["default"])(_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["default"].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")
}, (0, _getRenderPropValue.getRenderPropValue)(title))), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-buttons")
}, /*#__PURE__*/React.createElement(_button["default"], (0, _extends2["default"])({
onClick: onCancel,
size: "small"
}, cancelButtonProps), cancelText || popconfirmLocale.cancelText), /*#__PURE__*/React.createElement(_button["default"], (0, _extends2["default"])({
onClick: onConfirm
}, (0, _button2.convertLegacyProps)(okType), {
size: "small"
}, okButtonProps), okText || popconfirmLocale.okText)));
};
var _React$useContext = React.useContext(_configProvider.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 = (0, _classnames["default"])(prefixClsConfirm, overlayClassName);
var overlay = /*#__PURE__*/React.createElement(_LocaleReceiver["default"], {
componentName: "Popconfirm",
defaultLocale: _default2["default"].Popconfirm
}, function (popconfirmLocale) {
return renderOverlay(prefixCls, popconfirmLocale);
});
return /*#__PURE__*/React.createElement(_tooltip["default"], (0, _extends2["default"])({}, restProps, {
prefixCls: prefixCls,
placement: placement,
onVisibleChange: onVisibleChange,
visible: visible,
overlay: overlay,
overlayClassName: overlayClassNames,
ref: ref
}), (0, _reactNode.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["default"], null),
disabled: false
};
var _default = Popconfirm;
exports["default"] = _default;