Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/components/InteractiveCodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,58 @@ function HtmlCssEditor({
);
}

function HtmlJavascriptEditor({
defaultHTML,
setHTML,
defaultJavaScript,
setJS,
}: {
defaultHTML: string;
setHTML: Dispatch<SetStateAction<string>>;
defaultJavaScript: string;
setJS: Dispatch<SetStateAction<string>>;
}) {
return (
<>
<Tabs groupId="editor">
<TabItem value="html" label="HTML">
<Editor
height="400px"
defaultLanguage="html"
defaultValue={defaultHTML}
onChange={(value) => {
setHTML(value);
}}
/>
</TabItem>
<TabItem value="js" label="JavaScript">
<Editor
height="400px"
defaultLanguage="javascript"
defaultValue={defaultJavaScript}
onChange={(value) => {
setJS(value);
}}
/>
</TabItem>
</Tabs>
</>
);
}

export default function InteractiveCodeEditor({
language,
children,
defaultCSS,
defaultJavaScript,
}: {
language: "markdown" | "html" | "html-css" | "html-css-javascript" | "latex";
language:
| "markdown"
| "html"
| "html-css"
| "html-javascript"
| "html-css-javascript"
| "latex";
children?: string;
defaultCSS?: string;
defaultJavaScript?: string;
Expand Down Expand Up @@ -135,6 +180,13 @@ export default function InteractiveCodeEditor({
defaultCSS={defaultCSS}
setCSS={setCSS}
/>
) : language === "html-javascript" ? (
<HtmlJavascriptEditor
defaultHTML={children}
setHTML={setCode}
defaultJavaScript={defaultJavaScript}
setJS={setJS}
/>
) : (
<Editor
height="400px"
Expand All @@ -157,6 +209,8 @@ export default function InteractiveCodeEditor({
? latexToHTML(code)
: language === "html-css"
? `<style>${css}</style>${code}`
: language === "html-javascript"
? `${code}<script>${js}</script>`
: `<style>${css}</style>${code}<script>${js}</script>`}
</IframeOutput>
</div>
Expand Down