Skip to content

Commit b17af13

Browse files
committed
Playground partial
1 parent 4eb3040 commit b17af13

File tree

5 files changed

+78
-39
lines changed

5 files changed

+78
-39
lines changed

web/src/js/sandbox.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ hljs.registerLanguage('javascript', javascript);
55

66
const codeInput = document.querySelector('#code-input');
77
const codeOutput = document.querySelector('#code-output');
8+
const runButton = document.querySelector('.run-button');
9+
const resultBlock = document.querySelector('.result');
810

911
codeOutput.textContent = codeInput.value;
1012
hljs.highlightElement(codeOutput);
@@ -32,4 +34,20 @@ const resizeObserver = new ResizeObserver((entries) => {
3234
}
3335
});
3436

37+
// const originalConsoleLog = console.log;
38+
console.log = function (...args) {
39+
args.forEach(function (arg) {
40+
resultBlock.innerHTML += `<div class="console-log">${arg}</div>`;
41+
});
42+
}
43+
runButton.addEventListener('click', (event) => {
44+
resultBlock.innerHTML = '';
45+
const code = codeInput.value;
46+
try {
47+
Function(code)();
48+
} catch (e) {
49+
console.log(e);
50+
}
51+
})
52+
3553
resizeObserver.observe(codeInput);

web/src/sandbox.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@
5151
<main>
5252
<div class="main box">
5353
<h1>Sandbox</h1>
54-
<div class="editor">
55-
<textarea id="code-input" class="input" spellcheck="false"></textarea>
56-
<div id="code-output" class="output language-javascript"></div>
54+
<div class="sandbox-wrapper">
55+
<div class="editor">
56+
<textarea id="code-input" class="input" spellcheck="false"></textarea>
57+
<div id="code-output" class="output language-javascript"></div>
58+
</div>
59+
<div class="result"></div>
60+
</div>
61+
<div>
62+
<button class="run-button">Run</button>
5763
</div>
5864
</div>
5965
</main>

web/src/scss/includes/forms.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
button {
44
background-color: $button-color;
5-
border: none;
6-
border-radius: 1rem;
5+
border: 1px solid $button-color;
6+
border-radius: 0.5rem;
77
cursor: pointer;
88
padding: 1rem;
99

1010
font-weight: 600;
11-
color: $font-color;
11+
color: $font-color-dark;
1212

1313
&:hover {
1414
background-color: $button-color-hover;
15+
border-color: $font-color;
16+
color: $font-color;
1517
}
1618

1719
&.big {

web/src/scss/includes/theme.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
$font-color: $foreground;
55
$font-color-light: $white;
6+
$font-color-dark: $dark;
67

7-
$button-color: $green;
8-
$button-color-hover: $green;
8+
$button-color: $foreground;
9+
$button-color-hover: $selection;
910

1011
$box-color: $bg;
1112
$box-light: $selection;

web/src/scss/parts/editor.scss

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,54 @@
11
@use "../includes/variables" as *;
22
@use "../includes/mixins" as *;
33

4-
.editor {
5-
position: relative;
6-
height: 30rem;
7-
padding: 0;
8-
border: none;
4+
.sandbox-wrapper {
5+
display: flex;
6+
gap: 1rem;
97
margin: 2rem 0;
108

11-
.input, .output {
12-
box-sizing: border-box;
13-
position: absolute;
14-
height: 100%;
15-
width: 90%;
9+
.editor {
10+
position: relative;
11+
flex-basis: 800px;
12+
flex-grow: 1;
1613

17-
font-family: monospace;
18-
padding: 0.5em;
14+
height: 30rem;
15+
padding: 0;
1916
border: none;
20-
font-size: 0.85rem;
21-
line-height: 1.375rem;
22-
white-space: pre;
23-
word-wrap: break-word;
24-
overflow: auto;
25-
26-
scrollbar-color: $secondary $highlight;
27-
scrollbar-width: thin;
28-
}
2917

30-
.input {
31-
z-index: 1;
32-
color: transparent;
33-
caret-color: $foreground;
34-
background-color: transparent;
35-
}
18+
.input, .output {
19+
box-sizing: border-box;
20+
position: absolute;
21+
height: 100%;
22+
width: 100%;
23+
24+
font-family: monospace;
25+
padding: 0.5em;
26+
border: none;
27+
font-size: 0.85rem;
28+
line-height: 1.375rem;
29+
white-space: pre;
30+
word-wrap: break-word;
31+
overflow: auto;
3632

37-
.output {
38-
z-index: 0;
39-
background-color: $bg;
40-
padding-bottom: 7px;
33+
scrollbar-color: $secondary $highlight;
34+
scrollbar-width: thin;
35+
}
36+
37+
.input {
38+
z-index: 1;
39+
color: transparent;
40+
caret-color: $foreground;
41+
background-color: transparent;
42+
}
43+
44+
.output {
45+
z-index: 0;
46+
background-color: $bg;
47+
padding-bottom: 7px;
48+
}
49+
}
50+
.result {
51+
flex-basis: 400px;
52+
flex-shrink: 0;
4153
}
4254
}

0 commit comments

Comments
 (0)