forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog-view.js
90 lines (82 loc) · 3.04 KB
/
dialog-view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, {Fragment} from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Commands, {Command} from '../atom/commands';
import Panel from '../atom/panel';
import {TabbableButton} from './tabbable';
export default class DialogView extends React.Component {
static propTypes = {
// Customization
prompt: PropTypes.string,
progressMessage: PropTypes.string,
acceptEnabled: PropTypes.bool,
acceptClassName: PropTypes.string,
acceptText: PropTypes.string,
// Callbacks
accept: PropTypes.func.isRequired,
cancel: PropTypes.func.isRequired,
// State
tabGroup: PropTypes.object.isRequired,
inProgress: PropTypes.bool.isRequired,
error: PropTypes.instanceOf(Error),
// Atom environment
workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
// Form content
children: PropTypes.node.isRequired,
}
static defaultProps = {
acceptEnabled: true,
acceptText: 'Accept',
}
render() {
return (
<Panel workspace={this.props.workspace} location="modal">
<div className="github-Dialog">
<Commands registry={this.props.commands} target=".github-Dialog">
<Command command="core:confirm" callback={this.props.accept} />
<Command command="core:cancel" callback={this.props.cancel} />
</Commands>
{this.props.prompt && (
<header className="github-DialogPrompt">{this.props.prompt}</header>
)}
<main className="github-DialogForm">
{this.props.children}
</main>
<footer className="github-DialogFooter">
<div className="github-DialogInfo">
{this.props.progressMessage && this.props.inProgress && (
<Fragment>
<span className="inline-block loading loading-spinner-small" />
<span className="github-DialogProgress-message">{this.props.progressMessage}</span>
</Fragment>
)}
{this.props.error && (
<ul className="error-messages">
<li>{this.props.error.userMessage || this.props.error.message}</li>
</ul>
)}
</div>
<div className="github-DialogButtons">
<TabbableButton
tabGroup={this.props.tabGroup}
commands={this.props.commands}
className="btn github-Dialog-cancelButton"
onClick={this.props.cancel}>
Cancel
</TabbableButton>
<TabbableButton
tabGroup={this.props.tabGroup}
commands={this.props.commands}
className={cx('btn btn-primary github-Dialog-acceptButton', this.props.acceptClassName)}
onClick={this.props.accept}
disabled={this.props.inProgress || !this.props.acceptEnabled}>
{this.props.acceptText}
</TabbableButton>
</div>
</footer>
</div>
</Panel>
);
}
}