2017-01-24 18:54:05 +03:00
|
|
|
/*
|
|
|
|
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';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-01-24 18:54:05 +03:00
|
|
|
|
2017-12-01 13:30:49 +03:00
|
|
|
import { KeyCode } from '../../../Keyboard';
|
2017-02-13 19:03:21 +03:00
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2017-03-12 23:13:39 +03:00
|
|
|
import sdk from '../../../index';
|
2017-01-24 18:54:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2017-12-26 04:03:18 +03:00
|
|
|
onFinished: PropTypes.func.isRequired,
|
2017-01-24 18:54:05 +03:00
|
|
|
|
|
|
|
// callback to call when Enter is pressed
|
2017-12-26 04:03:18 +03:00
|
|
|
onEnterPressed: PropTypes.func,
|
2017-01-24 18:54:05 +03:00
|
|
|
|
2018-02-06 18:01:14 +03:00
|
|
|
// called when a key is pressed
|
|
|
|
onKeyDown: PropTypes.func,
|
|
|
|
|
2017-01-24 18:54:05 +03:00
|
|
|
// CSS class to apply to dialog div
|
2017-12-26 04:03:18 +03:00
|
|
|
className: PropTypes.string,
|
2017-01-24 18:54:05 +03:00
|
|
|
|
|
|
|
// Title for the dialog.
|
|
|
|
// (could probably actually be something more complicated than a string if desired)
|
2017-12-26 04:03:18 +03:00
|
|
|
title: PropTypes.string.isRequired,
|
2017-01-24 18:54:05 +03:00
|
|
|
|
|
|
|
// children should be the content of the dialog
|
2017-12-26 04:03:18 +03:00
|
|
|
children: PropTypes.node,
|
2017-01-24 18:54:05 +03:00
|
|
|
},
|
|
|
|
|
2017-05-16 16:50:19 +03:00
|
|
|
_onKeyDown: function(e) {
|
2018-02-06 18:01:14 +03:00
|
|
|
if (this.props.onKeyDown) {
|
|
|
|
this.props.onKeyDown(e);
|
|
|
|
}
|
2017-01-24 18:54:05 +03:00
|
|
|
if (e.keyCode === KeyCode.ESCAPE) {
|
2017-05-16 16:00:09 +03:00
|
|
|
e.stopPropagation();
|
2017-01-24 18:54:05 +03:00
|
|
|
e.preventDefault();
|
|
|
|
this.props.onFinished();
|
|
|
|
} else if (e.keyCode === KeyCode.ENTER) {
|
|
|
|
if (this.props.onEnterPressed) {
|
2017-05-16 16:00:09 +03:00
|
|
|
e.stopPropagation();
|
2017-01-24 18:54:05 +03:00
|
|
|
e.preventDefault();
|
|
|
|
this.props.onEnterPressed(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-13 19:03:21 +03:00
|
|
|
_onCancelClick: function(e) {
|
|
|
|
this.props.onFinished();
|
|
|
|
},
|
|
|
|
|
2017-01-24 18:54:05 +03:00
|
|
|
render: function() {
|
2017-03-12 23:03:05 +03:00
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
2017-05-27 22:47:09 +03:00
|
|
|
|
2017-01-24 18:54:05 +03:00
|
|
|
return (
|
2017-05-16 16:50:19 +03:00
|
|
|
<div onKeyDown={this._onKeyDown} className={this.props.className}>
|
2017-02-13 19:03:21 +03:00
|
|
|
<AccessibleButton onClick={this._onCancelClick}
|
|
|
|
className="mx_Dialog_cancelButton"
|
|
|
|
>
|
2017-03-12 23:03:05 +03:00
|
|
|
<TintableSvg src="img/icons-close-button.svg" width="35" height="35" />
|
2017-02-13 19:03:21 +03:00
|
|
|
</AccessibleButton>
|
2017-12-18 13:06:21 +03:00
|
|
|
<div className={'mx_Dialog_title ' + this.props.titleClass}>
|
2017-01-24 18:54:05 +03:00
|
|
|
{ this.props.title }
|
|
|
|
</div>
|
|
|
|
{ this.props.children }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|