2015-09-21 17:23:51 +01:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-08-21 19:18:32 +01:00
|
|
|
Copyright 2017 New Vector Ltd.
|
2015-09-21 17:23:51 +01: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-24 15:54:05 +00:00
|
|
|
import React from 'react';
|
2017-12-26 14:03:18 +13:00
|
|
|
import PropTypes from 'prop-types';
|
2020-10-29 15:53:14 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
|
2019-12-19 18:19:56 -07:00
|
|
|
import * as sdk from '../../../index';
|
2017-05-25 18:20:48 +01:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-09-21 17:23:51 +01:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
export default class QuestionDialog extends React.Component {
|
|
|
|
|
static propTypes = {
|
2017-12-26 14:03:18 +13:00
|
|
|
title: PropTypes.string,
|
|
|
|
|
description: PropTypes.node,
|
|
|
|
|
extraButtons: PropTypes.node,
|
|
|
|
|
button: PropTypes.string,
|
2020-10-29 15:53:14 +00:00
|
|
|
buttonDisabled: PropTypes.bool,
|
2017-12-26 14:03:18 +13:00
|
|
|
danger: PropTypes.bool,
|
|
|
|
|
focus: PropTypes.bool,
|
|
|
|
|
onFinished: PropTypes.func.isRequired,
|
2020-01-31 17:03:10 +01:00
|
|
|
headerImage: PropTypes.string,
|
2020-02-26 21:54:45 +00:00
|
|
|
quitOnly: PropTypes.bool, // quitOnly doesn't show the cancel button just the quit [x].
|
2020-03-16 12:00:56 +00:00
|
|
|
fixedWidth: PropTypes.bool,
|
2020-10-29 15:53:14 +00:00
|
|
|
className: PropTypes.string,
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2015-09-21 17:23:51 +01:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
static defaultProps = {
|
|
|
|
|
title: "",
|
|
|
|
|
description: "",
|
|
|
|
|
extraButtons: null,
|
|
|
|
|
focus: true,
|
|
|
|
|
hasCancelButton: true,
|
|
|
|
|
danger: false,
|
|
|
|
|
quitOnly: false,
|
|
|
|
|
};
|
2015-11-30 14:11:04 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
onOk = () => {
|
2015-11-30 14:11:04 +00:00
|
|
|
this.props.onFinished(true);
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2015-11-30 14:11:04 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
onCancel = () => {
|
2015-11-30 14:11:04 +00:00
|
|
|
this.props.onFinished(false);
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2015-11-30 14:11:04 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
render() {
|
2017-01-24 15:54:05 +00:00
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
2017-12-21 23:51:14 +13:00
|
|
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
|
|
|
|
let primaryButtonClass = "";
|
|
|
|
|
if (this.props.danger) {
|
|
|
|
|
primaryButtonClass = "danger";
|
|
|
|
|
}
|
2015-11-30 14:11:04 +00:00
|
|
|
return (
|
2020-03-16 12:00:56 +00:00
|
|
|
<BaseDialog
|
2020-10-29 15:53:14 +00:00
|
|
|
className={classNames("mx_QuestionDialog", this.props.className)}
|
2020-03-16 12:00:56 +00:00
|
|
|
onFinished={this.props.onFinished}
|
2017-01-24 15:54:05 +00:00
|
|
|
title={this.props.title}
|
2017-11-29 21:13:48 +01:00
|
|
|
contentId='mx_Dialog_content'
|
2020-01-31 17:03:10 +01:00
|
|
|
headerImage={this.props.headerImage}
|
2018-10-10 17:07:17 +01:00
|
|
|
hasCancel={this.props.hasCancelButton}
|
2020-03-16 12:00:56 +00:00
|
|
|
fixedWidth={this.props.fixedWidth}
|
2017-01-24 15:54:05 +00:00
|
|
|
>
|
2017-11-30 08:32:18 +01:00
|
|
|
<div className="mx_Dialog_content" id='mx_Dialog_content'>
|
2017-09-28 11:21:06 +01:00
|
|
|
{ this.props.description }
|
2015-11-30 14:11:04 +00:00
|
|
|
</div>
|
2017-12-21 23:51:14 +13:00
|
|
|
<DialogButtons primaryButton={this.props.button || _t('OK')}
|
2018-06-14 18:58:38 +01:00
|
|
|
primaryButtonClass={primaryButtonClass}
|
2020-10-29 15:53:14 +00:00
|
|
|
primaryDisabled={this.props.buttonDisabled}
|
2018-05-22 15:45:58 +01:00
|
|
|
cancelButton={this.props.cancelButton}
|
2020-02-26 21:54:45 +00:00
|
|
|
hasCancel={this.props.hasCancelButton && !this.props.quitOnly}
|
2017-12-21 23:51:14 +13:00
|
|
|
onPrimaryButtonClick={this.onOk}
|
2018-01-12 10:52:51 +00:00
|
|
|
focus={this.props.focus}
|
2017-12-21 23:51:14 +13:00
|
|
|
onCancel={this.onCancel}
|
|
|
|
|
>
|
2017-09-28 11:21:06 +01:00
|
|
|
{ this.props.extraButtons }
|
2017-12-21 23:51:14 +13:00
|
|
|
</DialogButtons>
|
2017-01-24 15:54:05 +00:00
|
|
|
</BaseDialog>
|
2015-11-30 14:11:04 +00:00
|
|
|
);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|