2024-04-24 15:56:11 +00:00
|
|
|
import QuizAnswerer from "@/components/QuizAnswerer";
|
|
|
|
import { Root, createRoot } from "react-dom/client";
|
|
|
|
|
|
|
|
|
|
|
|
export class ContainerWidget {
|
|
|
|
root: Root | undefined;
|
|
|
|
|
|
|
|
constructor({ selector, quizId }: {
|
|
|
|
quizId: string;
|
|
|
|
selector: string;
|
|
|
|
}) {
|
2024-04-25 14:06:42 +00:00
|
|
|
const element = document.querySelector(selector);
|
2024-04-24 15:56:11 +00:00
|
|
|
if (!element) throw new Error("Element for widget doesn't exist");
|
|
|
|
|
|
|
|
this.root = createRoot(element);
|
|
|
|
|
|
|
|
this.root.render(
|
|
|
|
<QuizAnswerer
|
|
|
|
quizId={quizId}
|
|
|
|
changeFaviconAndTitle={false}
|
|
|
|
disableGlobalCss
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
if (this.root) this.root.unmount();
|
|
|
|
}
|
|
|
|
}
|