@@ -14,6 +14,24 @@ import styles from "./styles.module.scss";
1414import { consoleFeedTheme , jsonTreeTheme } from "./themes" ;
1515import 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+ }
1735interface 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
198236export 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}
0 commit comments