@stellar-expert/ui-framework 1.14.1 → 1.14.3
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.
- package/interaction/system-dialog.js +28 -2
- package/package.json +1 -1
|
@@ -19,6 +19,17 @@ export const SystemDialog = React.memo(function SystemDialog() {
|
|
|
19
19
|
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
window.alert = function (content, options = {title: defaultAlertTitle, icon: 'info'}) {
|
|
22
|
+
function close() {
|
|
23
|
+
setContent(undefined)
|
|
24
|
+
window.removeEventListener('keydown', keyHandler, true)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function keyHandler(e) {
|
|
28
|
+
if (e.keyCode === 27 || e.keyCode === 13) {
|
|
29
|
+
close()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
setContent(<>
|
|
23
34
|
<h2>
|
|
24
35
|
<i className={'inline-block icon-' + (options.icon || 'info')} style={{marginLeft: '-0.2em'}}/>{' '}
|
|
@@ -26,7 +37,8 @@ export const SystemDialog = React.memo(function SystemDialog() {
|
|
|
26
37
|
</h2>
|
|
27
38
|
<div className="space">{content}</div>
|
|
28
39
|
</>)
|
|
29
|
-
setButtons([null, <Button block autoFocus onClick={
|
|
40
|
+
setButtons([null, <Button block autoFocus onClick={close}>Ok</Button>])
|
|
41
|
+
window.addEventListener('keydown', keyHandler, true)
|
|
30
42
|
}
|
|
31
43
|
window.confirm = function (content, options = {
|
|
32
44
|
title: defaultConfirmTitle,
|
|
@@ -37,7 +49,19 @@ export const SystemDialog = React.memo(function SystemDialog() {
|
|
|
37
49
|
return new Promise((resolve, reject) => {
|
|
38
50
|
function setResult(result) {
|
|
39
51
|
setContent(undefined)
|
|
40
|
-
|
|
52
|
+
if (result)
|
|
53
|
+
resolve(true)
|
|
54
|
+
else
|
|
55
|
+
reject()
|
|
56
|
+
window.removeEventListener('keydown', keyHandler, true)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function keyHandler(e) {
|
|
60
|
+
if (e.keyCode === 27) {
|
|
61
|
+
setResult(false)
|
|
62
|
+
} else if (e.keyCode === 13) {
|
|
63
|
+
setResult(true)
|
|
64
|
+
}
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
setContent(<>
|
|
@@ -50,6 +74,8 @@ export const SystemDialog = React.memo(function SystemDialog() {
|
|
|
50
74
|
<Button block autoFocus onClick={() => setResult(true)}>{options.confirmTitle || defaultConfirmCaption}</Button>,
|
|
51
75
|
<Button block outline onClick={() => setResult(false)}>{options.cancelTitle || defaultCancelCaption}</Button>
|
|
52
76
|
])
|
|
77
|
+
|
|
78
|
+
window.addEventListener('keydown', keyHandler, true)
|
|
53
79
|
})
|
|
54
80
|
}
|
|
55
81
|
}, [])
|