2015-09-21 17:23:51 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2017-2024 New Vector Ltd.
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-09-21 17:23:51 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2015-09-21 17:23:51 +01:00
|
|
|
*/
|
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import React from "react";
|
2020-10-29 15:53:14 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2022-03-02 16:33:40 -07:00
|
|
|
import BaseDialog from "./BaseDialog";
|
|
|
|
|
import DialogButtons from "../elements/DialogButtons";
|
2015-09-21 17:23:51 +01:00
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
export interface IQuestionDialogProps {
|
2021-09-05 12:57:41 +02:00
|
|
|
title?: string;
|
|
|
|
|
description?: React.ReactNode;
|
|
|
|
|
extraButtons?: React.ReactNode;
|
|
|
|
|
button?: string;
|
|
|
|
|
buttonDisabled?: boolean;
|
|
|
|
|
danger?: boolean;
|
|
|
|
|
focus?: boolean;
|
|
|
|
|
headerImage?: string;
|
|
|
|
|
quitOnly?: boolean; // quitOnly doesn't show the cancel button just the quit [x].
|
|
|
|
|
fixedWidth?: boolean;
|
|
|
|
|
className?: string;
|
|
|
|
|
hasCancelButton?: boolean;
|
2021-09-13 18:03:05 +02:00
|
|
|
cancelButton?: React.ReactNode;
|
2023-02-28 10:31:48 +00:00
|
|
|
onFinished(ok?: boolean): void;
|
2021-09-05 12:57:41 +02:00
|
|
|
}
|
2015-09-21 17:23:51 +01:00
|
|
|
|
2022-07-13 12:55:08 +02:00
|
|
|
export default class QuestionDialog extends React.Component<IQuestionDialogProps> {
|
|
|
|
|
public static defaultProps: Partial<IQuestionDialogProps> = {
|
2020-08-29 12:14:16 +01:00
|
|
|
title: "",
|
|
|
|
|
description: "",
|
|
|
|
|
extraButtons: null,
|
|
|
|
|
focus: true,
|
|
|
|
|
hasCancelButton: true,
|
|
|
|
|
danger: false,
|
|
|
|
|
quitOnly: false,
|
|
|
|
|
};
|
2015-11-30 14:11:04 +00:00
|
|
|
|
2021-09-05 12:57:41 +02:00
|
|
|
private onOk = (): void => {
|
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
|
|
|
|
2021-09-05 12:57:41 +02:00
|
|
|
private onCancel = (): void => {
|
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
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2017-12-21 23:51:14 +13:00
|
|
|
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}
|
2022-12-12 12:24:14 +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
|
|
|
>
|
2022-12-12 12:24:14 +01:00
|
|
|
<div className="mx_Dialog_content" id="mx_Dialog_content">
|
|
|
|
|
{this.props.description}
|
2015-11-30 14:11:04 +00:00
|
|
|
</div>
|
2022-12-12 12:24:14 +01:00
|
|
|
<DialogButtons
|
2023-08-22 20:55:15 +01:00
|
|
|
primaryButton={this.props.button || _t("action|ok")}
|
2017-12-21 23:51:14 +13:00
|
|
|
primaryButtonClass={primaryButtonClass}
|
2020-10-29 15:53:14 +00:00
|
|
|
primaryDisabled={this.props.buttonDisabled}
|
2018-06-14 18:58:38 +01:00
|
|
|
cancelButton={this.props.cancelButton}
|
2020-02-26 21:54:45 +00:00
|
|
|
hasCancel={this.props.hasCancelButton && !this.props.quitOnly}
|
2018-06-14 18:58:38 +01: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}
|
|
|
|
|
>
|
2022-12-12 12:24:14 +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
|
|
|
}
|
|
|
|
|
}
|