Use DialogButtons in QuestionDialog

Use DialogButtons to eliminate duplicate button code.
This commit is contained in:
Aidan Gauland 2017-12-21 23:51:14 +13:00
parent 45d86ea7ca
commit 3b2c61e456

View file

@ -18,7 +18,6 @@ limitations under the License.
import React from 'react'; import React from 'react';
import sdk from '../../../index'; import sdk from '../../../index';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import classnames from 'classnames';
export default React.createClass({ export default React.createClass({
displayName: 'QuestionDialog', displayName: 'QuestionDialog',
@ -53,30 +52,27 @@ export default React.createClass({
render: function() { render: function() {
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
const cancelButton = this.props.hasCancelButton ? ( const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
<button onClick={this.onCancel}> let primaryButtonClass = "";
{ _t("Cancel") } if (this.props.danger) {
</button> primaryButtonClass = "danger";
) : null; }
const buttonClasses = classnames({
mx_Dialog_primary: true,
danger: this.props.danger,
});
return ( return (
<BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished} <BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished}
onEnterPressed={this.onOk} onEnterPressed={this.onOk}
title={this.props.title} title={this.props.title}
focus={this.props.focus}
> >
<div className="mx_Dialog_content"> <div className="mx_Dialog_content">
{ this.props.description } { this.props.description }
</div> </div>.
<div className="mx_Dialog_buttons"> <DialogButtons primaryButton={this.props.button || _t('OK')}
<button className={buttonClasses} onClick={this.onOk} autoFocus={this.props.focus}> onPrimaryButtonClick={this.onOk}
{ this.props.button || _t('OK') } primaryButtonClass={primaryButtonClass}
</button> onCancel={this.onCancel}
>
{ this.props.extraButtons } { this.props.extraButtons }
{ cancelButton } </DialogButtons>
</div>
</BaseDialog> </BaseDialog>
); );
}, },