Skip to content

Commit 4afcc01

Browse files
committed
Add resizer
1 parent 08ce7ad commit 4afcc01

File tree

6 files changed

+94
-11
lines changed

6 files changed

+94
-11
lines changed

playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"lz-string": "^1.4.4",
1515
"react": "^17.0.2",
1616
"react-dom": "^17.0.2",
17-
"react-error-boundary": "^3.1.4"
17+
"react-error-boundary": "^3.1.4",
18+
"react-split-pane": "^0.1.92"
1819
},
1920
"devDependencies": {
2021
"@types/react": "^17.0.2",

playground/src/app.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState } from "react";
22
import { Editor } from "./editor";
33
import { readHash, writeHash } from "./hash";
44
import { Preview } from "./preview";
5+
import SplitPane from "react-split-pane";
6+
import "./resizer.css";
57

68
const defaultCode = `
79
# Hello
@@ -40,6 +42,9 @@ function App() {
4042
writeHash(input);
4143
}, [input]);
4244

45+
// when the width changes we want to re-render the preview
46+
const [refreshKey, setRefreshKey] = useState(0);
47+
4348
return data.standalonePreview ? (
4449
<Preview input={input} standalone={true} />
4550
) : (
@@ -54,8 +59,15 @@ function App() {
5459
</a>
5560
</header>
5661
<main>
57-
<Editor setInput={setInput} input={input} />
58-
<Preview input={input} />
62+
<SplitPane
63+
split="vertical"
64+
minSize={200}
65+
defaultSize="50%"
66+
onDragFinished={(e) => setRefreshKey(e)}
67+
>
68+
<Editor setInput={setInput} input={input} />
69+
<Preview input={input} refreshKey={refreshKey} />
70+
</SplitPane>
5971
</main>
6072
</div>
6173
);

playground/src/index.css

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ header svg {
6060
color: rgb(96 165 250);
6161
}
6262
main {
63-
display: flex;
63+
/* display: flex; */
6464
flex: 1 1 auto;
6565
overflow: hidden;
66+
position: relative;
6667
}
6768

6869
.editor-side {
69-
min-width: 400px;
70+
min-width: 200px;
7071
display: flex;
7172
flex-direction: column;
7273
flex: 1;
74+
height: 100%;
7375
/* background-color: #222;
7476
color: white; */
7577
}
@@ -135,14 +137,17 @@ main {
135137
}
136138

137139
.preview {
138-
min-width: 600px;
139140
flex: 1;
140141
min-height: 0;
142+
}
143+
144+
.preview:not(.standalone) {
141145
overflow: auto;
146+
position: absolute;
147+
inset: 0;
142148
}
143149

144150
.preview.standalone {
145-
overflow: unset;
146151
padding: 0.1px;
147152
}
148153

@@ -184,7 +189,7 @@ main {
184189
z-index: 3;
185190
background-color: #222;
186191
color: #fafafa;
187-
border-radius: 4px;
192+
border-radius: 8px;
188193
border: 1px solid #fafafa;
189194
}
190195

playground/src/preview.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function ErrorFallback({ error }) {
2929
);
3030
}
3131

32-
function InnerPreview({ input, standalone }) {
32+
function InnerPreview({ input, standalone, refreshKey }) {
3333
const [Content, setContent] = useState(undefined);
3434
const [error, setError] = useState(undefined);
3535
useEffect(() => {
@@ -78,7 +78,7 @@ function InnerPreview({ input, standalone }) {
7878
</a>
7979
)}
8080
<div className={`preview-container ${error ? "with-error" : ""}`}>
81-
{Content ? <Content components={{ CH }} /> : null}
81+
{Content ? <Content components={{ CH }} key={refreshKey} /> : null}
8282
</div>
8383
</>
8484
);

playground/src/resizer.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.Resizer {
2+
background: #000;
3+
opacity: 0.2;
4+
z-index: 1;
5+
-moz-box-sizing: border-box;
6+
-webkit-box-sizing: border-box;
7+
box-sizing: border-box;
8+
-moz-background-clip: padding;
9+
-webkit-background-clip: padding;
10+
background-clip: padding-box;
11+
}
12+
13+
.Resizer:hover {
14+
-webkit-transition: all 2s ease;
15+
transition: all 2s ease;
16+
}
17+
18+
.Resizer.horizontal {
19+
height: 11px;
20+
margin: -5px 0;
21+
border-top: 5px solid rgba(255, 255, 255, 0);
22+
border-bottom: 5px solid rgba(255, 255, 255, 0);
23+
cursor: row-resize;
24+
width: 100%;
25+
}
26+
27+
.Resizer.horizontal:hover {
28+
border-top: 5px solid rgba(0, 0, 0, 0.5);
29+
border-bottom: 5px solid rgba(0, 0, 0, 0.5);
30+
}
31+
32+
.Resizer.vertical {
33+
width: 11px;
34+
margin: 0 -5px;
35+
border-left: 5px solid rgba(255, 255, 255, 0);
36+
border-right: 5px solid rgba(255, 255, 255, 0);
37+
cursor: col-resize;
38+
}
39+
40+
.Resizer.vertical:hover {
41+
border-left: 5px solid rgba(0, 0, 0, 0.5);
42+
border-right: 5px solid rgba(0, 0, 0, 0.5);
43+
}
44+
.Resizer.disabled {
45+
cursor: not-allowed;
46+
}
47+
.Resizer.disabled:hover {
48+
border-color: transparent;
49+
}

yarn.lock

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13635,7 +13635,7 @@ promzard@^0.3.0:
1363513635
dependencies:
1363613636
read "1"
1363713637

13638-
prop-types@^15.6.2, prop-types@^15.7.2:
13638+
prop-types@^15.5.4, prop-types@^15.6.2, prop-types@^15.7.2:
1363913639
version "15.8.1"
1364013640
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
1364113641
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
@@ -14008,6 +14008,22 @@ [email protected]:
1400814008
dependencies:
1400914009
history "^5.2.0"
1401014010

14011+
react-split-pane@^0.1.92:
14012+
version "0.1.92"
14013+
resolved "https://registry.yarnpkg.com/react-split-pane/-/react-split-pane-0.1.92.tgz#68242f72138aed95dd5910eeb9d99822c4fc3a41"
14014+
integrity sha512-GfXP1xSzLMcLJI5BM36Vh7GgZBpy+U/X0no+VM3fxayv+p1Jly5HpMofZJraeaMl73b3hvlr+N9zJKvLB/uz9w==
14015+
dependencies:
14016+
prop-types "^15.7.2"
14017+
react-lifecycles-compat "^3.0.4"
14018+
react-style-proptype "^3.2.2"
14019+
14020+
react-style-proptype@^3.2.2:
14021+
version "3.2.2"
14022+
resolved "https://registry.yarnpkg.com/react-style-proptype/-/react-style-proptype-3.2.2.tgz#d8e998e62ce79ec35b087252b90f19f1c33968a0"
14023+
integrity sha512-ywYLSjNkxKHiZOqNlso9PZByNEY+FTyh3C+7uuziK0xFXu9xzdyfHwg4S9iyiRRoPCR4k2LqaBBsWVmSBwCWYQ==
14024+
dependencies:
14025+
prop-types "^15.5.4"
14026+
1401114027
react-textarea-autosize@^8.3.2:
1401214028
version "8.3.3"
1401314029
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-8.3.3.tgz#f70913945369da453fd554c168f6baacd1fa04d8"

0 commit comments

Comments
 (0)