@arcblock/ux 2.10.52 → 2.10.54

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
2
+ import { forwardRef, isValidElement, useImperativeHandle, useRef, useState } from 'react';
3
3
  import { useMemoizedFn, useReactive } from 'ahooks';
4
4
  import noop from 'lodash/noop';
5
5
  import Confirm from './confirm';
@@ -10,33 +10,56 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
10
10
  const [content, setContent] = useState('');
11
11
  const state = useReactive({
12
12
  show: false,
13
+ title: '',
14
+ content: '',
13
15
  onConfirm: noop,
14
16
  onCancel: noop,
17
+ // 其他属性
15
18
  loading: false,
16
19
  showCancelButton: true,
17
20
  showCloseButton: true,
18
21
  confirmButtonText: 'Confirm',
19
- cancelButtonText: 'Cancel'
22
+ confirmButtonProps: {},
23
+ cancelButtonText: 'Cancel',
24
+ cancelButtonProps: {}
20
25
  });
21
26
  const open = useMemoizedFn((params = {}) => {
22
- setTitle(params.title);
23
- setContent(params.content);
27
+ if (/*#__PURE__*/isValidElement(params.title)) {
28
+ setTitle(params.title);
29
+ state.title = '';
30
+ } else {
31
+ setTitle('');
32
+ state.title = params.title;
33
+ }
34
+ if (/*#__PURE__*/isValidElement(params.content)) {
35
+ setContent(params.content);
36
+ state.content = '';
37
+ } else {
38
+ setContent('');
39
+ state.content = params.content;
40
+ }
24
41
  state.onConfirm = params.onConfirm || noop;
25
42
  state.onCancel = params.onCancel || noop;
26
43
  state.showCloseButton = params.showCloseButton ?? true;
27
44
  state.showCancelButton = params.showCancelButton ?? true;
28
45
  if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
46
+ if (params.confirmButtonProps) state.confirmButtonProps = params.confirmButtonProps;
29
47
  if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
48
+ if (params.cancelButtonProps) state.cancelButtonProps = params.cancelButtonProps;
30
49
  state.loading = false;
31
50
  state.show = true;
32
51
  });
33
52
  const reset = useMemoizedFn(() => {
34
53
  setTitle('');
35
54
  setContent('');
55
+ state.title = '';
56
+ state.content = '';
36
57
  state.onConfirm = noop;
37
58
  state.onCancel = noop;
38
59
  state.confirmButtonText = 'Confirm';
60
+ state.confirmButtonProps = {};
39
61
  state.cancelButtonText = 'Cancel';
62
+ state.cancelButtonProps = {};
40
63
  });
41
64
  const close = useMemoizedFn(() => {
42
65
  state.show = false;
@@ -45,8 +68,24 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
45
68
  }, 300);
46
69
  });
47
70
  const update = useMemoizedFn(params => {
48
- if (params.title) setTitle(params.title);
49
- if (params.content) setContent(params.content);
71
+ if (params.title) {
72
+ if (/*#__PURE__*/isValidElement(params.title)) {
73
+ setTitle(params.title);
74
+ state.title = '';
75
+ } else {
76
+ setTitle('');
77
+ state.title = params.title;
78
+ }
79
+ }
80
+ if (params.content) {
81
+ if (/*#__PURE__*/isValidElement(params.content)) {
82
+ setContent(params.content);
83
+ state.content = '';
84
+ } else {
85
+ setContent('');
86
+ state.content = params.content;
87
+ }
88
+ }
50
89
  });
51
90
  const onCancel = useMemoizedFn((e, reason) => {
52
91
  close();
@@ -67,10 +106,12 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
67
106
  update
68
107
  };
69
108
  }, [open, close, update]);
109
+ const realTitle = title || state.title;
110
+ const realContent = content || state.content;
70
111
  return /*#__PURE__*/_jsx(Confirm, {
71
112
  ...props,
72
113
  open: state.show,
73
- title: title,
114
+ title: realTitle,
74
115
  onConfirm: onConfirm,
75
116
  onCancel: onCancel,
76
117
  confirmButton: {
@@ -78,7 +119,8 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
78
119
  props: {
79
120
  variant: 'contained',
80
121
  color: 'primary',
81
- loading: state.loading
122
+ loading: state.loading,
123
+ ...state.confirmButtonProps
82
124
  }
83
125
  },
84
126
  showCloseButton: state.showCloseButton,
@@ -87,10 +129,11 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
87
129
  text: state.cancelButtonText,
88
130
  props: {
89
131
  variant: 'outlined',
90
- color: 'primary'
132
+ color: 'primary',
133
+ ...state.cancelButtonProps
91
134
  }
92
135
  },
93
- children: content
136
+ children: realContent instanceof Function ? realContent() : realContent
94
137
  });
95
138
  });
96
139
  export default function useConfirm(props = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.10.52",
3
+ "version": "2.10.54",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -64,12 +64,12 @@
64
64
  "react": ">=18.2.0",
65
65
  "react-router-dom": ">=6.22.3"
66
66
  },
67
- "gitHead": "81930383a1128ca408ac99b7aaf15be422929606",
67
+ "gitHead": "7c4a184c51c647739e8d2cc8944c564b5c0d2ec0",
68
68
  "dependencies": {
69
69
  "@arcblock/did-motif": "^1.1.13",
70
- "@arcblock/icons": "^2.10.52",
71
- "@arcblock/nft-display": "^2.10.52",
72
- "@arcblock/react-hooks": "^2.10.52",
70
+ "@arcblock/icons": "^2.10.54",
71
+ "@arcblock/nft-display": "^2.10.54",
72
+ "@arcblock/react-hooks": "^2.10.54",
73
73
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
74
74
  "@fontsource/inter": "^5.0.16",
75
75
  "@fontsource/ubuntu-mono": "^5.0.18",
@@ -1,4 +1,4 @@
1
- import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
1
+ import { forwardRef, isValidElement, useImperativeHandle, useRef, useState } from 'react';
2
2
  import { useMemoizedFn, useReactive } from 'ahooks';
3
3
  import noop from 'lodash/noop';
4
4
 
@@ -11,23 +11,42 @@ const ConfirmHolder = forwardRef((props, ref) => {
11
11
  const [content, setContent] = useState('');
12
12
  const state = useReactive({
13
13
  show: false,
14
+ title: '',
15
+ content: '',
14
16
  onConfirm: noop,
15
17
  onCancel: noop,
18
+ // 其他属性
16
19
  loading: false,
17
20
  showCancelButton: true,
18
21
  showCloseButton: true,
19
22
  confirmButtonText: 'Confirm',
23
+ confirmButtonProps: {},
20
24
  cancelButtonText: 'Cancel',
25
+ cancelButtonProps: {},
21
26
  });
22
27
  const open = useMemoizedFn((params = {}) => {
23
- setTitle(params.title);
24
- setContent(params.content);
28
+ if (isValidElement(params.title)) {
29
+ setTitle(params.title);
30
+ state.title = '';
31
+ } else {
32
+ setTitle('');
33
+ state.title = params.title;
34
+ }
35
+ if (isValidElement(params.content)) {
36
+ setContent(params.content);
37
+ state.content = '';
38
+ } else {
39
+ setContent('');
40
+ state.content = params.content;
41
+ }
25
42
  state.onConfirm = params.onConfirm || noop;
26
43
  state.onCancel = params.onCancel || noop;
27
44
  state.showCloseButton = params.showCloseButton ?? true;
28
45
  state.showCancelButton = params.showCancelButton ?? true;
29
46
  if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
47
+ if (params.confirmButtonProps) state.confirmButtonProps = params.confirmButtonProps;
30
48
  if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
49
+ if (params.cancelButtonProps) state.cancelButtonProps = params.cancelButtonProps;
31
50
 
32
51
  state.loading = false;
33
52
  state.show = true;
@@ -35,10 +54,14 @@ const ConfirmHolder = forwardRef((props, ref) => {
35
54
  const reset = useMemoizedFn(() => {
36
55
  setTitle('');
37
56
  setContent('');
57
+ state.title = '';
58
+ state.content = '';
38
59
  state.onConfirm = noop;
39
60
  state.onCancel = noop;
40
61
  state.confirmButtonText = 'Confirm';
62
+ state.confirmButtonProps = {};
41
63
  state.cancelButtonText = 'Cancel';
64
+ state.cancelButtonProps = {};
42
65
  });
43
66
  const close = useMemoizedFn(() => {
44
67
  state.show = false;
@@ -47,8 +70,24 @@ const ConfirmHolder = forwardRef((props, ref) => {
47
70
  }, 300);
48
71
  });
49
72
  const update = useMemoizedFn((params) => {
50
- if (params.title) setTitle(params.title);
51
- if (params.content) setContent(params.content);
73
+ if (params.title) {
74
+ if (isValidElement(params.title)) {
75
+ setTitle(params.title);
76
+ state.title = '';
77
+ } else {
78
+ setTitle('');
79
+ state.title = params.title;
80
+ }
81
+ }
82
+ if (params.content) {
83
+ if (isValidElement(params.content)) {
84
+ setContent(params.content);
85
+ state.content = '';
86
+ } else {
87
+ setContent('');
88
+ state.content = params.content;
89
+ }
90
+ }
52
91
  });
53
92
  const onCancel = useMemoizedFn((e, reason) => {
54
93
  close();
@@ -70,11 +109,14 @@ const ConfirmHolder = forwardRef((props, ref) => {
70
109
  };
71
110
  }, [open, close, update]);
72
111
 
112
+ const realTitle = title || state.title;
113
+ const realContent = content || state.content;
114
+
73
115
  return (
74
116
  <Confirm
75
117
  {...props}
76
118
  open={state.show}
77
- title={title}
119
+ title={realTitle}
78
120
  onConfirm={onConfirm}
79
121
  onCancel={onCancel}
80
122
  confirmButton={{
@@ -83,6 +125,7 @@ const ConfirmHolder = forwardRef((props, ref) => {
83
125
  variant: 'contained',
84
126
  color: 'primary',
85
127
  loading: state.loading,
128
+ ...state.confirmButtonProps,
86
129
  },
87
130
  }}
88
131
  showCloseButton={state.showCloseButton}
@@ -92,9 +135,10 @@ const ConfirmHolder = forwardRef((props, ref) => {
92
135
  props: {
93
136
  variant: 'outlined',
94
137
  color: 'primary',
138
+ ...state.cancelButtonProps,
95
139
  },
96
140
  }}>
97
- {content}
141
+ {realContent instanceof Function ? realContent() : realContent}
98
142
  </Confirm>
99
143
  );
100
144
  });