@hi-ui/pop-confirm 4.2.4 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/lib/cjs/PopConfirm.js +16 -5
  3. package/lib/cjs/hooks/use-id/lib/esm/index.js +34 -0
  4. package/lib/cjs/hooks/use-id/node_modules/uuid/dist/esm-browser/regex.js +16 -0
  5. package/lib/cjs/hooks/use-id/node_modules/uuid/dist/esm-browser/rng.js +33 -0
  6. package/lib/cjs/hooks/use-id/node_modules/uuid/dist/esm-browser/stringify.js +41 -0
  7. package/lib/cjs/hooks/use-id/node_modules/uuid/dist/esm-browser/v4.js +33 -0
  8. package/lib/cjs/hooks/use-id/node_modules/uuid/dist/esm-browser/validate.js +19 -0
  9. package/lib/cjs/icons/index.js +1 -1
  10. package/lib/cjs/index.js +6 -3
  11. package/lib/cjs/styles/index.scss.js +1 -1
  12. package/lib/cjs/use-pop-confirm.js +11 -10
  13. package/lib/cjs/utils/container/lib/esm/index.js +58 -0
  14. package/lib/cjs/with-api.js +73 -0
  15. package/lib/esm/PopConfirm.js +17 -7
  16. package/lib/esm/hooks/use-id/lib/esm/index.js +29 -0
  17. package/lib/esm/hooks/use-id/node_modules/uuid/dist/esm-browser/regex.js +11 -0
  18. package/lib/esm/hooks/use-id/node_modules/uuid/dist/esm-browser/rng.js +27 -0
  19. package/lib/esm/hooks/use-id/node_modules/uuid/dist/esm-browser/stringify.js +36 -0
  20. package/lib/esm/hooks/use-id/node_modules/uuid/dist/esm-browser/v4.js +28 -0
  21. package/lib/esm/hooks/use-id/node_modules/uuid/dist/esm-browser/validate.js +14 -0
  22. package/lib/esm/icons/index.js +2 -2
  23. package/lib/esm/index.js +5 -1
  24. package/lib/esm/styles/index.scss.js +1 -1
  25. package/lib/esm/use-pop-confirm.js +11 -10
  26. package/lib/esm/utils/container/lib/esm/index.js +51 -0
  27. package/lib/esm/with-api.js +68 -0
  28. package/lib/types/PopConfirm.d.ts +5 -0
  29. package/lib/types/index.d.ts +6 -1
  30. package/lib/types/use-pop-confirm.d.ts +11 -1
  31. package/lib/types/with-api.d.ts +8 -0
  32. package/package.json +16 -15
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # @hi-ui/pop-confirm
2
2
 
3
+ ## 5.0.0-alpha.0
4
+
5
+ ### Major Changes
6
+
7
+ - 1b05b44a4: feat: 组件的 package.json 中的 exports 统一加上 types 配置 (5.0)
8
+
9
+ ### Minor Changes
10
+
11
+ - ceca247b4: feat(pop-confirm): PopConfirm 组件支持以 api 方式调用
12
+
13
+ ### Patch Changes
14
+
15
+ - 694fe87ce: style(pop-confirm): 新版样式修改 (5.0)
16
+ - 61d132802: build: 将 package.json 中 exports 配置中的 types 配置放在最上面 (5.0)
17
+ - c125e4c48: fix: 修复 UI 问题 (5.0)
18
+ - Updated dependencies [dfff90e7c]
19
+ - Updated dependencies [5de7a848b]
20
+ - Updated dependencies [1b05b44a4]
21
+ - Updated dependencies [67960d871]
22
+ - Updated dependencies [de7f92b26]
23
+ - Updated dependencies [8116f0304]
24
+ - Updated dependencies [9fa354f31]
25
+ - Updated dependencies [77ed66eac]
26
+ - Updated dependencies [61d132802]
27
+ - Updated dependencies [489b27cb3]
28
+ - Updated dependencies [6eac4b78b]
29
+ - Updated dependencies [bcd3d08dd]
30
+ - Updated dependencies [4fb586f6f]
31
+ - Updated dependencies [c125e4c48]
32
+ - Updated dependencies [b7ad460d8]
33
+ - @hi-ui/button@5.0.0-alpha.0
34
+ - @hi-ui/core@5.0.0-alpha.0
35
+ - @hi-ui/use-latest@5.0.0-alpha.0
36
+ - @hi-ui/use-toggle@5.0.0-alpha.0
37
+ - @hi-ui/use-uncontrolled-state@5.0.0-alpha.0
38
+ - @hi-ui/icons@5.0.0-alpha.0
39
+ - @hi-ui/popper@5.0.0-alpha.0
40
+ - @hi-ui/classname@5.0.0-alpha.0
41
+ - @hi-ui/dom-utils@5.0.0-alpha.0
42
+ - @hi-ui/env@5.0.0-alpha.0
43
+ - @hi-ui/react-utils@5.0.0-alpha.0
44
+ - @hi-ui/type-assertion@5.0.0-alpha.0
45
+
46
+ ## 4.2.5
47
+
48
+ ### Patch Changes
49
+
50
+ - [#2813](https://github.com/XiaoMi/hiui/pull/2813) [`084600ea6`](https://github.com/XiaoMi/hiui/commit/084600ea6e4fdec7efde79a3cc90d8ef45ca602f) Thanks [@xiamiao1121](https://github.com/xiamiao1121)! - fix: 修复点击按钮会触发 onCancel 问题
51
+
52
+ - Updated dependencies [[`3afbf239e`](https://github.com/XiaoMi/hiui/commit/3afbf239e816ede48d6a85cbd99b6b099b8c8eb3)]:
53
+ - @hi-ui/env@4.0.7
54
+
3
55
  ## 4.2.4
4
56
 
5
57
  ### Patch Changes
@@ -36,8 +36,10 @@ var POP_CONFIRM_PREFIX = classname.getPrefixCls('pop-confirm');
36
36
  * 气泡确认框
37
37
  */
38
38
  var PopConfirm = /*#__PURE__*/React.forwardRef(function (_a, ref) {
39
+ var _cx;
39
40
  var _a$prefixCls = _a.prefixCls,
40
41
  prefixCls = _a$prefixCls === void 0 ? POP_CONFIRM_PREFIX : _a$prefixCls,
42
+ innerRef = _a.innerRef,
41
43
  className = _a.className,
42
44
  children = _a.children,
43
45
  title = _a.title,
@@ -47,7 +49,7 @@ var PopConfirm = /*#__PURE__*/React.forwardRef(function (_a, ref) {
47
49
  cancelTextProp = _a.cancelText,
48
50
  confirmTextProp = _a.confirmText,
49
51
  footer = _a.footer,
50
- rest = tslib.__rest(_a, ["prefixCls", "role", "className", "children", "title", "content", "icon", "cancelText", "confirmText", "footer"]);
52
+ rest = tslib.__rest(_a, ["prefixCls", "innerRef", "role", "className", "children", "title", "content", "icon", "cancelText", "confirmText", "footer"]);
51
53
  var i18n = core.useLocaleContext();
52
54
  var cancelText = typeAssertion.isUndef(cancelTextProp) ? i18n.get('popConfirm.cancelText') : cancelTextProp;
53
55
  var confirmText = typeAssertion.isUndef(confirmTextProp) ? i18n.get('popConfirm.confirmText') : confirmTextProp;
@@ -56,8 +58,15 @@ var PopConfirm = /*#__PURE__*/React.forwardRef(function (_a, ref) {
56
58
  getPopperProps = _usePopConfirm.getPopperProps,
57
59
  getTriggerProps = _usePopConfirm.getTriggerProps,
58
60
  onCancel = _usePopConfirm.onCancel,
59
- onConfirm = _usePopConfirm.onConfirm;
60
- var cls = classname.cx(prefixCls, className);
61
+ onConfirm = _usePopConfirm.onConfirm,
62
+ visibleAction = _usePopConfirm.visibleAction;
63
+ React.useImperativeHandle(innerRef, function () {
64
+ return {
65
+ open: visibleAction.on,
66
+ close: visibleAction.off
67
+ };
68
+ });
69
+ var cls = classname.cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--icon-less"] = icon === null, _cx));
61
70
  var hasConfirm = confirmText !== null;
62
71
  var hasCancel = cancelText !== null;
63
72
  var hasFooter = hasConfirm || hasCancel || footer !== null;
@@ -80,17 +89,19 @@ var PopConfirm = /*#__PURE__*/React.forwardRef(function (_a, ref) {
80
89
  key: "1",
81
90
  className: prefixCls + "__btn-cancel",
82
91
  type: "default",
83
- size: "md",
92
+ appearance: "line",
93
+ size: "sm",
84
94
  onClick: onCancel
85
95
  }, cancelText)) : null, hasConfirm ? ( /*#__PURE__*/React__default["default"].createElement(Button__default["default"], {
86
96
  key: "2",
87
97
  className: prefixCls + "__btn-confirm",
88
98
  type: "primary",
89
- size: "md",
99
+ size: "sm",
90
100
  onClick: onConfirm
91
101
  }, confirmText)) : null] : footer)) : null)));
92
102
  });
93
103
  if (env.__DEV__) {
94
104
  PopConfirm.displayName = 'PopConfirm';
95
105
  }
106
+ exports.POP_CONFIRM_PREFIX = POP_CONFIRM_PREFIX;
96
107
  exports.PopConfirm = PopConfirm;
@@ -0,0 +1,34 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ require('react');
16
+ var v4 = require('../../node_modules/uuid/dist/esm-browser/v4.js');
17
+
18
+ /** @LICENSE
19
+ * @hi-ui/use-id
20
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-id#readme
21
+ *
22
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
23
+ *
24
+ * This source code is licensed under the MIT license found in the
25
+ * LICENSE file in the root directory of this source tree.
26
+ */
27
+
28
+ /**
29
+ * Generate a uuid.
30
+ */
31
+ var uuid = function uuid() {
32
+ return v4["default"]();
33
+ };
34
+ exports.uuid = uuid;
@@ -0,0 +1,16 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
16
+ exports["default"] = REGEX;
@@ -0,0 +1,33 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+
16
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
17
+ // require the crypto API and do not support built-in fallback to lower quality random number
18
+ // generators (like Math.random()).
19
+ var getRandomValues;
20
+ var rnds8 = new Uint8Array(16);
21
+ function rng() {
22
+ // lazy load so that environments that need to polyfill have a chance to do so
23
+ if (!getRandomValues) {
24
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
25
+ // find the complete implementation of crypto (msCrypto) on IE11.
26
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
27
+ if (!getRandomValues) {
28
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
29
+ }
30
+ }
31
+ return getRandomValues(rnds8);
32
+ }
33
+ exports["default"] = rng;
@@ -0,0 +1,41 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var validate = require('./validate.js');
16
+
17
+ /**
18
+ * Convert array of 16 byte values to UUID string format of the form:
19
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
20
+ */
21
+
22
+ var byteToHex = [];
23
+ for (var i = 0; i < 256; ++i) {
24
+ byteToHex.push((i + 0x100).toString(16).substr(1));
25
+ }
26
+ function stringify(arr) {
27
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
28
+ // Note: Be careful editing this code! It's been tuned for performance
29
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
30
+ var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
31
+ // of the following:
32
+ // - One or more input array values don't map to a hex octet (leading to
33
+ // "undefined" in the uuid)
34
+ // - Invalid input values for the RFC `version` or `variant` fields
35
+
36
+ if (!validate["default"](uuid)) {
37
+ throw TypeError('Stringified UUID is invalid');
38
+ }
39
+ return uuid;
40
+ }
41
+ exports["default"] = stringify;
@@ -0,0 +1,33 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var rng = require('./rng.js');
16
+ var stringify = require('./stringify.js');
17
+ function v4(options, buf, offset) {
18
+ options = options || {};
19
+ var rnds = options.random || (options.rng || rng["default"])(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
20
+
21
+ rnds[6] = rnds[6] & 0x0f | 0x40;
22
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
23
+
24
+ if (buf) {
25
+ offset = offset || 0;
26
+ for (var i = 0; i < 16; ++i) {
27
+ buf[offset + i] = rnds[i];
28
+ }
29
+ return buf;
30
+ }
31
+ return stringify["default"](rnds);
32
+ }
33
+ exports["default"] = v4;
@@ -0,0 +1,19 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var regex = require('./regex.js');
16
+ function validate(uuid) {
17
+ return typeof uuid === 'string' && regex["default"].test(uuid);
18
+ }
19
+ exports["default"] = validate;
@@ -21,5 +21,5 @@ function _interopDefaultCompat(e) {
21
21
  };
22
22
  }
23
23
  var React__default = /*#__PURE__*/_interopDefaultCompat(React);
24
- var defaultTipIcon = /*#__PURE__*/React__default["default"].createElement(icons.ExclamationCircleFilled, null);
24
+ var defaultTipIcon = /*#__PURE__*/React__default["default"].createElement(icons.InfoCircleFilled, null);
25
25
  exports.defaultTipIcon = defaultTipIcon;
package/lib/cjs/index.js CHANGED
@@ -13,6 +13,9 @@ Object.defineProperty(exports, '__esModule', {
13
13
  value: true
14
14
  });
15
15
  require('./styles/index.scss.js');
16
- var PopConfirm = require('./PopConfirm.js');
17
- exports.PopConfirm = PopConfirm.PopConfirm;
18
- exports["default"] = PopConfirm.PopConfirm;
16
+ var PopConfirm$1 = require('./PopConfirm.js');
17
+ var withApi = require('./with-api.js');
18
+ var PopConfirm = withApi.withPopConfirm(PopConfirm$1.PopConfirm);
19
+ exports.POP_CONFIRM_PREFIX = PopConfirm$1.POP_CONFIRM_PREFIX;
20
+ exports.PopConfirm = PopConfirm;
21
+ exports["default"] = PopConfirm;
@@ -12,7 +12,7 @@
12
12
  Object.defineProperty(exports, '__esModule', {
13
13
  value: true
14
14
  });
15
- var css_248z = ".hi-v4-pop-confirm {overflow-wrap: break-word;font-size: var(--hi-v4-text-size-md, 0.875rem);line-height: var(--hi-v4-text-lineheight-md, 1.375rem);position: relative;background: var(--hi-v4-color-static-white, #fff);white-space: nowrap;border-radius: var(--hi-v4-border-radius-lg, 6px);padding: var(--hi-v4-spacing-10, 20px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;}.hi-v4-pop-confirm__content {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;}.hi-v4-pop-confirm__content-icon {margin-right: var(--hi-v4-spacing-5, 10px);color: var(--hi-v4-color-warning-500, var(--hi-v4-color-yellow-500, #fab007));font-size: var(--hi-v4-text-size-xl, 1.125rem);}.hi-v4-pop-confirm__content-title {color: var(--hi-v4-color-gray-700, #1f2733);font-weight: var(--hi-v4-text-weight-semibold, 600);}.hi-v4-pop-confirm__body {margin: var(--hi-v4-spacing-5, 10px) 0 0 var(--hi-v4-spacing-14, 28px);white-space: normal;color: var(--hi-v4-color-gray-600, #5f6a7a);}.hi-v4-pop-confirm__footer {margin-top: var(--hi-v4-spacing-10, 20px);text-align: right;}";
15
+ var css_248z = ".hi-v5-pop-confirm {overflow-wrap: break-word;font-size: var(--hi-v5-text-size-md, 0.875rem);line-height: var(--hi-v5-text-lineheight-md, 1.375rem);position: relative;background: var(--hi-v5-color-static-white, #fff);white-space: nowrap;border: var(--hi-v5-border-size-normal, 1px solid) var(--hi-v5-color-gray-200, #e6e8eb);border-radius: var(--hi-v5-border-radius-xl, 8px);padding: var(--hi-v5-spacing-8, 16px) var(--hi-v5-spacing-10, 20px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;}.hi-v5-pop-confirm__content {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;}.hi-v5-pop-confirm__content-icon {margin-right: var(--hi-v5-spacing-4, 8px);color: var(--hi-v5-color-primary-500, var(--hi-v5-color-brandblue-500, #2660ff));font-size: var(--hi-v5-text-size-lg, 1rem);}.hi-v5-pop-confirm__content-title {color: var(--hi-v5-color-gray-700, #1a1d26);font-weight: var(--hi-v5-text-weight-semibold, 600);}.hi-v5-pop-confirm__body {margin: var(--hi-v5-spacing-2, 4px) 0 0 var(--hi-v5-spacing-12, 24px);white-space: normal;color: var(--hi-v5-color-gray-700, #1a1d26);}.hi-v5-pop-confirm--icon-less .hi-v5-pop-confirm__body {margin-left: 0;}.hi-v5-pop-confirm__footer {margin-top: var(--hi-v5-spacing-8, 16px);text-align: right;}";
16
16
  var __styleInject__ = require('@hi-ui/style-inject')["default"];
17
17
  __styleInject__(css_248z);
18
18
  exports["default"] = css_248z;
@@ -28,8 +28,9 @@ var usePopConfirm = function usePopConfirm(_a) {
28
28
  onCancelProp = _a.onCancel,
29
29
  onConfirmProp = _a.onConfirm,
30
30
  onOpen = _a.onOpen,
31
- _onClose = _a.onClose,
32
- restProps = tslib.__rest(_a, ["visible", "disabled", "closeOnCancel", "closeOnConfirm", "onCancel", "onConfirm", "onOpen", "onClose"]);
31
+ onClose = _a.onClose,
32
+ attachEl = _a.attachEl,
33
+ restProps = tslib.__rest(_a, ["visible", "disabled", "closeOnCancel", "closeOnConfirm", "onCancel", "onConfirm", "onOpen", "onClose", "attachEl"]);
33
34
  // TODO: 移除 popper,使用 hook 重写
34
35
  var _omitPopperOverlayPro = Popper.omitPopperOverlayProps(restProps),
35
36
  popper = _omitPopperOverlayPro[0],
@@ -38,18 +39,17 @@ var usePopConfirm = function usePopConfirm(_a) {
38
39
  defaultVisible: false,
39
40
  visible: visibleProp,
40
41
  onOpen: onOpen,
41
- onClose: function onClose() {
42
- _onClose === null || _onClose === void 0 ? void 0 : _onClose();
43
- onCancelProp === null || onCancelProp === void 0 ? void 0 : onCancelProp();
44
- }
42
+ onClose: onClose
45
43
  }),
46
44
  visible = _useUncontrolledToggl[0],
47
45
  visibleAction = _useUncontrolledToggl[1];
46
+ var onCancelLatest = useLatest.useLatestCallback(onCancelProp);
48
47
  var onCancel = React.useCallback(function () {
48
+ onCancelLatest();
49
49
  if (closeOnCancel) {
50
50
  visibleAction.off();
51
51
  }
52
- }, [closeOnCancel, visibleAction]);
52
+ }, [closeOnCancel, visibleAction, onCancelLatest]);
53
53
  var onConfirmLatest = useLatest.useLatestCallback(onConfirmProp);
54
54
  var onConfirm = React.useCallback(function () {
55
55
  onConfirmLatest();
@@ -75,10 +75,10 @@ var usePopConfirm = function usePopConfirm(_a) {
75
75
  });
76
76
  return Object.assign(Object.assign({}, popperProps), {
77
77
  visible: visible,
78
- attachEl: targetEl,
78
+ attachEl: attachEl !== null && attachEl !== void 0 ? attachEl : targetEl,
79
79
  onClose: visibleAction.off
80
80
  });
81
- }, [visible, targetEl, popper, visibleAction]);
81
+ }, [visible, attachEl, targetEl, popper, visibleAction]);
82
82
  var rootProps = Object.assign({
83
83
  role: 'alert-dialog'
84
84
  }, rest);
@@ -87,7 +87,8 @@ var usePopConfirm = function usePopConfirm(_a) {
87
87
  getTriggerProps: getTriggerProps,
88
88
  getPopperProps: getPopperProps,
89
89
  onCancel: onCancel,
90
- onConfirm: onConfirm
90
+ onConfirm: onConfirm,
91
+ visibleAction: visibleAction
91
92
  };
92
93
  };
93
94
  exports.usePopConfirm = usePopConfirm;
@@ -0,0 +1,58 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+
16
+ /** @LICENSE
17
+ * @hi-ui/container
18
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/container#readme
19
+ *
20
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
21
+ *
22
+ * This source code is licensed under the MIT license found in the
23
+ * LICENSE file in the root directory of this source tree.
24
+ */
25
+ /**
26
+ * 获取用于承载组件的容器,将挂载在 body 下面
27
+ *
28
+ * @param selector 以 `.` 开头的选择器类
29
+ * @returns 容器元素
30
+ */
31
+ var getContainer = function getContainer(selector, doc, customWrapper) {
32
+ if (doc === void 0) {
33
+ doc = document;
34
+ }
35
+ var rootElm = doc.querySelector(selector);
36
+ if (rootElm) return rootElm;
37
+ rootElm = doc.createElement('div');
38
+ rootElm.className = selector.slice(1);
39
+ var wrapper = customWrapper !== null && customWrapper !== void 0 ? customWrapper : doc.body;
40
+ wrapper.appendChild(rootElm);
41
+ return rootElm;
42
+ };
43
+ /**
44
+ * 从 DOM 中移除指定的承载容器
45
+ *
46
+ * @param selector 以 `.` 开头的选择器类
47
+ */
48
+ var removeContainer = function removeContainer(selector, doc) {
49
+ if (doc === void 0) {
50
+ doc = document;
51
+ }
52
+ var rootElm = doc.querySelector(selector);
53
+ if (rootElm && rootElm.parentNode) {
54
+ rootElm.parentNode.removeChild(rootElm);
55
+ }
56
+ };
57
+ exports.getContainer = getContainer;
58
+ exports.removeContainer = removeContainer;
@@ -0,0 +1,73 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var tslib = require('tslib');
16
+ var React = require('react');
17
+ var reactDom = require('react-dom');
18
+ var index$1 = require('./utils/container/lib/esm/index.js');
19
+ var index = require('./hooks/use-id/lib/esm/index.js');
20
+ var PopConfirm = require('./PopConfirm.js');
21
+ var prefixCls = PopConfirm.POP_CONFIRM_PREFIX;
22
+ var selector = "." + prefixCls + "-wrapper";
23
+ var popConfirmInstanceCache = {};
24
+ var open = function open(target, _a) {
25
+ var key = _a.key,
26
+ disabledPortal = _a.disabledPortal,
27
+ rest = tslib.__rest(_a, ["key", "disabledPortal"]);
28
+ if (!key) {
29
+ key = index.uuid();
30
+ }
31
+ var selectId = selector + "__" + key;
32
+ var container = index$1.getContainer(selectId, undefined, disabledPortal ? target.parentNode : undefined);
33
+ var popConfirmRef = /*#__PURE__*/React.createRef();
34
+ var ClonedPopConfirm = /*#__PURE__*/React.createElement(PopConfirm.PopConfirm, Object.assign({
35
+ innerRef: popConfirmRef,
36
+ container: container,
37
+ attachEl: target,
38
+ closeOnOutsideClick: false,
39
+ onExited: function onExited() {
40
+ // 卸载
41
+ if (container) {
42
+ reactDom.unmountComponentAtNode(container);
43
+ index$1.removeContainer(selectId);
44
+ }
45
+ container = undefined;
46
+ }
47
+ }, rest));
48
+ requestAnimationFrame(function () {
49
+ reactDom.render(ClonedPopConfirm, container);
50
+ popConfirmRef.current.open();
51
+ });
52
+ var close = function close() {
53
+ var _a;
54
+ (_a = popConfirmRef.current) === null || _a === void 0 ? void 0 : _a.close();
55
+ };
56
+ if (key) {
57
+ popConfirmInstanceCache[key] = close;
58
+ }
59
+ return key;
60
+ };
61
+ var close = function close(key) {
62
+ if (typeof popConfirmInstanceCache[key] === 'function') {
63
+ popConfirmInstanceCache[key]();
64
+ }
65
+ delete popConfirmInstanceCache[key];
66
+ };
67
+ function withPopConfirm(instance) {
68
+ return Object.assign(instance, {
69
+ open: open,
70
+ close: close
71
+ });
72
+ }
73
+ exports.withPopConfirm = withPopConfirm;
@@ -8,7 +8,7 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import { __rest } from 'tslib';
11
- import React, { forwardRef } from 'react';
11
+ import React, { forwardRef, useImperativeHandle } from 'react';
12
12
  import { getPrefixCls, cx } from '@hi-ui/classname';
13
13
  import { __DEV__ } from '@hi-ui/env';
14
14
  import { useLocaleContext } from '@hi-ui/core';
@@ -22,8 +22,10 @@ var POP_CONFIRM_PREFIX = getPrefixCls('pop-confirm');
22
22
  * 气泡确认框
23
23
  */
24
24
  var PopConfirm = /*#__PURE__*/forwardRef(function (_a, ref) {
25
+ var _cx;
25
26
  var _a$prefixCls = _a.prefixCls,
26
27
  prefixCls = _a$prefixCls === void 0 ? POP_CONFIRM_PREFIX : _a$prefixCls,
28
+ innerRef = _a.innerRef,
27
29
  className = _a.className,
28
30
  children = _a.children,
29
31
  title = _a.title,
@@ -33,7 +35,7 @@ var PopConfirm = /*#__PURE__*/forwardRef(function (_a, ref) {
33
35
  cancelTextProp = _a.cancelText,
34
36
  confirmTextProp = _a.confirmText,
35
37
  footer = _a.footer,
36
- rest = __rest(_a, ["prefixCls", "role", "className", "children", "title", "content", "icon", "cancelText", "confirmText", "footer"]);
38
+ rest = __rest(_a, ["prefixCls", "innerRef", "role", "className", "children", "title", "content", "icon", "cancelText", "confirmText", "footer"]);
37
39
  var i18n = useLocaleContext();
38
40
  var cancelText = isUndef(cancelTextProp) ? i18n.get('popConfirm.cancelText') : cancelTextProp;
39
41
  var confirmText = isUndef(confirmTextProp) ? i18n.get('popConfirm.confirmText') : confirmTextProp;
@@ -42,8 +44,15 @@ var PopConfirm = /*#__PURE__*/forwardRef(function (_a, ref) {
42
44
  getPopperProps = _usePopConfirm.getPopperProps,
43
45
  getTriggerProps = _usePopConfirm.getTriggerProps,
44
46
  onCancel = _usePopConfirm.onCancel,
45
- onConfirm = _usePopConfirm.onConfirm;
46
- var cls = cx(prefixCls, className);
47
+ onConfirm = _usePopConfirm.onConfirm,
48
+ visibleAction = _usePopConfirm.visibleAction;
49
+ useImperativeHandle(innerRef, function () {
50
+ return {
51
+ open: visibleAction.on,
52
+ close: visibleAction.off
53
+ };
54
+ });
55
+ var cls = cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--icon-less"] = icon === null, _cx));
47
56
  var hasConfirm = confirmText !== null;
48
57
  var hasCancel = cancelText !== null;
49
58
  var hasFooter = hasConfirm || hasCancel || footer !== null;
@@ -66,17 +75,18 @@ var PopConfirm = /*#__PURE__*/forwardRef(function (_a, ref) {
66
75
  key: "1",
67
76
  className: prefixCls + "__btn-cancel",
68
77
  type: "default",
69
- size: "md",
78
+ appearance: "line",
79
+ size: "sm",
70
80
  onClick: onCancel
71
81
  }, cancelText)) : null, hasConfirm ? ( /*#__PURE__*/React.createElement(Button, {
72
82
  key: "2",
73
83
  className: prefixCls + "__btn-confirm",
74
84
  type: "primary",
75
- size: "md",
85
+ size: "sm",
76
86
  onClick: onConfirm
77
87
  }, confirmText)) : null] : footer)) : null)));
78
88
  });
79
89
  if (__DEV__) {
80
90
  PopConfirm.displayName = 'PopConfirm';
81
91
  }
82
- export { PopConfirm };
92
+ export { POP_CONFIRM_PREFIX, PopConfirm };
@@ -0,0 +1,29 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import 'react';
11
+ import v4 from '../../node_modules/uuid/dist/esm-browser/v4.js';
12
+
13
+ /** @LICENSE
14
+ * @hi-ui/use-id
15
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-id#readme
16
+ *
17
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+
23
+ /**
24
+ * Generate a uuid.
25
+ */
26
+ var uuid = function uuid() {
27
+ return v4();
28
+ };
29
+ export { uuid };
@@ -0,0 +1,11 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
11
+ export { REGEX as default };
@@ -0,0 +1,27 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
11
+ // require the crypto API and do not support built-in fallback to lower quality random number
12
+ // generators (like Math.random()).
13
+ var getRandomValues;
14
+ var rnds8 = new Uint8Array(16);
15
+ function rng() {
16
+ // lazy load so that environments that need to polyfill have a chance to do so
17
+ if (!getRandomValues) {
18
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
19
+ // find the complete implementation of crypto (msCrypto) on IE11.
20
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
21
+ if (!getRandomValues) {
22
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
23
+ }
24
+ }
25
+ return getRandomValues(rnds8);
26
+ }
27
+ export { rng as default };
@@ -0,0 +1,36 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import validate from './validate.js';
11
+
12
+ /**
13
+ * Convert array of 16 byte values to UUID string format of the form:
14
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
15
+ */
16
+
17
+ var byteToHex = [];
18
+ for (var i = 0; i < 256; ++i) {
19
+ byteToHex.push((i + 0x100).toString(16).substr(1));
20
+ }
21
+ function stringify(arr) {
22
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
23
+ // Note: Be careful editing this code! It's been tuned for performance
24
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
25
+ var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
26
+ // of the following:
27
+ // - One or more input array values don't map to a hex octet (leading to
28
+ // "undefined" in the uuid)
29
+ // - Invalid input values for the RFC `version` or `variant` fields
30
+
31
+ if (!validate(uuid)) {
32
+ throw TypeError('Stringified UUID is invalid');
33
+ }
34
+ return uuid;
35
+ }
36
+ export { stringify as default };
@@ -0,0 +1,28 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import rng from './rng.js';
11
+ import stringify from './stringify.js';
12
+ function v4(options, buf, offset) {
13
+ options = options || {};
14
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
15
+
16
+ rnds[6] = rnds[6] & 0x0f | 0x40;
17
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
18
+
19
+ if (buf) {
20
+ offset = offset || 0;
21
+ for (var i = 0; i < 16; ++i) {
22
+ buf[offset + i] = rnds[i];
23
+ }
24
+ return buf;
25
+ }
26
+ return stringify(rnds);
27
+ }
28
+ export { v4 as default };
@@ -0,0 +1,14 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import REGEX from './regex.js';
11
+ function validate(uuid) {
12
+ return typeof uuid === 'string' && REGEX.test(uuid);
13
+ }
14
+ export { validate as default };
@@ -8,6 +8,6 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import React from 'react';
11
- import { ExclamationCircleFilled } from '@hi-ui/icons';
12
- var defaultTipIcon = /*#__PURE__*/React.createElement(ExclamationCircleFilled, null);
11
+ import { InfoCircleFilled } from '@hi-ui/icons';
12
+ var defaultTipIcon = /*#__PURE__*/React.createElement(InfoCircleFilled, null);
13
13
  export { defaultTipIcon };
package/lib/esm/index.js CHANGED
@@ -8,4 +8,8 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import './styles/index.scss.js';
11
- export { PopConfirm, PopConfirm as default } from './PopConfirm.js';
11
+ import { PopConfirm as PopConfirm$1 } from './PopConfirm.js';
12
+ export { POP_CONFIRM_PREFIX } from './PopConfirm.js';
13
+ import { withPopConfirm } from './with-api.js';
14
+ var PopConfirm = withPopConfirm(PopConfirm$1);
15
+ export { PopConfirm, PopConfirm as default };
@@ -8,6 +8,6 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import __styleInject__ from '@hi-ui/style-inject';
11
- var css_248z = ".hi-v4-pop-confirm {overflow-wrap: break-word;font-size: var(--hi-v4-text-size-md, 0.875rem);line-height: var(--hi-v4-text-lineheight-md, 1.375rem);position: relative;background: var(--hi-v4-color-static-white, #fff);white-space: nowrap;border-radius: var(--hi-v4-border-radius-lg, 6px);padding: var(--hi-v4-spacing-10, 20px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;}.hi-v4-pop-confirm__content {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;}.hi-v4-pop-confirm__content-icon {margin-right: var(--hi-v4-spacing-5, 10px);color: var(--hi-v4-color-warning-500, var(--hi-v4-color-yellow-500, #fab007));font-size: var(--hi-v4-text-size-xl, 1.125rem);}.hi-v4-pop-confirm__content-title {color: var(--hi-v4-color-gray-700, #1f2733);font-weight: var(--hi-v4-text-weight-semibold, 600);}.hi-v4-pop-confirm__body {margin: var(--hi-v4-spacing-5, 10px) 0 0 var(--hi-v4-spacing-14, 28px);white-space: normal;color: var(--hi-v4-color-gray-600, #5f6a7a);}.hi-v4-pop-confirm__footer {margin-top: var(--hi-v4-spacing-10, 20px);text-align: right;}";
11
+ var css_248z = ".hi-v5-pop-confirm {overflow-wrap: break-word;font-size: var(--hi-v5-text-size-md, 0.875rem);line-height: var(--hi-v5-text-lineheight-md, 1.375rem);position: relative;background: var(--hi-v5-color-static-white, #fff);white-space: nowrap;border: var(--hi-v5-border-size-normal, 1px solid) var(--hi-v5-color-gray-200, #e6e8eb);border-radius: var(--hi-v5-border-radius-xl, 8px);padding: var(--hi-v5-spacing-8, 16px) var(--hi-v5-spacing-10, 20px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;}.hi-v5-pop-confirm__content {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;}.hi-v5-pop-confirm__content-icon {margin-right: var(--hi-v5-spacing-4, 8px);color: var(--hi-v5-color-primary-500, var(--hi-v5-color-brandblue-500, #2660ff));font-size: var(--hi-v5-text-size-lg, 1rem);}.hi-v5-pop-confirm__content-title {color: var(--hi-v5-color-gray-700, #1a1d26);font-weight: var(--hi-v5-text-weight-semibold, 600);}.hi-v5-pop-confirm__body {margin: var(--hi-v5-spacing-2, 4px) 0 0 var(--hi-v5-spacing-12, 24px);white-space: normal;color: var(--hi-v5-color-gray-700, #1a1d26);}.hi-v5-pop-confirm--icon-less .hi-v5-pop-confirm__body {margin-left: 0;}.hi-v5-pop-confirm__footer {margin-top: var(--hi-v5-spacing-8, 16px);text-align: right;}";
12
12
  __styleInject__(css_248z);
13
13
  export { css_248z as default };
@@ -23,8 +23,9 @@ var usePopConfirm = function usePopConfirm(_a) {
23
23
  onCancelProp = _a.onCancel,
24
24
  onConfirmProp = _a.onConfirm,
25
25
  onOpen = _a.onOpen,
26
- _onClose = _a.onClose,
27
- restProps = __rest(_a, ["visible", "disabled", "closeOnCancel", "closeOnConfirm", "onCancel", "onConfirm", "onOpen", "onClose"]);
26
+ onClose = _a.onClose,
27
+ attachEl = _a.attachEl,
28
+ restProps = __rest(_a, ["visible", "disabled", "closeOnCancel", "closeOnConfirm", "onCancel", "onConfirm", "onOpen", "onClose", "attachEl"]);
28
29
  // TODO: 移除 popper,使用 hook 重写
29
30
  var _omitPopperOverlayPro = omitPopperOverlayProps(restProps),
30
31
  popper = _omitPopperOverlayPro[0],
@@ -33,18 +34,17 @@ var usePopConfirm = function usePopConfirm(_a) {
33
34
  defaultVisible: false,
34
35
  visible: visibleProp,
35
36
  onOpen: onOpen,
36
- onClose: function onClose() {
37
- _onClose === null || _onClose === void 0 ? void 0 : _onClose();
38
- onCancelProp === null || onCancelProp === void 0 ? void 0 : onCancelProp();
39
- }
37
+ onClose: onClose
40
38
  }),
41
39
  visible = _useUncontrolledToggl[0],
42
40
  visibleAction = _useUncontrolledToggl[1];
41
+ var onCancelLatest = useLatestCallback(onCancelProp);
43
42
  var onCancel = useCallback(function () {
43
+ onCancelLatest();
44
44
  if (closeOnCancel) {
45
45
  visibleAction.off();
46
46
  }
47
- }, [closeOnCancel, visibleAction]);
47
+ }, [closeOnCancel, visibleAction, onCancelLatest]);
48
48
  var onConfirmLatest = useLatestCallback(onConfirmProp);
49
49
  var onConfirm = useCallback(function () {
50
50
  onConfirmLatest();
@@ -70,10 +70,10 @@ var usePopConfirm = function usePopConfirm(_a) {
70
70
  });
71
71
  return Object.assign(Object.assign({}, popperProps), {
72
72
  visible: visible,
73
- attachEl: targetEl,
73
+ attachEl: attachEl !== null && attachEl !== void 0 ? attachEl : targetEl,
74
74
  onClose: visibleAction.off
75
75
  });
76
- }, [visible, targetEl, popper, visibleAction]);
76
+ }, [visible, attachEl, targetEl, popper, visibleAction]);
77
77
  var rootProps = Object.assign({
78
78
  role: 'alert-dialog'
79
79
  }, rest);
@@ -82,7 +82,8 @@ var usePopConfirm = function usePopConfirm(_a) {
82
82
  getTriggerProps: getTriggerProps,
83
83
  getPopperProps: getPopperProps,
84
84
  onCancel: onCancel,
85
- onConfirm: onConfirm
85
+ onConfirm: onConfirm,
86
+ visibleAction: visibleAction
86
87
  };
87
88
  };
88
89
  export { usePopConfirm };
@@ -0,0 +1,51 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ /** @LICENSE
11
+ * @hi-ui/container
12
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/container#readme
13
+ *
14
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ */
19
+ /**
20
+ * 获取用于承载组件的容器,将挂载在 body 下面
21
+ *
22
+ * @param selector 以 `.` 开头的选择器类
23
+ * @returns 容器元素
24
+ */
25
+ var getContainer = function getContainer(selector, doc, customWrapper) {
26
+ if (doc === void 0) {
27
+ doc = document;
28
+ }
29
+ var rootElm = doc.querySelector(selector);
30
+ if (rootElm) return rootElm;
31
+ rootElm = doc.createElement('div');
32
+ rootElm.className = selector.slice(1);
33
+ var wrapper = customWrapper !== null && customWrapper !== void 0 ? customWrapper : doc.body;
34
+ wrapper.appendChild(rootElm);
35
+ return rootElm;
36
+ };
37
+ /**
38
+ * 从 DOM 中移除指定的承载容器
39
+ *
40
+ * @param selector 以 `.` 开头的选择器类
41
+ */
42
+ var removeContainer = function removeContainer(selector, doc) {
43
+ if (doc === void 0) {
44
+ doc = document;
45
+ }
46
+ var rootElm = doc.querySelector(selector);
47
+ if (rootElm && rootElm.parentNode) {
48
+ rootElm.parentNode.removeChild(rootElm);
49
+ }
50
+ };
51
+ export { getContainer, removeContainer };
@@ -0,0 +1,68 @@
1
+ /** @LICENSE
2
+ * @hi-ui/pop-confirm
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/pop-confirm#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { __rest } from 'tslib';
11
+ import { createElement, createRef } from 'react';
12
+ import { unmountComponentAtNode, render } from 'react-dom';
13
+ import { getContainer, removeContainer } from './utils/container/lib/esm/index.js';
14
+ import { uuid } from './hooks/use-id/lib/esm/index.js';
15
+ import { PopConfirm, POP_CONFIRM_PREFIX } from './PopConfirm.js';
16
+ var prefixCls = POP_CONFIRM_PREFIX;
17
+ var selector = "." + prefixCls + "-wrapper";
18
+ var popConfirmInstanceCache = {};
19
+ var open = function open(target, _a) {
20
+ var key = _a.key,
21
+ disabledPortal = _a.disabledPortal,
22
+ rest = __rest(_a, ["key", "disabledPortal"]);
23
+ if (!key) {
24
+ key = uuid();
25
+ }
26
+ var selectId = selector + "__" + key;
27
+ var container = getContainer(selectId, undefined, disabledPortal ? target.parentNode : undefined);
28
+ var popConfirmRef = /*#__PURE__*/createRef();
29
+ var ClonedPopConfirm = /*#__PURE__*/createElement(PopConfirm, Object.assign({
30
+ innerRef: popConfirmRef,
31
+ container: container,
32
+ attachEl: target,
33
+ closeOnOutsideClick: false,
34
+ onExited: function onExited() {
35
+ // 卸载
36
+ if (container) {
37
+ unmountComponentAtNode(container);
38
+ removeContainer(selectId);
39
+ }
40
+ container = undefined;
41
+ }
42
+ }, rest));
43
+ requestAnimationFrame(function () {
44
+ render(ClonedPopConfirm, container);
45
+ popConfirmRef.current.open();
46
+ });
47
+ var close = function close() {
48
+ var _a;
49
+ (_a = popConfirmRef.current) === null || _a === void 0 ? void 0 : _a.close();
50
+ };
51
+ if (key) {
52
+ popConfirmInstanceCache[key] = close;
53
+ }
54
+ return key;
55
+ };
56
+ var close = function close(key) {
57
+ if (typeof popConfirmInstanceCache[key] === 'function') {
58
+ popConfirmInstanceCache[key]();
59
+ }
60
+ delete popConfirmInstanceCache[key];
61
+ };
62
+ function withPopConfirm(instance) {
63
+ return Object.assign(instance, {
64
+ open: open,
65
+ close: close
66
+ });
67
+ }
68
+ export { withPopConfirm };
@@ -1,11 +1,16 @@
1
1
  import React from 'react';
2
2
  import { HiBaseHTMLProps } from '@hi-ui/core';
3
3
  import { UsePopConfirmProps } from './use-pop-confirm';
4
+ export declare const POP_CONFIRM_PREFIX: string;
4
5
  /**
5
6
  * 气泡确认框
6
7
  */
7
8
  export declare const PopConfirm: React.ForwardRefExoticComponent<PopConfirmProps & React.RefAttributes<HTMLDivElement | null>>;
8
9
  export interface PopConfirmProps extends Omit<HiBaseHTMLProps<'div'>, 'title'>, UsePopConfirmProps {
10
+ innerRef?: React.Ref<{
11
+ open: () => void;
12
+ close: () => void;
13
+ }>;
9
14
  /**
10
15
  * 确认框标题
11
16
  */
@@ -1,3 +1,8 @@
1
+ /// <reference types="react" />
1
2
  import './styles/index.scss';
2
3
  export * from './PopConfirm';
3
- export { PopConfirm as default } from './PopConfirm';
4
+ export declare const PopConfirm: import("react").ForwardRefExoticComponent<import("./PopConfirm").PopConfirmProps & import("react").RefAttributes<HTMLDivElement | null>> & {
5
+ open: (target: HTMLElement, { key, disabledPortal, ...rest }: import("./with-api").PopConfirmApiProps) => import("react").Key;
6
+ close: (key: string) => void;
7
+ };
8
+ export default PopConfirm;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { PopperOverlayProps } from '@hi-ui/popper';
3
- export declare const usePopConfirm: ({ visible: visibleProp, disabled, closeOnCancel, closeOnConfirm, onCancel: onCancelProp, onConfirm: onConfirmProp, onOpen, onClose, ...restProps }: UsePopConfirmProps) => {
3
+ export declare const usePopConfirm: ({ visible: visibleProp, disabled, closeOnCancel, closeOnConfirm, onCancel: onCancelProp, onConfirm: onConfirmProp, onOpen, onClose, attachEl, ...restProps }: UsePopConfirmProps) => {
4
4
  rootProps: any;
5
5
  getTriggerProps: (props: any, ref: any) => {
6
6
  ref: ((value: HTMLElement | ((prevState: HTMLElement | null) => HTMLElement | null)) => void) | null;
@@ -16,6 +16,12 @@ export declare const usePopConfirm: ({ visible: visibleProp, disabled, closeOnCa
16
16
  };
17
17
  onCancel: () => void;
18
18
  onConfirm: () => void;
19
+ visibleAction: {
20
+ set: (stateOrFunction: import("react").SetStateAction<boolean>, ...args: any[]) => void;
21
+ on: () => void;
22
+ off: () => void;
23
+ not: () => void;
24
+ };
19
25
  };
20
26
  export interface UsePopConfirmProps extends PopperOverlayProps {
21
27
  /**
@@ -52,6 +58,10 @@ export interface UsePopConfirmProps extends PopperOverlayProps {
52
58
  * 设置基于 reference 元素的间隙偏移量
53
59
  */
54
60
  gutterGap?: number;
61
+ /**
62
+ * 吸附的元素
63
+ */
64
+ attachEl?: HTMLElement;
55
65
  /**
56
66
  * 是否开启禁用。暂不对外暴露
57
67
  * @private
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { PopConfirm, PopConfirmProps } from './PopConfirm';
3
+ export interface PopConfirmApiProps extends PopConfirmProps {
4
+ }
5
+ export declare function withPopConfirm(instance: typeof PopConfirm): import("react").ForwardRefExoticComponent<PopConfirmProps & import("react").RefAttributes<HTMLDivElement | null>> & {
6
+ open: (target: HTMLElement, { key, disabledPortal, ...rest }: PopConfirmApiProps) => import("react").Key;
7
+ close: (key: string) => void;
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/pop-confirm",
3
- "version": "4.2.4",
3
+ "version": "5.0.0-alpha.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -19,6 +19,7 @@
19
19
  "typings": "lib/types/index.d.ts",
20
20
  "exports": {
21
21
  ".": {
22
+ "types": "./lib/types/index.d.ts",
22
23
  "require": "./lib/cjs/index.js",
23
24
  "default": "./lib/esm/index.js"
24
25
  }
@@ -43,26 +44,26 @@
43
44
  "url": "https://github.com/XiaoMi/hiui/issues"
44
45
  },
45
46
  "dependencies": {
46
- "@hi-ui/button": "^4.0.10",
47
- "@hi-ui/classname": "^4.0.5",
48
- "@hi-ui/dom-utils": "^4.0.7",
49
- "@hi-ui/env": "^4.0.5",
50
- "@hi-ui/icons": "^4.0.19",
51
- "@hi-ui/popper": "^4.1.5",
52
- "@hi-ui/react-utils": "^4.0.4",
53
- "@hi-ui/type-assertion": "^4.0.4",
54
- "@hi-ui/use-latest": "^4.0.4",
55
- "@hi-ui/use-toggle": "^4.0.4",
56
- "@hi-ui/use-uncontrolled-state": "^4.0.4"
47
+ "@hi-ui/button": "^5.0.0-alpha.0",
48
+ "@hi-ui/classname": "^5.0.0-alpha.0",
49
+ "@hi-ui/dom-utils": "^5.0.0-alpha.0",
50
+ "@hi-ui/env": "^5.0.0-alpha.0",
51
+ "@hi-ui/icons": "^5.0.0-alpha.0",
52
+ "@hi-ui/popper": "^5.0.0-alpha.0",
53
+ "@hi-ui/react-utils": "^5.0.0-alpha.0",
54
+ "@hi-ui/type-assertion": "^5.0.0-alpha.0",
55
+ "@hi-ui/use-latest": "^5.0.0-alpha.0",
56
+ "@hi-ui/use-toggle": "^5.0.0-alpha.0",
57
+ "@hi-ui/use-uncontrolled-state": "^5.0.0-alpha.0"
57
58
  },
58
59
  "peerDependencies": {
59
- "@hi-ui/core": ">=4.0.8",
60
+ "@hi-ui/core": ">=5.0.0-alpha.0",
60
61
  "react": ">=16.8.6",
61
62
  "react-dom": ">=16.8.6"
62
63
  },
63
64
  "devDependencies": {
64
- "@hi-ui/core": "^4.0.8",
65
- "@hi-ui/core-css": "^4.1.5",
65
+ "@hi-ui/core": "^5.0.0-alpha.0",
66
+ "@hi-ui/core-css": "^5.0.0-alpha.0",
66
67
  "react": "^17.0.1",
67
68
  "react-dom": "^17.0.1"
68
69
  }