frontAnswerer/src/widget.tsx

30 lines
802 B
TypeScript
Raw Normal View History

import QuizAnswerer from "@/components/QuizAnswerer";
2024-04-24 15:56:11 +00:00
import { createRoot } from "react-dom/client";
// eslint-disable-next-line react-refresh/only-export-components
export * from "./widgets";
2024-01-20 12:26:28 +00:00
2024-04-24 15:56:11 +00:00
// old widget
2024-01-20 12:26:28 +00:00
const widget = {
create({ selector, quizId, changeFaviconAndTitle = true }: {
2024-01-20 12:26:28 +00:00
selector: string;
quizId: string;
changeFaviconAndTitle: boolean;
2024-01-20 12:26:28 +00:00
}) {
const element = document.getElementById(selector);
if (!element) throw new Error("Element for widget doesn't exist");
2024-04-24 15:56:11 +00:00
const root = createRoot(element);
2024-01-20 12:26:28 +00:00
2024-04-24 15:56:11 +00:00
root.render(
<QuizAnswerer
quizId={quizId}
changeFaviconAndTitle={changeFaviconAndTitle}
disableGlobalCss
/>
);
2024-01-20 12:26:28 +00:00
},
};
export default widget;