You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
994 B
TypeScript
41 lines
994 B
TypeScript
5 years ago
|
import React, { useState } from "react";
|
||
|
import { t } from "../i18n";
|
||
|
|
||
|
import { Dialog } from "./Dialog";
|
||
4 years ago
|
import { useExcalidrawContainer } from "./App";
|
||
5 years ago
|
|
||
5 years ago
|
export const ErrorDialog = ({
|
||
2 years ago
|
children,
|
||
5 years ago
|
onClose,
|
||
|
}: {
|
||
2 years ago
|
children?: React.ReactNode;
|
||
5 years ago
|
onClose?: () => void;
|
||
5 years ago
|
}) => {
|
||
2 years ago
|
const [modalIsShown, setModalIsShown] = useState(!!children);
|
||
4 years ago
|
const { container: excalidrawContainer } = useExcalidrawContainer();
|
||
5 years ago
|
|
||
|
const handleClose = React.useCallback(() => {
|
||
|
setModalIsShown(false);
|
||
|
|
||
|
if (onClose) {
|
||
|
onClose();
|
||
|
}
|
||
4 years ago
|
// TODO: Fix the A11y issues so this is never needed since we should always focus on last active element
|
||
|
excalidrawContainer?.focus();
|
||
|
}, [onClose, excalidrawContainer]);
|
||
5 years ago
|
|
||
|
return (
|
||
|
<>
|
||
|
{modalIsShown && (
|
||
|
<Dialog
|
||
2 years ago
|
size="small"
|
||
5 years ago
|
onCloseRequest={handleClose}
|
||
|
title={t("errorDialog.title")}
|
||
|
>
|
||
2 years ago
|
<div style={{ whiteSpace: "pre-wrap" }}>{children}</div>
|
||
5 years ago
|
</Dialog>
|
||
|
)}
|
||
|
</>
|
||
|
);
|
||
5 years ago
|
};
|