logbox manager, alert manager and fix bitverse colors

This commit is contained in:
Olivier Gagnon
2021-10-01 10:39:09 -04:00
parent 62cd8ffcc6
commit 97c04a1037
18 changed files with 18 additions and 447 deletions
+6 -37
View File
@@ -1,43 +1,12 @@
import { createPopup } from "./createPopup";
import { getRandomInt } from "../../utils/helpers/getRandomInt";
import { AlertEvents } from "./AlertManager";
import React from "react";
import { jsx } from "@emotion/react";
interface IProps {
content: JSX.Element;
}
function MessagePopup(props: IProps): React.ReactElement {
return <>{props.content}</>;
}
export function dialogBoxCreate(txt: string | JSX.Element, preformatted = false): void {
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 }} />,
});
} else {
createPopup(popupId, MessagePopup, {
content: (
<p
dangerouslySetInnerHTML={{
__html: txt.replace(/(?:\r\n|\r|\n)/g, "<br />"),
}}
/>
),
});
}
export function dialogBoxCreate(txt: string | JSX.Element): void {
if (typeof txt !== "string") {
AlertEvents.emit(txt);
} else {
createPopup(popupId, MessagePopup, {
content: txt,
});
AlertEvents.emit(<pre dangerouslySetInnerHTML={{ __html: txt }} />);
}
}