forked from codewithtim/ReactJSTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim
authored and
Tim
committed
Aug 28, 2016
1 parent
9c6978a
commit 7512e59
Showing
44 changed files
with
22,070 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Lesson 12 Webpack setup/src/components/babel-transformer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import * as Babel from 'babel-standalone'; | ||
|
||
export default class BabelTransformer extends React.Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
inputJSX: '/* Add your JSX here */', | ||
outputJS: '', | ||
error: '' | ||
} | ||
this.transformJSX = this.transformJSX.bind(this); | ||
} | ||
|
||
transformJSX(event) { | ||
let code = event.target.value; | ||
try { | ||
this.setState({ | ||
outputJS: Babel.transform(code, { sourceMaps: true, presets: ['es2015', 'react'] }).code, | ||
error: '' | ||
}); | ||
|
||
console.log(this.state.outputJS); | ||
} | ||
catch(error) { | ||
this.setState({error: error.message}) | ||
} | ||
} | ||
render() { | ||
|
||
return ( | ||
<div> | ||
<div className="container" > | ||
<textarea onChange={this.transformJSX} defaultValue={this.state.inputJSX}></textarea> | ||
<pre> | ||
{this.state.outputJS} | ||
</pre> | ||
|
||
</div> | ||
<footer>{this.state.error}</footer> | ||
</div> | ||
) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const Hello = () => { | ||
return ( | ||
<div>Hello world!</div> | ||
) | ||
} | ||
import BabelTransformer from './components/babel-transformer'; | ||
|
||
ReactDOM.render( | ||
<Hello />, | ||
<BabelTransformer />, | ||
document.getElementById('app') | ||
); | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
/*font-family: monospace;*/ | ||
} | ||
|
||
footer { | ||
display: block; | ||
height: 10vh; | ||
overflow: auto; | ||
background-color: #f1f1f1; | ||
color: #c7254e; | ||
font-size: 28px; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
} | ||
|
||
.container { | ||
height: 90vh; | ||
display: flex; | ||
box-sizing: border-box; | ||
|
||
} | ||
|
||
pre, textarea { | ||
width: 50%; | ||
margin: 0; | ||
padding: 10px; | ||
color: #222; | ||
overflow: scroll; | ||
} | ||
|
||
|
||
textarea:focus { | ||
outline: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.