feat(react): port info modal

This commit is contained in:
Elian Doran
2025-08-03 23:20:32 +03:00
parent e53ad2c62a
commit a62f12b427
4 changed files with 72 additions and 84 deletions

View File

@@ -0,0 +1,56 @@
import { EventData } from "../../components/app_context";
import ReactBasicWidget from "../react/ReactBasicWidget";
import { ConfirmDialogCallback } from "./confirm";
import { closeActiveDialog, openDialog } from "../../services/dialog";
import Modal from "../react/Modal";
import { t } from "../../services/i18n";
import Button from "../react/Button";
import { useRef } from "preact/compat";
interface ShowInfoDialogProps {
message?: string | HTMLElement;
callback?: ConfirmDialogCallback;
lastElementToFocus?: HTMLElement | null;
}
function ShowInfoDialogComponent({ message, callback, lastElementToFocus }: ShowInfoDialogProps) {
const okButtonRef = useRef<HTMLButtonElement>(null);
return (message && <Modal
className="info-dialog"
size="sm"
title={t("info.modalTitle")}
onHidden={() => {
callback?.();
lastElementToFocus?.focus();
}}
onShown={() => okButtonRef.current?.focus?.()}
footer={<Button
buttonRef={okButtonRef}
text={t("info.okButton")}
onClick={() => closeActiveDialog()}
/>}
>
<div className="info-dialog-content" dangerouslySetInnerHTML={{ __html: message ?? "" }}></div>
</Modal>);
}
export default class InfoDialog extends ReactBasicWidget {
private props: ShowInfoDialogProps = {};
get component() {
return <ShowInfoDialogComponent {...this.props} />;
}
showInfoDialogEvent({ message, callback }: EventData<"showInfoDialog">) {
this.props = {
message: Array.isArray(message) ? message[0] : message,
callback,
lastElementToFocus: (document.activeElement as HTMLElement)
};
this.doRender();
openDialog(this.$widget);
}
}