@stellar-expert/ui-framework 1.13.8 → 1.14.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.
- package/index.js +2 -0
- package/interaction/dialog.js +28 -0
- package/interaction/dialog.scss +35 -0
- package/interaction/system-dialog.js +65 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -50,6 +50,8 @@ export * from './interaction/theme-selector'
|
|
|
50
50
|
export * from './interaction/inline-progress'
|
|
51
51
|
export * from './interaction/responsive'
|
|
52
52
|
export * from './interaction/qr-code'
|
|
53
|
+
export * from './interaction/dialog'
|
|
54
|
+
export * from './interaction/system-dialog'
|
|
53
55
|
//date components
|
|
54
56
|
export * from './date/utc-timestamp'
|
|
55
57
|
export * from './date/elapsed-time'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import './dialog.scss'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Modal dialog
|
|
7
|
+
* @param {boolean} dialogOpen - Whether a dialog is shown
|
|
8
|
+
* @param {*} children - Dialog content
|
|
9
|
+
* @return {JSX.Element|null}
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
export const Dialog = React.memo(function Dialog({dialogOpen, children}) {
|
|
13
|
+
if (!dialogOpen)
|
|
14
|
+
return null
|
|
15
|
+
return <div className="dialog">
|
|
16
|
+
<div className="dialog-backdrop"/>
|
|
17
|
+
<div className="dialog-content container">
|
|
18
|
+
<div className="container">
|
|
19
|
+
{children}
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
Dialog.propTypes = {
|
|
26
|
+
dialogOpen: PropTypes.bool,
|
|
27
|
+
children: PropTypes.any
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.dialog {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
right: 0;
|
|
6
|
+
bottom: 0;
|
|
7
|
+
z-index: 1000;
|
|
8
|
+
overscroll-behavior: contain;
|
|
9
|
+
|
|
10
|
+
> .dialog-backdrop {
|
|
11
|
+
position: absolute;
|
|
12
|
+
top: 0;
|
|
13
|
+
left: 0;
|
|
14
|
+
right: 0;
|
|
15
|
+
bottom: 0;
|
|
16
|
+
background: var(--color-modal-bg);
|
|
17
|
+
backdrop-filter: blur(2px);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
> .dialog-content {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
height: 100%;
|
|
25
|
+
|
|
26
|
+
> .container {
|
|
27
|
+
background: var(--color-bg);
|
|
28
|
+
border: 1px solid var(--color-contrast-border);
|
|
29
|
+
border-radius: $border-radius-input;
|
|
30
|
+
box-shadow: 0 2px 4px 0 var(--color-modal-bg);
|
|
31
|
+
padding: $space-micro $space-standard $space-standard;
|
|
32
|
+
max-width: 32em;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, {useEffect, useState} from 'react'
|
|
2
|
+
import {Button} from '../controls/button'
|
|
3
|
+
import {Dialog} from './dialog'
|
|
4
|
+
|
|
5
|
+
const defaultConfirmCaption = 'Confirm'
|
|
6
|
+
const defaultCancelCaption = 'Cancel'
|
|
7
|
+
|
|
8
|
+
const defaultAlertTitle = 'Info'
|
|
9
|
+
const defaultConfirmTitle = 'Confirmation'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Replaces the built-in alert() and confirm() dialogs with prettier versions
|
|
13
|
+
* @return {JSX.Element|null}
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
export const SystemDialog = React.memo(function SystemDialog() {
|
|
17
|
+
const [buttons, setButtons] = useState([])
|
|
18
|
+
const [content, setContent] = useState()
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
window.alert = function (content, options = {title: defaultAlertTitle, icon: 'info'}) {
|
|
22
|
+
setContent(<>
|
|
23
|
+
<h2>
|
|
24
|
+
<i className={'inline-block icon-' + (options.icon || 'info')} style={{marginLeft: '-0.2em'}}/>{' '}
|
|
25
|
+
{options.title || defaultAlertTitle}
|
|
26
|
+
</h2>
|
|
27
|
+
<div className="space">{content}</div>
|
|
28
|
+
</>)
|
|
29
|
+
setButtons([null, <Button block autoFocus onClick={() => setContent(undefined)}>Ok</Button>])
|
|
30
|
+
}
|
|
31
|
+
window.confirm = function (content, options = {
|
|
32
|
+
title: defaultConfirmTitle,
|
|
33
|
+
icon: 'help',
|
|
34
|
+
confirmTitle: defaultConfirmCaption,
|
|
35
|
+
cancelTitle: defaultCancelCaption
|
|
36
|
+
}) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
function setResult(result) {
|
|
39
|
+
setContent(undefined)
|
|
40
|
+
resolve(result)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setContent(<>
|
|
44
|
+
<h2>
|
|
45
|
+
<i className={'inline-block icon-' + (options.icon || 'help')} style={{marginLeft: '-0.2em'}}/>{' '}
|
|
46
|
+
{options.title || defaultConfirmTitle}</h2>
|
|
47
|
+
<div className="space">{content}</div>
|
|
48
|
+
</>)
|
|
49
|
+
setButtons([
|
|
50
|
+
<Button block autoFocus onClick={() => setResult(true)}>{options.confirmTitle || defaultConfirmCaption}</Button>,
|
|
51
|
+
<Button block outline onClick={() => setResult(false)}>{options.cancelTitle || defaultCancelCaption}</Button>
|
|
52
|
+
])
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}, [])
|
|
56
|
+
if (!content)
|
|
57
|
+
return null
|
|
58
|
+
return <Dialog dialogOpen>
|
|
59
|
+
<div style={{minHeight: '6em'}}>{content}</div>
|
|
60
|
+
<hr/>
|
|
61
|
+
<div className="row space">
|
|
62
|
+
{buttons.map((button, index) => <div key={index} className="column column-50">{button}</div>)}
|
|
63
|
+
</div>
|
|
64
|
+
</Dialog>
|
|
65
|
+
})
|