2015-09-21 16:23:51 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-09-21 16:23:51 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var React = require("react");
|
|
|
|
|
2015-11-30 14:11:04 +00:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'QuestionDialog',
|
2015-09-21 16:23:51 +00:00
|
|
|
propTypes: {
|
|
|
|
title: React.PropTypes.string,
|
2016-03-18 11:20:00 +00:00
|
|
|
description: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.element,
|
|
|
|
React.PropTypes.string,
|
|
|
|
]),
|
2015-09-21 16:23:51 +00:00
|
|
|
button: React.PropTypes.string,
|
|
|
|
focus: React.PropTypes.bool,
|
|
|
|
onFinished: React.PropTypes.func.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
title: "",
|
|
|
|
description: "",
|
|
|
|
button: "OK",
|
|
|
|
focus: true,
|
|
|
|
};
|
|
|
|
},
|
2015-11-30 14:11:04 +00:00
|
|
|
|
|
|
|
onOk: function() {
|
|
|
|
this.props.onFinished(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
onCancel: function() {
|
|
|
|
this.props.onFinished(false);
|
|
|
|
},
|
|
|
|
|
2016-09-16 01:26:17 +00:00
|
|
|
onKeyDown: function(e) {
|
|
|
|
if (e.keyCode === 27) { // escape
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onFinished(false);
|
|
|
|
}
|
|
|
|
else if (e.keyCode === 13) { // enter
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onFinished(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 14:11:04 +00:00
|
|
|
render: function() {
|
|
|
|
return (
|
2016-09-16 01:26:17 +00:00
|
|
|
<div className="mx_QuestionDialog" onKeyDown={ this.onKeyDown }>
|
2016-01-13 15:32:41 +00:00
|
|
|
<div className="mx_Dialog_title">
|
2015-11-30 14:11:04 +00:00
|
|
|
{this.props.title}
|
|
|
|
</div>
|
|
|
|
<div className="mx_Dialog_content">
|
|
|
|
{this.props.description}
|
|
|
|
</div>
|
|
|
|
<div className="mx_Dialog_buttons">
|
2016-07-15 10:23:58 +00:00
|
|
|
<button className="mx_Dialog_primary" onClick={this.onOk} autoFocus={this.props.focus}>
|
2015-11-30 14:11:04 +00:00
|
|
|
{this.props.button}
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button onClick={this.onCancel}>
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|