mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 14:05:04 +08:00
Merge pull request #645 from matrix-org/rav/base_dialog
Create a common BaseDialog
This commit is contained in:
commit
7343ef968e
@ -20,6 +20,7 @@ module.exports = {
|
|||||||
TAB: 9,
|
TAB: 9,
|
||||||
ENTER: 13,
|
ENTER: 13,
|
||||||
SHIFT: 16,
|
SHIFT: 16,
|
||||||
|
ESCAPE: 27,
|
||||||
PAGE_UP: 33,
|
PAGE_UP: 33,
|
||||||
PAGE_DOWN: 34,
|
PAGE_DOWN: 34,
|
||||||
END: 35,
|
END: 35,
|
||||||
|
@ -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);
|
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';
|
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);
|
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';
|
import views$dialogs$ChatInviteDialog from './components/views/dialogs/ChatInviteDialog';
|
||||||
views$dialogs$ChatInviteDialog && (module.exports.components['views.dialogs.ChatInviteDialog'] = views$dialogs$ChatInviteDialog);
|
views$dialogs$ChatInviteDialog && (module.exports.components['views.dialogs.ChatInviteDialog'] = views$dialogs$ChatInviteDialog);
|
||||||
import views$dialogs$DeactivateAccountDialog from './components/views/dialogs/DeactivateAccountDialog';
|
import views$dialogs$DeactivateAccountDialog from './components/views/dialogs/DeactivateAccountDialog';
|
||||||
|
72
src/components/views/dialogs/BaseDialog.js
Normal file
72
src/components/views/dialogs/BaseDialog.js
Normal file
@ -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 (
|
||||||
|
<div onKeyDown={this._onKeyDown} className={this.props.className}>
|
||||||
|
<div className='mx_Dialog_title'>
|
||||||
|
{ this.props.title }
|
||||||
|
</div>
|
||||||
|
{ this.props.children }
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
@ -25,9 +25,10 @@ limitations under the License.
|
|||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var React = require("react");
|
import React from 'react';
|
||||||
|
import sdk from '../../../index';
|
||||||
|
|
||||||
module.exports = React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'ErrorDialog',
|
displayName: 'ErrorDialog',
|
||||||
propTypes: {
|
propTypes: {
|
||||||
title: React.PropTypes.string,
|
title: React.PropTypes.string,
|
||||||
@ -49,20 +50,11 @@ module.exports = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
onKeyDown: function(e) {
|
|
||||||
if (e.keyCode === 27) { // escape
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
this.props.onFinished(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
return (
|
return (
|
||||||
<div className="mx_ErrorDialog" onKeyDown={ this.onKeyDown }>
|
<BaseDialog className="mx_ErrorDialog" onFinished={this.props.onFinished}
|
||||||
<div className="mx_Dialog_title">
|
title={this.props.title}>
|
||||||
{this.props.title}
|
|
||||||
</div>
|
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
{this.props.description}
|
{this.props.description}
|
||||||
</div>
|
</div>
|
||||||
@ -71,7 +63,7 @@ module.exports = React.createClass({
|
|||||||
{this.props.button}
|
{this.props.button}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
@ -111,20 +111,9 @@ export default React.createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_onKeyDown: function(e) {
|
_onEnterPressed: function(e) {
|
||||||
if (e.keyCode === 27) { // escape
|
if (this.state.submitButtonEnabled && !this.state.busy) {
|
||||||
e.stopPropagation();
|
this._onSubmit();
|
||||||
e.preventDefault();
|
|
||||||
if (!this.state.busy) {
|
|
||||||
this._onCancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (e.keyCode === 13) { // enter
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
if (this.state.submitButtonEnabled && !this.state.busy) {
|
|
||||||
this._onSubmit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -171,6 +160,7 @@ export default React.createClass({
|
|||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
const Loader = sdk.getComponent("elements.Spinner");
|
const Loader = sdk.getComponent("elements.Spinner");
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
|
|
||||||
let error = null;
|
let error = null;
|
||||||
if (this.state.errorText) {
|
if (this.state.errorText) {
|
||||||
@ -200,10 +190,11 @@ export default React.createClass({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx_InteractiveAuthDialog" onKeyDown={this._onKeyDown}>
|
<BaseDialog className="mx_InteractiveAuthDialog"
|
||||||
<div className="mx_Dialog_title">
|
onEnterPressed={this._onEnterPressed}
|
||||||
{this.props.title}
|
onFinished={this.props.onFinished}
|
||||||
</div>
|
title={this.props.title}
|
||||||
|
>
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
<p>This operation requires additional authentication.</p>
|
<p>This operation requires additional authentication.</p>
|
||||||
{this._renderCurrentStage()}
|
{this._renderCurrentStage()}
|
||||||
@ -213,7 +204,7 @@ export default React.createClass({
|
|||||||
{submitButton}
|
{submitButton}
|
||||||
{cancelButton}
|
{cancelButton}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -23,8 +23,9 @@ limitations under the License.
|
|||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var React = require("react");
|
import React from 'react';
|
||||||
var dis = require("../../../dispatcher");
|
import dis from '../../../dispatcher';
|
||||||
|
import sdk from '../../../index';
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'NeedToRegisterDialog',
|
displayName: 'NeedToRegisterDialog',
|
||||||
@ -54,11 +55,12 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
return (
|
return (
|
||||||
<div className="mx_NeedToRegisterDialog">
|
<BaseDialog className="mx_NeedToRegisterDialog"
|
||||||
<div className="mx_Dialog_title">
|
onFinished={this.props.onFinished}
|
||||||
{this.props.title}
|
title={this.props.title}
|
||||||
</div>
|
>
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
{this.props.description}
|
{this.props.description}
|
||||||
</div>
|
</div>
|
||||||
@ -70,7 +72,7 @@ module.exports = React.createClass({
|
|||||||
Register
|
Register
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var React = require("react");
|
import React from 'react';
|
||||||
|
import sdk from '../../../index';
|
||||||
|
|
||||||
module.exports = React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'QuestionDialog',
|
displayName: 'QuestionDialog',
|
||||||
propTypes: {
|
propTypes: {
|
||||||
title: React.PropTypes.string,
|
title: React.PropTypes.string,
|
||||||
@ -46,25 +47,13 @@ module.exports = React.createClass({
|
|||||||
this.props.onFinished(false);
|
this.props.onFinished(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
return (
|
return (
|
||||||
<div className="mx_QuestionDialog" onKeyDown={ this.onKeyDown }>
|
<BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished}
|
||||||
<div className="mx_Dialog_title">
|
onEnterPressed={ this.onOk }
|
||||||
{this.props.title}
|
title={this.props.title}
|
||||||
</div>
|
>
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
{this.props.description}
|
{this.props.description}
|
||||||
</div>
|
</div>
|
||||||
@ -77,7 +66,7 @@ module.exports = React.createClass({
|
|||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
@ -14,17 +14,16 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var React = require("react");
|
import React from 'react';
|
||||||
var sdk = require("../../../index.js");
|
import sdk from '../../../index';
|
||||||
var MatrixClientPeg = require("../../../MatrixClientPeg");
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompt the user to set a display name.
|
* Prompt the user to set a display name.
|
||||||
*
|
*
|
||||||
* On success, `onFinished(true, newDisplayName)` is called.
|
* On success, `onFinished(true, newDisplayName)` is called.
|
||||||
*/
|
*/
|
||||||
module.exports = React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'SetDisplayNameDialog',
|
displayName: 'SetDisplayNameDialog',
|
||||||
propTypes: {
|
propTypes: {
|
||||||
onFinished: React.PropTypes.func.isRequired,
|
onFinished: React.PropTypes.func.isRequired,
|
||||||
@ -61,11 +60,12 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
return (
|
return (
|
||||||
<div className="mx_SetDisplayNameDialog">
|
<BaseDialog className="mx_SetDisplayNameDialog"
|
||||||
<div className="mx_Dialog_title">
|
onFinished={this.props.onFinished}
|
||||||
Set a Display Name
|
title="Set a Display Name"
|
||||||
</div>
|
>
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
Your display name is how you'll appear to others when you speak in rooms.<br/>
|
Your display name is how you'll appear to others when you speak in rooms.<br/>
|
||||||
What would you like it to be?
|
What would you like it to be?
|
||||||
@ -81,7 +81,7 @@ module.exports = React.createClass({
|
|||||||
<input className="mx_Dialog_primary" type="submit" value="Set" />
|
<input className="mx_Dialog_primary" type="submit" value="Set" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var React = require("react");
|
import React from 'react';
|
||||||
|
import sdk from '../../../index';
|
||||||
|
|
||||||
module.exports = React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'TextInputDialog',
|
displayName: 'TextInputDialog',
|
||||||
propTypes: {
|
propTypes: {
|
||||||
title: React.PropTypes.string,
|
title: React.PropTypes.string,
|
||||||
@ -27,7 +28,7 @@ module.exports = React.createClass({
|
|||||||
value: React.PropTypes.string,
|
value: React.PropTypes.string,
|
||||||
button: React.PropTypes.string,
|
button: React.PropTypes.string,
|
||||||
focus: React.PropTypes.bool,
|
focus: React.PropTypes.bool,
|
||||||
onFinished: React.PropTypes.func.isRequired
|
onFinished: React.PropTypes.func.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
@ -36,7 +37,7 @@ module.exports = React.createClass({
|
|||||||
value: "",
|
value: "",
|
||||||
description: "",
|
description: "",
|
||||||
button: "OK",
|
button: "OK",
|
||||||
focus: true
|
focus: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -55,25 +56,13 @@ module.exports = React.createClass({
|
|||||||
this.props.onFinished(false);
|
this.props.onFinished(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
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, this.refs.textinput.value);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
||||||
return (
|
return (
|
||||||
<div className="mx_TextInputDialog">
|
<BaseDialog className="mx_TextInputDialog" onFinished={this.props.onFinished}
|
||||||
<div className="mx_Dialog_title">
|
onEnterPressed={this.onOk}
|
||||||
{this.props.title}
|
title={this.props.title}
|
||||||
</div>
|
>
|
||||||
<div className="mx_Dialog_content">
|
<div className="mx_Dialog_content">
|
||||||
<div className="mx_TextInputDialog_label">
|
<div className="mx_TextInputDialog_label">
|
||||||
<label htmlFor="textinput"> {this.props.description} </label>
|
<label htmlFor="textinput"> {this.props.description} </label>
|
||||||
@ -90,7 +79,7 @@ module.exports = React.createClass({
|
|||||||
{this.props.button}
|
{this.props.button}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user