Skip to content

Commit 8c5b39e

Browse files
authored
Merge pull request #143 from chvmvd/fix-playground
Fix playground #123
2 parents 55a7186 + e560ad5 commit 8c5b39e

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

src/components/BrowserWindow/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import styles from "./styles.module.css";
1212

1313
interface Props {
1414
children: ReactNode;
15-
minHeight: number;
16-
url: string;
15+
height: string;
16+
url?: string;
1717
}
1818

1919
export default function BrowserWindow({
2020
children,
21-
minHeight,
21+
height,
2222
url = "http://localhost:3000",
2323
}: Props): JSX.Element {
2424
return (
25-
<div className={styles.browserWindow} style={{ minHeight }}>
25+
<div className={styles.browserWindow} style={{ height }}>
2626
<div className={styles.browserWindowHeader}>
2727
<div className={styles.buttons}>
2828
<span className={styles.dot} style={{ background: "#f25f58" }} />
@@ -41,7 +41,9 @@ export default function BrowserWindow({
4141
</div>
4242
</div>
4343

44-
<div className={styles.browserWindowBody}>{children}</div>
44+
<div className={styles.browserWindowBody} style={{ height: "90%" }}>
45+
{children}
46+
</div>
4547
</div>
4648
);
4749
}

src/components/IframeOutput.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React from "react";
22
import BrowserWindow from "@site/src/components/BrowserWindow";
33

4-
export default function IframeOutput({ children }: { children: string }) {
4+
export default function IframeOutput({
5+
children,
6+
height,
7+
}: {
8+
children: string;
9+
height?: string;
10+
}) {
511
return (
612
<>
7-
<BrowserWindow minHeight={200}>
13+
<BrowserWindow height={height === undefined ? "200px" : height}>
814
<iframe
915
width="100%"
1016
height="100%"
@@ -13,10 +19,12 @@ export default function IframeOutput({ children }: { children: string }) {
1319
onLoad={(e) => {
1420
setInterval(
1521
(e) => {
16-
const iframe = e.target as HTMLIFrameElement;
17-
iframe.height = "100%";
18-
iframe.height =
19-
iframe.contentDocument.documentElement.scrollHeight + "px";
22+
if (height == undefined) {
23+
const iframe = e.target as HTMLIFrameElement;
24+
iframe.height = "100%";
25+
iframe.height =
26+
iframe.contentDocument.documentElement.scrollHeight + "px";
27+
}
2028
},
2129
3000,
2230
e

src/pages/HTMLPlayground.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,34 @@ export default function Home(): JSX.Element {
1111
return (
1212
<Layout
1313
title={`Hello from ${siteConfig.title}`}
14-
description="Description will go into a meta tag in <head />"
14+
description="This is a playground of HTML"
1515
>
1616
<Box p={2} mt={2}>
1717
<Grid container direction="row" spacing={2}>
1818
<Grid item xs={6}>
1919
<Editor
20-
height="400px"
20+
height="80vh"
2121
defaultLanguage="html"
22-
defaultValue={"aouesa"}
22+
defaultValue={`\
23+
<!DOCTYPE html>
24+
<html lang="ja">
25+
<head>
26+
<meta charset="UTF-8" />
27+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
28+
<title>Document</title>
29+
</head>
30+
<body>
31+
<p>Hello World!</p>
32+
</body>
33+
</html>\
34+
`}
2335
onChange={(value) => {
2436
setHTML(value);
2537
}}
2638
/>
2739
</Grid>
2840
<Grid item xs={6}>
29-
<IframeOutput>{html}</IframeOutput>
41+
<IframeOutput height="80vh">{html}</IframeOutput>
3042
</Grid>
3143
</Grid>
3244
</Box>

0 commit comments

Comments
 (0)