Skip to content

Commit 83bbfef

Browse files
authored
Mobile playground improvements (#22)
* Improve playground responsivenes on mobile Editing is till really poor because monaco-editor does not really support mobile yet. But reading expereince is improved by seperating input/output into two "tabs". * Fixed content pane being hidden in desktop view
1 parent 2f94fd9 commit 83bbfef

File tree

2 files changed

+104
-16
lines changed

2 files changed

+104
-16
lines changed

src/pages/play/Playground.tsx

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ import styles from "./styles.module.scss";
1414
import { consoleFeedTheme, jsonTreeTheme } from "./themes";
1515
import type { CustomTypeScriptWorker } from "./ts.worker";
1616

17+
enum PanelKind {
18+
Input,
19+
Output,
20+
}
21+
interface PanelState {
22+
activePanel: PanelKind;
23+
}
24+
interface PanelContext extends PanelState {
25+
setActivePanel(panelID: PanelKind): void;
26+
}
27+
28+
const PanelContext = React.createContext<PanelContext>(null!);
29+
30+
function PanelContextProvider({ children }: { children: React.ReactNode }) {
31+
const [activePanel, setActivePanel] = useState<PanelKind>(PanelKind.Input);
32+
33+
return <PanelContext.Provider value={{ activePanel, setActivePanel }}>{children}</PanelContext.Provider>;
34+
}
1735
interface EditorState {
1836
source: string;
1937
lua: string;
@@ -67,8 +85,10 @@ function InputPane() {
6785
[],
6886
);
6987

88+
const { activePanel } = useContext(PanelContext);
89+
7090
return (
71-
<div className={styles.contentPane}>
91+
<div className={clsx(styles.contentPane, activePanel != PanelKind.Input && styles.contentPaneHiddenMobile)}>
7292
<MonacoEditor
7393
theme={theme}
7494
language="typescript"
@@ -107,9 +127,9 @@ function LuaOutput() {
107127
const { results } = useContext(EditorContext);
108128

109129
return (
110-
<div className={styles.editorOutput}>
111-
<div className={styles.editorOutputLineNumbers}>{">_"}</div>
112-
<div className={styles.editorOutputTerminal}>
130+
<div className={styles.luaOutput}>
131+
<div className={styles.luaOutputLineNumbers}>{">_"}</div>
132+
<div className={styles.luaOutputTerminal}>
113133
<ConsoleFeed
114134
key={isDarkTheme} // It does not update styles without re-mount
115135
logs={results as any}
@@ -134,8 +154,10 @@ function OutputPane() {
134154
return `https://sokra.github.io/source-map-visualization#base64,${inputs}`;
135155
}, [lua, sourceMap, source]);
136156

157+
const { activePanel } = useContext(PanelContext);
158+
137159
return (
138-
<div className={styles.contentPane}>
160+
<div className={clsx(styles.contentPane, activePanel != PanelKind.Output && styles.contentPaneHiddenMobile)}>
139161
<div className={styles.outputEditor}>
140162
<div style={{ height: "100%", display: isAstView ? "none" : "block" }}>
141163
<MonacoEditor
@@ -159,7 +181,7 @@ function OutputPane() {
159181
className={clsx("button button--outline button--primary", !isAstView && "button--active")}
160182
onClick={toggleAstView}
161183
>
162-
{isAstView ? "Lua AST" : "TEXT"}
184+
{isAstView ? "Text" : "Lua AST"}
163185
</button>
164186
<a className="button button--success" href={sourceMapUrl} target="_blank">
165187
Source Map
@@ -178,6 +200,8 @@ function PlaygroundNavbar() {
178200
const tsMinor = tsVersion.split(".")[1];
179201
const tsLink = `https://www.typescriptlang.org/docs/handbook/release-notes/typescript-${tsMajor}-${tsMinor}.html`;
180202

203+
const { activePanel, setActivePanel } = useContext(PanelContext);
204+
181205
return (
182206
<nav className={styles.navbar}>
183207
<div className={styles.navbarVersions}>
@@ -191,20 +215,36 @@ function PlaygroundNavbar() {
191215
<b>v{tsVersion}</b>
192216
</a>
193217
</div>
218+
<div className={styles.navBarPanelSelection}>
219+
<button
220+
className={clsx("button button--primary button--outline", activePanel == 0 && "button--active")}
221+
onClick={() => setActivePanel(PanelKind.Input)}
222+
>
223+
TS Input
224+
</button>
225+
<button
226+
className={clsx("button button--primary button--outline", activePanel == 1 && "button--active")}
227+
onClick={() => setActivePanel(PanelKind.Output)}
228+
>
229+
Lua Output
230+
</button>
231+
</div>
194232
</nav>
195233
);
196234
}
197235

198236
export default function Playground() {
199237
return (
200238
<>
201-
<PlaygroundNavbar />
202-
<div className={styles.content}>
203-
<EditorContextProvider>
204-
<InputPane />
205-
<OutputPane />
206-
</EditorContextProvider>
207-
</div>
239+
<PanelContextProvider>
240+
<PlaygroundNavbar />
241+
<div className={styles.content}>
242+
<EditorContextProvider>
243+
<InputPane />
244+
<OutputPane />
245+
</EditorContextProvider>
246+
</div>
247+
</PanelContextProvider>
208248
</>
209249
);
210250
}

src/pages/play/styles.module.scss

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ $navbar-height: 50px;
3838
padding-left: 12px;
3939
display: flex;
4040
align-items: center;
41+
justify-content: space-between;
4142
}
4243

4344
.navbarVersions {
@@ -46,6 +47,11 @@ $navbar-height: 50px;
4647
font-family: monospace;
4748
}
4849

50+
.navBarPanelSelection {
51+
display: none;
52+
padding-right: 12px;
53+
}
54+
4955
.content {
5056
width: 100%;
5157
height: calc(100vh - var(--ifm-navbar-height) - #{$navbar-height});
@@ -80,22 +86,64 @@ $output-height: 180px;
8086
}
8187
}
8288

83-
.editorOutput {
89+
.luaOutput {
8490
border-top: 1px var(--monaco-accent) solid;
8591
height: $output-height;
8692
font-family: Menlo, Monaco, "Lucida Console", "Courier New", monospace;
8793
display: flex;
8894
}
8995

90-
.editorOutputLineNumbers {
96+
.luaOutputLineNumbers {
9197
width: 40px;
9298
height: 100%;
9399
border-right: 1px var(--monaco-accent) solid;
94100
padding-top: 6px;
95101
padding-left: 10px;
96102
}
97103

98-
.editorOutputTerminal {
104+
.luaOutputTerminal {
99105
width: 100%;
100106
overflow-y: auto;
101107
}
108+
109+
@media only screen and (max-width: 400px) {
110+
.navbarVersions {
111+
display: none;
112+
}
113+
}
114+
115+
@media only screen and (max-width: 996px) {
116+
.content {
117+
flex-flow: column;
118+
}
119+
120+
.navBarPanelSelection {
121+
display: block;
122+
}
123+
124+
.contentPane {
125+
width: 100%;
126+
}
127+
128+
.contentPaneHiddenMobile {
129+
display: none;
130+
}
131+
132+
.outputControls {
133+
top: 0.5em;
134+
right: 1em;
135+
* {
136+
--ifm-button-size-multiplier: 0.8;
137+
}
138+
}
139+
140+
$output-height-mobile: 100px;
141+
142+
.outputEditor {
143+
height: calc(100% - #{$output-height-mobile});
144+
}
145+
146+
.luaOutput {
147+
height: $output-height-mobile;
148+
}
149+
}

0 commit comments

Comments
 (0)