2017-12-21 10:48:46 +00:00
|
|
|
/*
|
2018-01-09 05:40:12 +00:00
|
|
|
Copyright 2017 Aidan Gauland
|
2018-04-27 11:38:49 +00:00
|
|
|
Copyright 2018 New Vector Ltd.
|
2017-12-21 10:48:46 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2017-12-25 22:55:15 +00:00
|
|
|
import PropTypes from "prop-types";
|
2017-12-21 10:48:46 +00:00
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic container for buttons in modal dialogs.
|
|
|
|
*/
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: "DialogButtons",
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
// The primary button which is styled differently and has default focus.
|
2017-12-25 22:55:15 +00:00
|
|
|
primaryButton: PropTypes.node.isRequired,
|
2017-12-21 10:48:46 +00:00
|
|
|
|
2018-05-22 14:45:58 +00:00
|
|
|
// A node to insert into the cancel button instead of default "Cancel"
|
|
|
|
cancelButton: PropTypes.node,
|
|
|
|
|
2017-12-21 10:48:46 +00:00
|
|
|
// onClick handler for the primary button.
|
2017-12-25 22:55:15 +00:00
|
|
|
onPrimaryButtonClick: PropTypes.func.isRequired,
|
2017-12-21 10:48:46 +00:00
|
|
|
|
2018-04-27 11:38:49 +00:00
|
|
|
// should there be a cancel button? default: true
|
|
|
|
hasCancel: PropTypes.bool,
|
|
|
|
|
2017-12-21 10:48:46 +00:00
|
|
|
// onClick handler for the cancel button.
|
2018-04-27 11:38:49 +00:00
|
|
|
onCancel: PropTypes.func,
|
2017-12-21 10:48:46 +00:00
|
|
|
|
2017-12-25 22:55:15 +00:00
|
|
|
focus: PropTypes.bool,
|
2018-04-27 14:19:08 +00:00
|
|
|
|
2018-09-17 16:05:29 +00:00
|
|
|
// disables the primary and cancel buttons
|
2018-04-27 14:19:08 +00:00
|
|
|
disabled: PropTypes.bool,
|
2018-09-17 16:05:29 +00:00
|
|
|
|
|
|
|
// disables only the primary button
|
|
|
|
primaryDisabled: PropTypes.bool,
|
2017-12-21 10:48:46 +00:00
|
|
|
},
|
|
|
|
|
2018-04-27 11:38:49 +00:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
hasCancel: true,
|
2018-04-27 14:19:08 +00:00
|
|
|
disabled: false,
|
2018-04-27 14:56:28 +00:00
|
|
|
};
|
2018-04-27 11:38:49 +00:00
|
|
|
},
|
|
|
|
|
2018-04-26 16:07:58 +00:00
|
|
|
_onCancelClick: function() {
|
|
|
|
this.props.onCancel();
|
|
|
|
},
|
|
|
|
|
2017-12-21 10:48:46 +00:00
|
|
|
render: function() {
|
|
|
|
let primaryButtonClassName = "mx_Dialog_primary";
|
|
|
|
if (this.props.primaryButtonClass) {
|
|
|
|
primaryButtonClassName += " " + this.props.primaryButtonClass;
|
|
|
|
}
|
2018-04-27 14:19:08 +00:00
|
|
|
let cancelButton;
|
2018-05-22 14:45:58 +00:00
|
|
|
if (this.props.cancelButton || this.props.hasCancel) {
|
2018-04-27 14:19:08 +00:00
|
|
|
cancelButton = <button onClick={this._onCancelClick} disabled={this.props.disabled}>
|
2018-05-22 14:45:58 +00:00
|
|
|
{ this.props.cancelButton || _t("Cancel") }
|
2018-04-27 14:19:08 +00:00
|
|
|
</button>;
|
|
|
|
}
|
2017-12-21 10:48:46 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_Dialog_buttons">
|
2018-10-19 21:33:23 +00:00
|
|
|
{ cancelButton }
|
|
|
|
{ this.props.children }
|
2017-12-21 10:48:46 +00:00
|
|
|
<button className={primaryButtonClassName}
|
|
|
|
onClick={this.props.onPrimaryButtonClick}
|
|
|
|
autoFocus={this.props.focus}
|
2018-09-17 16:05:29 +00:00
|
|
|
disabled={this.props.disabled || this.props.primaryDisabled}
|
2017-12-21 10:48:46 +00:00
|
|
|
>
|
|
|
|
{ this.props.primaryButton }
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|