@arcblock/ux 2.9.25 → 2.9.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  import PropTypes from 'prop-types';
2
+ import { useMemoizedFn } from 'ahooks';
2
3
  import Button from '../Button';
3
4
  import Dialog from './dialog';
4
5
 
@@ -29,6 +30,7 @@ export default function Confirm({
29
30
  children,
30
31
  onConfirm,
31
32
  onCancel,
33
+ showCloseButton,
32
34
  showCancelButton,
33
35
  confirmButton,
34
36
  cancelButton,
@@ -39,11 +41,18 @@ export default function Confirm({
39
41
  PaperProps.style = Object.assign({
40
42
  minHeight: 0
41
43
  }, PaperProps.style);
44
+ const handleClose = useMemoizedFn((e, reason) => {
45
+ if (['backdropClick', 'escapeKeyDown'].includes(reason)) {
46
+ return;
47
+ }
48
+ onCancel();
49
+ });
42
50
  return /*#__PURE__*/_jsx(Dialog, {
43
51
  title: title,
44
52
  PaperProps: PaperProps,
45
53
  ...rest,
46
- onClose: () => onCancel(),
54
+ onClose: handleClose,
55
+ showCloseButton: showCloseButton,
47
56
  slotProps: {
48
57
  header: {
49
58
  sx: {
@@ -60,7 +69,7 @@ export default function Confirm({
60
69
  },
61
70
  actions: /*#__PURE__*/_jsxs(_Fragment, {
62
71
  children: [showCancelButton && /*#__PURE__*/_jsx(Button, {
63
- onClick: () => onCancel(),
72
+ onClick: e => onCancel(e, 'closeButton'),
64
73
  color: "primary",
65
74
  ...cancelButton.props,
66
75
  children: cancelButton.text
@@ -81,6 +90,7 @@ Confirm.propTypes = {
81
90
  onConfirm: PropTypes.func.isRequired,
82
91
  onCancel: PropTypes.func.isRequired,
83
92
  showCancelButton: PropTypes.bool,
93
+ showCloseButton: PropTypes.bool,
84
94
  // 可以传入 {text: ..., props: ...}
85
95
  confirmButton: PropTypes.shape({
86
96
  text: PropTypes.string.isRequired,
@@ -93,6 +103,7 @@ Confirm.propTypes = {
93
103
  PaperProps: PropTypes.object
94
104
  };
95
105
  Confirm.defaultProps = {
106
+ showCloseButton: true,
96
107
  showCancelButton: true,
97
108
  confirmButton: {
98
109
  text: 'Confirm'
@@ -13,6 +13,8 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
13
13
  onConfirm: noop,
14
14
  onCancel: noop,
15
15
  loading: false,
16
+ showCancelButton: true,
17
+ showCloseButton: true,
16
18
  confirmButtonText: 'Confirm',
17
19
  cancelButtonText: 'Cancel'
18
20
  });
@@ -21,6 +23,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
21
23
  setContent(params.content);
22
24
  state.onConfirm = params.onConfirm || noop;
23
25
  state.onCancel = params.onCancel || noop;
26
+ state.showCloseButton = params.showCloseButton ?? true;
24
27
  state.showCancelButton = params.showCancelButton ?? true;
25
28
  if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
26
29
  if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
@@ -73,6 +76,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
73
76
  loading: state.loading
74
77
  }
75
78
  },
79
+ showCloseButton: state.showCloseButton,
76
80
  showCancelButton: state.showCancelButton,
77
81
  cancelButton: {
78
82
  text: state.cancelButtonText,
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = Confirm;
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _ahooks = require("ahooks");
8
9
  var _Button = _interopRequireDefault(require("../Button"));
9
10
  var _dialog = _interopRequireDefault(require("./dialog"));
10
11
  var _jsxRuntime = require("react/jsx-runtime");
11
- const _excluded = ["title", "children", "onConfirm", "onCancel", "showCancelButton", "confirmButton", "cancelButton", "PaperProps"];
12
+ const _excluded = ["title", "children", "onConfirm", "onCancel", "showCloseButton", "showCancelButton", "confirmButton", "cancelButton", "PaperProps"];
12
13
  /**
13
14
  @typedef {Object} ConfirmProps
14
15
  @property {boolean} open
@@ -41,6 +42,7 @@ function Confirm(_ref) {
41
42
  children,
42
43
  onConfirm,
43
44
  onCancel,
45
+ showCloseButton,
44
46
  showCancelButton,
45
47
  confirmButton,
46
48
  cancelButton,
@@ -51,11 +53,18 @@ function Confirm(_ref) {
51
53
  PaperProps.style = Object.assign({
52
54
  minHeight: 0
53
55
  }, PaperProps.style);
56
+ const handleClose = (0, _ahooks.useMemoizedFn)((e, reason) => {
57
+ if (['backdropClick', 'escapeKeyDown'].includes(reason)) {
58
+ return;
59
+ }
60
+ onCancel();
61
+ });
54
62
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dialog.default, _objectSpread(_objectSpread({
55
63
  title: title,
56
64
  PaperProps: PaperProps
57
65
  }, rest), {}, {
58
- onClose: () => onCancel(),
66
+ onClose: handleClose,
67
+ showCloseButton: showCloseButton,
59
68
  slotProps: {
60
69
  header: {
61
70
  sx: {
@@ -72,7 +81,7 @@ function Confirm(_ref) {
72
81
  },
73
82
  actions: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
74
83
  children: [showCancelButton && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread(_objectSpread({
75
- onClick: () => onCancel(),
84
+ onClick: e => onCancel(e, 'closeButton'),
76
85
  color: "primary"
77
86
  }, cancelButton.props), {}, {
78
87
  children: cancelButton.text
@@ -93,6 +102,7 @@ Confirm.propTypes = {
93
102
  onConfirm: _propTypes.default.func.isRequired,
94
103
  onCancel: _propTypes.default.func.isRequired,
95
104
  showCancelButton: _propTypes.default.bool,
105
+ showCloseButton: _propTypes.default.bool,
96
106
  // 可以传入 {text: ..., props: ...}
97
107
  confirmButton: _propTypes.default.shape({
98
108
  text: _propTypes.default.string.isRequired,
@@ -105,6 +115,7 @@ Confirm.propTypes = {
105
115
  PaperProps: _propTypes.default.object
106
116
  };
107
117
  Confirm.defaultProps = {
118
+ showCloseButton: true,
108
119
  showCancelButton: true,
109
120
  confirmButton: {
110
121
  text: 'Confirm'
@@ -25,16 +25,19 @@ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
25
25
  onConfirm: _noop.default,
26
26
  onCancel: _noop.default,
27
27
  loading: false,
28
+ showCancelButton: true,
29
+ showCloseButton: true,
28
30
  confirmButtonText: 'Confirm',
29
31
  cancelButtonText: 'Cancel'
30
32
  });
31
33
  const open = (0, _ahooks.useMemoizedFn)(function () {
32
- var _params$showCancelBut;
34
+ var _params$showCloseButt, _params$showCancelBut;
33
35
  let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
34
36
  setTitle(params.title);
35
37
  setContent(params.content);
36
38
  state.onConfirm = params.onConfirm || _noop.default;
37
39
  state.onCancel = params.onCancel || _noop.default;
40
+ state.showCloseButton = (_params$showCloseButt = params.showCloseButton) !== null && _params$showCloseButt !== void 0 ? _params$showCloseButt : true;
38
41
  state.showCancelButton = (_params$showCancelBut = params.showCancelButton) !== null && _params$showCancelBut !== void 0 ? _params$showCancelBut : true;
39
42
  if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
40
43
  if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
@@ -86,6 +89,7 @@ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
86
89
  loading: state.loading
87
90
  }
88
91
  },
92
+ showCloseButton: state.showCloseButton,
89
93
  showCancelButton: state.showCancelButton,
90
94
  cancelButton: {
91
95
  text: state.cancelButtonText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.9.25",
3
+ "version": "2.9.26",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -352,12 +352,12 @@
352
352
  "peerDependencies": {
353
353
  "react": ">=18.1.0"
354
354
  },
355
- "gitHead": "a55d6db8fb2b95082cbd879ed5469543a2c0835f",
355
+ "gitHead": "25042d0a9507aa5db30cfb95a802ec6283135176",
356
356
  "dependencies": {
357
357
  "@arcblock/did-motif": "^1.1.13",
358
- "@arcblock/icons": "^2.9.25",
359
- "@arcblock/nft-display": "^2.9.25",
360
- "@arcblock/react-hooks": "^2.9.25",
358
+ "@arcblock/icons": "^2.9.26",
359
+ "@arcblock/nft-display": "^2.9.26",
360
+ "@arcblock/react-hooks": "^2.9.26",
361
361
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
362
362
  "@emotion/react": "^11.10.4",
363
363
  "@emotion/styled": "^11.10.4",
@@ -1,4 +1,5 @@
1
1
  import PropTypes from 'prop-types';
2
+ import { useMemoizedFn } from 'ahooks';
2
3
 
3
4
  import Button from '../Button';
4
5
  import Dialog from './dialog';
@@ -27,6 +28,7 @@ export default function Confirm({
27
28
  children,
28
29
  onConfirm,
29
30
  onCancel,
31
+ showCloseButton,
30
32
  showCancelButton,
31
33
  confirmButton,
32
34
  cancelButton,
@@ -41,12 +43,20 @@ export default function Confirm({
41
43
  PaperProps.style
42
44
  );
43
45
 
46
+ const handleClose = useMemoizedFn((e, reason) => {
47
+ if (['backdropClick', 'escapeKeyDown'].includes(reason)) {
48
+ return;
49
+ }
50
+ onCancel();
51
+ });
52
+
44
53
  return (
45
54
  <Dialog
46
55
  title={title}
47
56
  PaperProps={PaperProps}
48
57
  {...rest}
49
- onClose={() => onCancel()}
58
+ onClose={handleClose}
59
+ showCloseButton={showCloseButton}
50
60
  slotProps={{
51
61
  header: {
52
62
  sx: {
@@ -62,7 +72,7 @@ export default function Confirm({
62
72
  actions={
63
73
  <>
64
74
  {showCancelButton && (
65
- <Button onClick={() => onCancel()} color="primary" {...cancelButton.props}>
75
+ <Button onClick={(e) => onCancel(e, 'closeButton')} color="primary" {...cancelButton.props}>
66
76
  {cancelButton.text}
67
77
  </Button>
68
78
  )}
@@ -82,6 +92,7 @@ Confirm.propTypes = {
82
92
  onConfirm: PropTypes.func.isRequired,
83
93
  onCancel: PropTypes.func.isRequired,
84
94
  showCancelButton: PropTypes.bool,
95
+ showCloseButton: PropTypes.bool,
85
96
  // 可以传入 {text: ..., props: ...}
86
97
  confirmButton: PropTypes.shape({
87
98
  text: PropTypes.string.isRequired,
@@ -95,6 +106,7 @@ Confirm.propTypes = {
95
106
  };
96
107
 
97
108
  Confirm.defaultProps = {
109
+ showCloseButton: true,
98
110
  showCancelButton: true,
99
111
  confirmButton: {
100
112
  text: 'Confirm',
@@ -14,6 +14,8 @@ const ConfirmHolder = forwardRef((props, ref) => {
14
14
  onConfirm: noop,
15
15
  onCancel: noop,
16
16
  loading: false,
17
+ showCancelButton: true,
18
+ showCloseButton: true,
17
19
  confirmButtonText: 'Confirm',
18
20
  cancelButtonText: 'Cancel',
19
21
  });
@@ -22,6 +24,7 @@ const ConfirmHolder = forwardRef((props, ref) => {
22
24
  setContent(params.content);
23
25
  state.onConfirm = params.onConfirm || noop;
24
26
  state.onCancel = params.onCancel || noop;
27
+ state.showCloseButton = params.showCloseButton ?? true;
25
28
  state.showCancelButton = params.showCancelButton ?? true;
26
29
  if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
27
30
  if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
@@ -81,6 +84,7 @@ const ConfirmHolder = forwardRef((props, ref) => {
81
84
  loading: state.loading,
82
85
  },
83
86
  }}
87
+ showCloseButton={state.showCloseButton}
84
88
  showCancelButton={state.showCancelButton}
85
89
  cancelButton={{
86
90
  text: state.cancelButtonText,