File tree Expand file tree Collapse file tree 11 files changed +557
-43
lines changed Expand file tree Collapse file tree 11 files changed +557
-43
lines changed Original file line number Diff line number Diff line change 33 "version" : " 0.1.0" ,
44 "private" : true ,
55 "dependencies" : {
6+ "bootstrap" : " ^4.3.1" ,
67 "codemirror" : " ^5.48.0" ,
78 "react" : " ^16.8.6" ,
9+ "react-bootstrap" : " ^1.0.0-beta.9" ,
810 "react-codemirror2" : " ^6.0.0" ,
911 "react-dom" : " ^16.8.6" ,
12+ "react-router-dom" : " ^5.0.1" ,
1013 "react-scripts" : " 3.0.1"
1114 },
1215 "scripts" : {
Original file line number Diff line number Diff line change 55.CodeMirror {
66 font-family : monospace;
77 font-size : 21pt ;
8- height : 300 px ;
8+ height : 400 px ;
99 /* background-color: #44475a; */
10+ }
11+
12+ .toggler {
13+ width : 200px ;
14+ position : relative;
15+ left : 50% ;
16+ margin : 40px 0 40px -100px
1017}
Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
2- import 'codemirror/lib/codemirror. css' ;
3- import './App.css'
4- import { Controlled as CodeMirror } from 'react-codemirror2 '
5- import 'codemirror/mode/xml/xml '
6- import 'codemirror/theme/dracula.css '
7-
2+ import 'bootstrap/dist/css/bootstrap.min. css'
3+ import { Switch , Route } from 'react-router-dom' ;
4+ import AppNav from './components/AppNav '
5+ import XML from './components/XML '
6+ import JS from './components/JS '
7+ import Home from './components/Home'
88
99
1010export default class App extends Component {
11- constructor ( ) {
12- super ( ) ;
13- this . state = {
14- name : 'CodeMirror' ,
15- code : '🌹💕🐱🚀 MODE: XML'
16- } ;
17- }
18-
19- updateCode = ( newCode ) => {
20- this . setState ( {
21- code : newCode ,
22- } ) ;
23- }
2411
25- render ( ) {
26- const options = {
27- lineNumbers : true ,
28- mode : 'xml' ,
29- theme : 'dracula'
30- } ;
12+ render ( ) {
13+
3114 return (
32- < div >
33- < p className = "op" >
34- { this . state . code }
35- </ p >
36- { /* <CodeMirror value={this.state.code} onChange={this.updateCode} options={options} autoFocus={true} /> */ }
37- < CodeMirror
38- value = { this . state . code }
39- options = { options }
40- onBeforeChange = { ( editor , data , code ) => {
41- this . setState ( { code} ) ;
42- } }
43- onChange = { ( editor , data , code ) => {
44- this . updateCode ( code )
45- } }
46- />
47- </ div >
15+ < React . Fragment >
16+ < AppNav />
17+ < Switch >
18+ < Route exact path = "/" component = { Home } />
19+ < Route path = "/xml" component = { XML } />
20+ < Route path = "/js" component = { JS } />
21+ </ Switch >
22+ </ React . Fragment >
4823 ) ;
4924 }
5025}
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import { Link } from 'react-router-dom'
3+ import './Navbar.css' ;
4+
5+ const AppNav = ( ) => {
6+ return (
7+ < React . Fragment >
8+ < nav className = "navbar navbar-expand-sm bg-dark navbar-dark px-sm-5" >
9+ < Link to = '/' >
10+ < span className = 'navbar-brand' > CodeMirror React</ span >
11+ </ Link >
12+ < ul className = "navbar-nav align-items-center" >
13+ < li className = "nav-item ml-5 " >
14+ < Link to = '/xml' className = 'nav-link' >
15+ XML
16+ </ Link >
17+ </ li >
18+ < li className = "nav-item ml-5 " >
19+ < Link to = '/js' className = 'nav-link' >
20+ JS
21+ </ Link >
22+ </ li >
23+ </ ul >
24+ </ nav >
25+ </ React . Fragment >
26+ )
27+ }
28+
29+ export default AppNav ;
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+
3+ const Hello = props => < h1 > { props . code } </ h1 > ;
4+
5+ export default Hello ;
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+
3+ const Home = ( ) => {
4+ return < h1 > HOME PAGE</ h1 >
5+ }
6+
7+ export default Home ;
Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react'
2+ import 'codemirror/lib/codemirror.css' ;
3+ import '../App.css'
4+ import { Controlled as CodeMirror } from 'react-codemirror2'
5+ import 'codemirror/mode/javascript/javascript'
6+ import 'codemirror/theme/dracula.css'
7+ import Hello from './Hello'
8+
9+
10+ export default class XML extends Component {
11+ constructor ( props ) {
12+ super ( props ) ;
13+ this . state = {
14+ name : 'CodeMirror' ,
15+ code : '🌹💕🐱🚀 MODE: JS' ,
16+ viewOpToggle : false
17+ } ;
18+ }
19+
20+ updateCode = ( newCode ) => {
21+ this . setState ( {
22+ code : newCode ,
23+ } ) ;
24+ }
25+
26+ handleSubmit = e => {
27+ e . preventDefault ( ) ;
28+ this . setState (
29+ { viewOpToggle : ! this . state . viewOpToggle }
30+ )
31+ }
32+ render ( ) {
33+ const options = {
34+ lineNumbers : true ,
35+ matchBrackets : true ,
36+ mode : 'javascript' ,
37+ theme : 'dracula'
38+ } ;
39+ return (
40+ < div >
41+ < CodeMirror
42+ ref = { this . code }
43+ value = { this . state . code }
44+ options = { options }
45+ onBeforeChange = { ( editor , data , code ) => {
46+ this . setState ( { code} ) ;
47+ } }
48+ />
49+ < div className = "btn btn-primary p-2 my-3 toggler" onClick = { this . handleSubmit } > Toggle Code Display</ div >
50+ { this . state . viewOpToggle &&
51+ < Hello code = { this . state . code } />
52+ }
53+ </ div >
54+ )
55+ }
56+ }
Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react'
2+ import 'codemirror/lib/codemirror.css' ;
3+ import '../App.css'
4+ import { Controlled as CodeMirror } from 'react-codemirror2'
5+ import 'codemirror/mode/xml/xml.js'
6+ import 'codemirror/theme/dracula.css'
7+ import Hello from './Hello'
8+
9+
10+ export default class XML extends Component {
11+ constructor ( props ) {
12+ super ( props ) ;
13+ this . state = {
14+ name : 'CodeMirror' ,
15+ code : '🌹💕🐱🚀 <MODE>: </XML>' ,
16+ viewOpToggle : false
17+ } ;
18+ }
19+
20+ updateCode = ( newCode ) => {
21+ this . setState ( {
22+ code : newCode ,
23+ } ) ;
24+ }
25+
26+ handleSubmit = e => {
27+ e . preventDefault ( ) ;
28+ this . setState (
29+ { viewOpToggle : ! this . state . viewOpToggle }
30+ )
31+ }
32+ render ( ) {
33+ const options = {
34+ lineNumbers : true ,
35+ matchBrackets : true ,
36+ mode : 'xml' ,
37+ theme : 'dracula'
38+ } ;
39+ return (
40+ < div >
41+ < CodeMirror
42+ ref = { this . code }
43+ value = { this . state . code }
44+ options = { options }
45+ onBeforeChange = { ( editor , data , code ) => {
46+ this . setState ( { code} ) ;
47+ } }
48+ />
49+ < div className = "btn btn-primary p-2 my-3 toggler" onClick = { this . handleSubmit } > Toggle Code Display</ div >
50+ { this . state . viewOpToggle &&
51+ < Hello code = { this . state . code } />
52+ }
53+ </ div >
54+ )
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments