Files
ThreadNet-Web/src/components/views/dialogs/QuestionDialog.tsx
T
David LangleyandGitHub 491f0cd08a Change license (#13)
* Copyright headers 1

* Licence headers 2

* Copyright Headers 3

* Copyright Headers 4

* Copyright Headers 5

* Copyright Headers 6

* Copyright headers 7

* Add copyright headers for html and config file

* Replace license files and update package.json

* Update with CLA

* lint
2024-09-09 13:57:16 +00:00

86 lines
2.7 KiB
TypeScript

/*
Copyright 2017-2024 New Vector Ltd.
Copyright 2015, 2016 OpenMarket Ltd
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import classNames from "classnames";
import { _t } from "../../../languageHandler";
import BaseDialog from "./BaseDialog";
import DialogButtons from "../elements/DialogButtons";
export interface IQuestionDialogProps {
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;
cancelButton?: React.ReactNode;
onFinished(ok?: boolean): void;
}
export default class QuestionDialog extends React.Component<IQuestionDialogProps> {
public static defaultProps: Partial<IQuestionDialogProps> = {
title: "",
description: "",
extraButtons: null,
focus: true,
hasCancelButton: true,
danger: false,
quitOnly: false,
};
private onOk = (): void => {
this.props.onFinished(true);
};
private onCancel = (): void => {
this.props.onFinished(false);
};
public render(): React.ReactNode {
let primaryButtonClass = "";
if (this.props.danger) {
primaryButtonClass = "danger";
}
return (
<BaseDialog
className={classNames("mx_QuestionDialog", this.props.className)}
onFinished={this.props.onFinished}
title={this.props.title}
contentId="mx_Dialog_content"
headerImage={this.props.headerImage}
hasCancel={this.props.hasCancelButton}
fixedWidth={this.props.fixedWidth}
>
<div className="mx_Dialog_content" id="mx_Dialog_content">
{this.props.description}
</div>
<DialogButtons
primaryButton={this.props.button || _t("action|ok")}
primaryButtonClass={primaryButtonClass}
primaryDisabled={this.props.buttonDisabled}
cancelButton={this.props.cancelButton}
hasCancel={this.props.hasCancelButton && !this.props.quitOnly}
onPrimaryButtonClick={this.onOk}
focus={this.props.focus}
onCancel={this.onCancel}
>
{this.props.extraButtons}
</DialogButtons>
</BaseDialog>
);
}
}