@@ -14,6 +14,24 @@ import styles from "./styles.module.scss";
14
14
import { consoleFeedTheme , jsonTreeTheme } from "./themes" ;
15
15
import type { CustomTypeScriptWorker } from "./ts.worker" ;
16
16
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
+ }
17
35
interface EditorState {
18
36
source : string ;
19
37
lua : string ;
@@ -67,8 +85,10 @@ function InputPane() {
67
85
[ ] ,
68
86
) ;
69
87
88
+ const { activePanel } = useContext ( PanelContext ) ;
89
+
70
90
return (
71
- < div className = { styles . contentPane } >
91
+ < div className = { clsx ( styles . contentPane , activePanel != PanelKind . Input && styles . contentPaneHiddenMobile ) } >
72
92
< MonacoEditor
73
93
theme = { theme }
74
94
language = "typescript"
@@ -107,9 +127,9 @@ function LuaOutput() {
107
127
const { results } = useContext ( EditorContext ) ;
108
128
109
129
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 } >
113
133
< ConsoleFeed
114
134
key = { isDarkTheme } // It does not update styles without re-mount
115
135
logs = { results as any }
@@ -134,8 +154,10 @@ function OutputPane() {
134
154
return `https://sokra.github.io/source-map-visualization#base64,${ inputs } ` ;
135
155
} , [ lua , sourceMap , source ] ) ;
136
156
157
+ const { activePanel } = useContext ( PanelContext ) ;
158
+
137
159
return (
138
- < div className = { styles . contentPane } >
160
+ < div className = { clsx ( styles . contentPane , activePanel != PanelKind . Output && styles . contentPaneHiddenMobile ) } >
139
161
< div className = { styles . outputEditor } >
140
162
< div style = { { height : "100%" , display : isAstView ? "none" : "block" } } >
141
163
< MonacoEditor
@@ -159,7 +181,7 @@ function OutputPane() {
159
181
className = { clsx ( "button button--outline button--primary" , ! isAstView && "button--active" ) }
160
182
onClick = { toggleAstView }
161
183
>
162
- { isAstView ? "Lua AST " : "TEXT " }
184
+ { isAstView ? "Text " : "Lua AST " }
163
185
</ button >
164
186
< a className = "button button--success" href = { sourceMapUrl } target = "_blank" >
165
187
Source Map
@@ -178,6 +200,8 @@ function PlaygroundNavbar() {
178
200
const tsMinor = tsVersion . split ( "." ) [ 1 ] ;
179
201
const tsLink = `https://www.typescriptlang.org/docs/handbook/release-notes/typescript-${ tsMajor } -${ tsMinor } .html` ;
180
202
203
+ const { activePanel, setActivePanel } = useContext ( PanelContext ) ;
204
+
181
205
return (
182
206
< nav className = { styles . navbar } >
183
207
< div className = { styles . navbarVersions } >
@@ -191,20 +215,36 @@ function PlaygroundNavbar() {
191
215
< b > v{ tsVersion } </ b >
192
216
</ a >
193
217
</ 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 >
194
232
</ nav >
195
233
) ;
196
234
}
197
235
198
236
export default function Playground ( ) {
199
237
return (
200
238
< >
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 >
208
248
</ >
209
249
) ;
210
250
}
0 commit comments