diff --git a/src/KeyCode.js b/src/KeyCode.js
index bbe1ddcefa..c9cac01239 100644
--- a/src/KeyCode.js
+++ b/src/KeyCode.js
@@ -20,6 +20,7 @@ module.exports = {
TAB: 9,
ENTER: 13,
SHIFT: 16,
+ ESCAPE: 27,
PAGE_UP: 33,
PAGE_DOWN: 34,
END: 35,
diff --git a/src/component-index.js b/src/component-index.js
index 237af71c2f..c50ee0dfc8 100644
--- a/src/component-index.js
+++ b/src/component-index.js
@@ -71,6 +71,8 @@ import views$create_room$Presets from './components/views/create_room/Presets';
views$create_room$Presets && (module.exports.components['views.create_room.Presets'] = views$create_room$Presets);
import views$create_room$RoomAlias from './components/views/create_room/RoomAlias';
views$create_room$RoomAlias && (module.exports.components['views.create_room.RoomAlias'] = views$create_room$RoomAlias);
+import views$dialogs$BaseDialog from './components/views/dialogs/BaseDialog';
+views$dialogs$BaseDialog && (module.exports.components['views.dialogs.BaseDialog'] = views$dialogs$BaseDialog);
import views$dialogs$ChatInviteDialog from './components/views/dialogs/ChatInviteDialog';
views$dialogs$ChatInviteDialog && (module.exports.components['views.dialogs.ChatInviteDialog'] = views$dialogs$ChatInviteDialog);
import views$dialogs$DeactivateAccountDialog from './components/views/dialogs/DeactivateAccountDialog';
diff --git a/src/components/views/dialogs/BaseDialog.js b/src/components/views/dialogs/BaseDialog.js
new file mode 100644
index 0000000000..2b3980c536
--- /dev/null
+++ b/src/components/views/dialogs/BaseDialog.js
@@ -0,0 +1,72 @@
+/*
+Copyright 2017 Vector Creations Ltd
+
+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.
+*/
+
+import React from 'react';
+
+import * as KeyCode from '../../../KeyCode';
+
+/**
+ * Basic container for modal dialogs.
+ *
+ * Includes a div for the title, and a keypress handler which cancels the
+ * dialog on escape.
+ */
+export default React.createClass({
+ displayName: 'BaseDialog',
+
+ propTypes: {
+ // onFinished callback to call when Escape is pressed
+ onFinished: React.PropTypes.func.isRequired,
+
+ // callback to call when Enter is pressed
+ onEnterPressed: React.PropTypes.func,
+
+ // CSS class to apply to dialog div
+ className: React.PropTypes.string,
+
+ // Title for the dialog.
+ // (could probably actually be something more complicated than a string if desired)
+ title: React.PropTypes.string.isRequired,
+
+ // children should be the content of the dialog
+ children: React.PropTypes.node,
+ },
+
+ _onKeyDown: function(e) {
+ if (e.keyCode === KeyCode.ESCAPE) {
+ e.stopPropagation();
+ e.preventDefault();
+ this.props.onFinished();
+ } else if (e.keyCode === KeyCode.ENTER) {
+ if (this.props.onEnterPressed) {
+ e.stopPropagation();
+ e.preventDefault();
+ this.props.onEnterPressed(e);
+ }
+ }
+ },
+
+ render: function() {
+ return (
+
-
+
);
- }
+ },
});
diff --git a/src/components/views/dialogs/SetDisplayNameDialog.js b/src/components/views/dialogs/SetDisplayNameDialog.js
index 18e6b66bff..1047e05c26 100644
--- a/src/components/views/dialogs/SetDisplayNameDialog.js
+++ b/src/components/views/dialogs/SetDisplayNameDialog.js
@@ -14,17 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-var React = require("react");
-var sdk = require("../../../index.js");
-var MatrixClientPeg = require("../../../MatrixClientPeg");
-
+import React from 'react';
+import sdk from '../../../index';
+import MatrixClientPeg from '../../../MatrixClientPeg';
/**
* Prompt the user to set a display name.
*
* On success, `onFinished(true, newDisplayName)` is called.
*/
-module.exports = React.createClass({
+export default React.createClass({
displayName: 'SetDisplayNameDialog',
propTypes: {
onFinished: React.PropTypes.func.isRequired,
@@ -61,11 +60,12 @@ module.exports = React.createClass({
},
render: function() {
+ const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
return (
-
-
- Set a Display Name
-
+
Your display name is how you'll appear to others when you speak in rooms.
What would you like it to be?
@@ -81,7 +81,7 @@ module.exports = React.createClass({