Skip to content

Commit 1e235fb

Browse files
committed
add BrowserWindow component
1 parent f513d6e commit 1e235fb

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React from "react";
9+
10+
import BrowserWindow from "./index";
11+
12+
// Quick and dirty component, to improve later if needed
13+
export default function IframeWindow({ url }: { url: string }): JSX.Element {
14+
return (
15+
<div style={{ padding: 10 }}>
16+
<BrowserWindow
17+
url={url}
18+
style={{
19+
minWidth: "min(100%,45vw)",
20+
width: 800,
21+
maxWidth: "100%",
22+
overflow: "hidden",
23+
}}
24+
bodyStyle={{ padding: 0 }}
25+
>
26+
<iframe
27+
src={url}
28+
title={url}
29+
style={{ display: "block", width: "100%", height: 300 }}
30+
/>
31+
</BrowserWindow>
32+
</div>
33+
);
34+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React, { type CSSProperties, type ReactNode } from "react";
9+
import clsx from "clsx";
10+
11+
import styles from "./styles.module.css";
12+
13+
interface Props {
14+
children: ReactNode;
15+
minHeight?: number;
16+
url: string;
17+
style?: CSSProperties;
18+
bodyStyle?: CSSProperties;
19+
}
20+
21+
export default function BrowserWindow({
22+
children,
23+
minHeight,
24+
url = "http://localhost:3000",
25+
style,
26+
bodyStyle,
27+
}: Props): JSX.Element {
28+
return (
29+
<div className={styles.browserWindow} style={{ ...style, minHeight }}>
30+
<div className={styles.browserWindowHeader}>
31+
<div className={styles.buttons}>
32+
<span className={styles.dot} style={{ background: "#f25f58" }} />
33+
<span className={styles.dot} style={{ background: "#fbbe3c" }} />
34+
<span className={styles.dot} style={{ background: "#58cb42" }} />
35+
</div>
36+
<div className={clsx(styles.browserWindowAddressBar, "text--truncate")}>
37+
{url}
38+
</div>
39+
<div className={styles.browserWindowMenuIcon}>
40+
<div>
41+
<span className={styles.bar} />
42+
<span className={styles.bar} />
43+
<span className={styles.bar} />
44+
</div>
45+
</div>
46+
</div>
47+
48+
<div className={styles.browserWindowBody} style={bodyStyle}>
49+
{children}
50+
</div>
51+
</div>
52+
);
53+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
.browserWindow {
9+
border: 3px solid var(--ifm-color-emphasis-200);
10+
border-radius: var(--ifm-global-radius);
11+
box-shadow: var(--ifm-global-shadow-lw);
12+
margin-bottom: var(--ifm-leading);
13+
}
14+
15+
.browserWindowHeader {
16+
align-items: center;
17+
background: var(--ifm-color-emphasis-200);
18+
display: flex;
19+
padding: 0.5rem 1rem;
20+
}
21+
22+
.row::after {
23+
content: "";
24+
display: table;
25+
clear: both;
26+
}
27+
28+
.buttons {
29+
white-space: nowrap;
30+
}
31+
32+
.right {
33+
align-self: center;
34+
width: 10%;
35+
}
36+
37+
[data-theme="light"] {
38+
--ifm-background-color: #fff;
39+
}
40+
41+
.browserWindowAddressBar {
42+
flex: 1 0;
43+
margin: 0 1rem 0 0.5rem;
44+
border-radius: 12.5px;
45+
background-color: var(--ifm-background-color);
46+
color: var(--ifm-color-gray-800);
47+
padding: 5px 15px;
48+
font:
49+
400 13px Arial,
50+
sans-serif;
51+
user-select: none;
52+
}
53+
54+
[data-theme="dark"] .browserWindowAddressBar {
55+
color: var(--ifm-color-gray-300);
56+
}
57+
58+
.dot {
59+
margin-right: 6px;
60+
margin-top: 4px;
61+
height: 12px;
62+
width: 12px;
63+
background-color: #bbb;
64+
border-radius: 50%;
65+
display: inline-block;
66+
}
67+
68+
.browserWindowMenuIcon {
69+
margin-left: auto;
70+
}
71+
72+
.bar {
73+
width: 17px;
74+
height: 3px;
75+
background-color: #aaa;
76+
margin: 3px 0;
77+
display: block;
78+
}
79+
80+
.browserWindowBody {
81+
background-color: var(--ifm-background-color);
82+
border-bottom-left-radius: inherit;
83+
border-bottom-right-radius: inherit;
84+
padding: 1rem;
85+
}
86+
87+
.browserWindowBody > *:last-child {
88+
margin-bottom: 0;
89+
}

0 commit comments

Comments
 (0)