2021-08-18 06:51:51 +02:00
|
|
|
import { createPopup } from "../src/ui/React/createPopup";
|
|
|
|
import { getRandomInt } from "./helpers/getRandomInt";
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
interface IProps {
|
2021-09-05 01:09:30 +02:00
|
|
|
content: JSX.Element;
|
2021-08-18 06:51:51 +02:00
|
|
|
}
|
|
|
|
|
2021-09-13 00:03:07 +02:00
|
|
|
function MessagePopup(props: IProps): React.ReactElement {
|
2021-09-05 01:09:30 +02:00
|
|
|
return <>{props.content}</>;
|
2021-08-18 06:51:51 +02:00
|
|
|
}
|
|
|
|
|
2021-09-13 00:03:07 +02:00
|
|
|
export function dialogBoxCreate(txt: string | JSX.Element, preformatted = false): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
const popupId =
|
|
|
|
`popup-` +
|
|
|
|
Array.from(Array(16))
|
|
|
|
.map(() => `${getRandomInt(0, 9)}`)
|
|
|
|
.join("");
|
|
|
|
if (typeof txt === "string") {
|
|
|
|
if (preformatted) {
|
|
|
|
// For text files as they are often computed data that
|
|
|
|
// shouldn't be wrapped and should retain tabstops.
|
|
|
|
createPopup(popupId, MessagePopup, {
|
|
|
|
content: <pre dangerouslySetInnerHTML={{ __html: txt }} />,
|
|
|
|
});
|
2021-08-18 06:51:51 +02:00
|
|
|
} else {
|
2021-09-05 01:09:30 +02:00
|
|
|
createPopup(popupId, MessagePopup, {
|
|
|
|
content: (
|
|
|
|
<p
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: txt.replace(/(?:\r\n|\r|\n)/g, "<br />"),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
});
|
2021-08-18 06:51:51 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
createPopup(popupId, MessagePopup, {
|
|
|
|
content: txt,
|
|
|
|
});
|
|
|
|
}
|
2021-08-18 06:51:51 +02:00
|
|
|
}
|