1+ import * as React from 'react' ;
2+ import * as Space from 'react-spaces' ;
3+ import MonacoEditor from 'react-monaco-editor' ;
4+ import { CenterType } from 'react-spaces' ;
5+ import './CodeEditor.scss' ;
6+
7+ export const CodeEditor = ( ) => {
8+ return (
9+ < Space . Fill className = "code-editor" >
10+ < Header />
11+ < Main />
12+ </ Space . Fill >
13+ )
14+ }
15+
16+ const Header = ( ) => {
17+ return (
18+ < Space . Top className = "title-bar" centerContent = { CenterType . HorizontalVertical } size = { 30 } style = { { backgroundColor : '#333' , color : '#c5c5c5' } } >
19+ < MenuBar />
20+ UI Demo - Example UI interface
21+ </ Space . Top >
22+ )
23+ }
24+
25+ const Main = ( ) => {
26+ const [ sidebarVisible , setSidebarVisible ] = React . useState ( true ) ;
27+ const [ sidebarWide , setSidebarWide ] = React . useState ( false ) ;
28+
29+ return (
30+ < Space . Fill style = { { backgroundColor : '#1E1E1E' } } >
31+ < Space . Fill >
32+ < IconPane />
33+ < SideBar wide = { sidebarWide } visible = { sidebarVisible } />
34+ < Editor toggleSize = { ( ) => setSidebarWide ( ! sidebarWide ) } toggleVisibility = { ( ) => setSidebarVisible ( ! sidebarVisible ) } />
35+ </ Space . Fill >
36+ </ Space . Fill >
37+ )
38+ }
39+
40+ const MenuBar = ( ) => {
41+ return (
42+ < Space . Left className = "menu-bar" size = "30%" >
43+
44+ </ Space . Left >
45+ )
46+ }
47+
48+ const Editor : React . FC < { toggleVisibility : ( ) => void , toggleSize : ( ) => void } > = ( props ) => {
49+ const [ code , setCode ] = React . useState ( 'import * as React from \'react\';\r\nimport * as Space from \'react-spaces\';\r\n\r\nexport const App = () => {\r\n <Space.ViewPort>\r\n <Space.Top size={30}>\r\n Hello!\r\n </Space.Top>\r\n <Space.Fill>\r\n World!\r\n </Space.Fill>\r\n </Space.ViewPort>\r\n}' ) ;
50+
51+ const options = {
52+ selectOnLineNumbers : true ,
53+ automaticLayout : true
54+ } ;
55+
56+ return (
57+ < Space . Fill >
58+ < Space . Fill >
59+ < Space . Top className = "editor-tabs" size = { 40 } >
60+ </ Space . Top >
61+ < Space . Fill className = "editor-main" >
62+ < MonacoEditor
63+ value = { code }
64+ onChange = { ( newValue : string ) => setCode ( newValue ) }
65+ options = { options }
66+ language = "javascript"
67+ theme = "vs-dark" />
68+ </ Space . Fill >
69+ </ Space . Fill >
70+ < BottomPane toggleSize = { props . toggleSize } toggleVisibility = { props . toggleVisibility } />
71+ </ Space . Fill >
72+ )
73+ }
74+
75+ const IconPane = ( ) => {
76+ return (
77+ < Space . Left order = { 1 } className = "side-bar-icons" size = { 50 } style = { { backgroundColor : '#333' } } >
78+ </ Space . Left >
79+ )
80+ }
81+
82+ const SideBar : React . FC < { wide : boolean , visible : boolean } > = ( props ) => {
83+ return (
84+ props . visible ?
85+ < Space . LeftResizable order = { 2 } className = "side-bar" size = { props . wide ? 500 : 300 } handleSize = { 2 } overlayHandle = { false } style = { { backgroundColor : '#252526' } } >
86+ < SideBarPane order = { 1 } title = "Open editors" height = { 200 } >
87+
88+ </ SideBarPane >
89+ < SideBarPane order = { 2 } title = "Demo" height = { 300 } >
90+
91+ </ SideBarPane >
92+ < SideBarPane fill = { true } title = "Outline" >
93+
94+ </ SideBarPane >
95+ </ Space . LeftResizable > :
96+ null
97+ )
98+ }
99+
100+ const SideBarPane : React . FC < { order ?: number , title : string , height ?: number , fill ?: boolean } > = ( props ) => {
101+ return (
102+ props . fill ?
103+ < Space . Fill className = "sidebar-pane" >
104+ < SideBarPaneInner title = { props . title } > { props . children } </ SideBarPaneInner >
105+ </ Space . Fill >
106+ :
107+ < Space . TopResizable className = "sidebar-pane" order = { props . order } size = { props . height ! } >
108+ < SideBarPaneInner title = { props . title } > { props . children } </ SideBarPaneInner >
109+ </ Space . TopResizable >
110+ )
111+ }
112+
113+ const SideBarPaneInner : React . FC < { title : string } > = ( props ) => {
114+ return (
115+ < >
116+ < Space . Top className = "title" size = { 28 } style = { { backgroundColor : '#383838' , color : '#c5c5c5' } } >
117+ < Space . CenteredVertically >
118+ { props . title }
119+ </ Space . CenteredVertically >
120+ </ Space . Top >
121+ < Space . Fill className = "content" >
122+ { props . children }
123+ </ Space . Fill >
124+ </ >
125+ )
126+ }
127+
128+ const BottomPane : React . FC < { toggleVisibility : ( ) => void , toggleSize : ( ) => void } > = ( props ) => {
129+ return (
130+ < Space . BottomResizable className = "bottom-pane" size = { 60 } handleSize = { 2 } centerContent = { Space . CenterType . HorizontalVertical } >
131+ < button onClick = { props . toggleVisibility } > Toggle sidebar visibility</ button >
132+ < button onClick = { props . toggleSize } > Toggle sidebar size</ button >
133+ </ Space . BottomResizable >
134+ )
135+ }
0 commit comments