frontAnswerer/src/widgets/popup/PopupWidget.tsx

30 lines
711 B
TypeScript
Raw Normal View History

2024-04-24 15:56:11 +00:00
import { Root, createRoot } from "react-dom/client";
2024-05-08 17:50:18 +00:00
import { ComponentPropsWithoutRef } from "react";
import QuizPopup from "./QuizPopup";
2024-04-24 15:56:11 +00:00
2024-05-08 17:50:18 +00:00
type Props = ComponentPropsWithoutRef<typeof QuizPopup>;
2024-04-24 15:56:11 +00:00
export class PopupWidget {
root: Root | undefined;
2024-05-08 17:50:18 +00:00
element = document.createElement("div");
2024-04-24 15:56:11 +00:00
2024-05-08 17:50:18 +00:00
constructor(props: Props) {
2024-04-24 15:56:11 +00:00
this.element.style.setProperty("display", "none");
document.body.appendChild(this.element);
this.root = createRoot(this.element);
2024-05-08 17:50:18 +00:00
this.render(props);
}
render(props: Props) {
this.root?.render(<QuizPopup {...props} />);
2024-04-24 15:56:11 +00:00
}
destroy() {
if (this.root) this.root.unmount();
this.element.remove();
}
}