frontAnswerer/src/widgets/popup/PopupWidget.tsx

31 lines
722 B
TypeScript
Raw Normal View History

2024-04-24 15:56:11 +00:00
import { Root, createRoot } from "react-dom/client";
import QuizDialog from "../shared/QuizDialog";
2024-04-24 15:56:11 +00:00
export class PopupWidget {
root: Root | undefined;
element: HTMLDivElement;
constructor({ quizId }: {
quizId: string;
}) {
this.element = document.createElement("div");
this.element.style.setProperty("display", "none");
document.body.appendChild(this.element);
this.root = createRoot(this.element);
this.root.render(
<QuizDialog
quizId={quizId}
onClose={() => this.destroy()}
/>
);
}
destroy() {
if (this.root) this.root.unmount();
this.element.remove();
}
}