Skip to content

Commit a63ded3

Browse files
authored
Merge pull request #114 from reubenmiller/feat-browser-window
feat: add new BrowserWindow component to improve screenshot appearance
2 parents 67553c7 + ddcb31e commit a63ded3

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 ReactNode} 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}): ReactNode {
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+
<iframe
26+
src={url}
27+
title={url}
28+
style={{display: 'block', width: '100%', height: 300}}
29+
/>
30+
</BrowserWindow>
31+
</div>
32+
);
33+
}
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): ReactNode {
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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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: 400 13px Arial, sans-serif;
49+
user-select: none;
50+
}
51+
52+
[data-theme='dark'] .browserWindowAddressBar {
53+
color: var(--ifm-color-gray-300);
54+
}
55+
56+
.dot {
57+
margin-right: 6px;
58+
margin-top: 4px;
59+
height: 12px;
60+
width: 12px;
61+
background-color: #bbb;
62+
border-radius: 50%;
63+
display: inline-block;
64+
}
65+
66+
.browserWindowMenuIcon {
67+
margin-left: auto;
68+
}
69+
70+
.bar {
71+
width: 17px;
72+
height: 3px;
73+
background-color: #aaa;
74+
margin: 3px 0;
75+
display: block;
76+
}
77+
78+
.browserWindowBody {
79+
background-color: var(--ifm-background-color);
80+
border-bottom-left-radius: inherit;
81+
border-bottom-right-radius: inherit;
82+
padding: 1rem;
83+
}
84+
85+
.browserWindowBody > *:last-child {
86+
margin-bottom: 0;
87+
}

0 commit comments

Comments
 (0)