Files
ThreadNet-Web/src/components/views/dialogs/QuestionDialog.tsx
T

86 lines
2.8 KiB
TypeScript
Raw Normal View History

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
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
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;
onFinished(ok?: boolean): void;
2021-09-05 12:57:41 +02:00
}
2015-09-21 17:23:51 +01: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,
};
2021-09-05 12:57:41 +02:00
private onOk = (): void => {
this.props.onFinished(true);
2020-08-29 12:14:16 +01:00
};
2021-09-05 12:57:41 +02:00
private onCancel = (): void => {
this.props.onFinished(false);
2020-08-29 12:14:16 +01:00
};
public render(): React.ReactNode {
2017-12-21 23:51:14 +13:00
let primaryButtonClass = "";
if (this.props.danger) {
primaryButtonClass = "danger";
}
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}
</div>
2022-12-12 12:24:14 +01:00
<DialogButtons
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}
cancelButton={this.props.cancelButton}
2020-02-26 21:54:45 +00:00
hasCancel={this.props.hasCancelButton && !this.props.quitOnly}
onPrimaryButtonClick={this.onOk}
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>
);
2020-08-29 12:14:16 +01:00
}
}