Browse Source

[docs] show line numbers in online jsx compiler

main
Paul O’Shannessy 10 years ago
parent
commit
4db91d74fe
  1. 1
      _js/jsx-compiler.js
  2. 17
      _js/live_editor.js
  3. 4
      css/react.scss

1
_js/jsx-compiler.js

@ -27,6 +27,7 @@ var CompilerPlayground = React.createClass({
renderCode={true} renderCode={true}
transformer={transformer.bind(null, this.state.harmony)} transformer={transformer.bind(null, this.state.harmony)}
showCompiledJSTab={false} showCompiledJSTab={false}
showLineNumbers={true}
/> />
<label className="compiler-option"> <label className="compiler-option">
<input <input

17
_js/live_editor.js

@ -9,12 +9,21 @@ var IS_MOBILE = (
); );
var CodeMirrorEditor = React.createClass({ var CodeMirrorEditor = React.createClass({
propTypes: {
lineNumbers: React.PropTypes.bool,
onChange: React.PropTypes.func
},
getDefaultProps: function() {
return {
lineNumbers: false
};
},
componentDidMount: function() { componentDidMount: function() {
if (IS_MOBILE) return; if (IS_MOBILE) return;
this.editor = CodeMirror.fromTextArea(this.refs.editor.getDOMNode(), { this.editor = CodeMirror.fromTextArea(this.refs.editor.getDOMNode(), {
mode: 'javascript', mode: 'javascript',
lineNumbers: false, lineNumbers: this.props.lineNumbers,
lineWrapping: true, lineWrapping: true,
smartIndent: false, // javascript mode does bad things with jsx indents smartIndent: false, // javascript mode does bad things with jsx indents
matchBrackets: true, matchBrackets: true,
@ -75,6 +84,7 @@ var ReactPlayground = React.createClass({
transformer: React.PropTypes.func, transformer: React.PropTypes.func,
renderCode: React.PropTypes.bool, renderCode: React.PropTypes.bool,
showCompiledJSTab: React.PropTypes.bool, showCompiledJSTab: React.PropTypes.bool,
showLineNumbers: React.PropTypes.bool,
editorTabTitle: React.PropTypes.string editorTabTitle: React.PropTypes.string
}, },
@ -84,7 +94,8 @@ var ReactPlayground = React.createClass({
return JSXTransformer.transform(code).code; return JSXTransformer.transform(code).code;
}, },
editorTabTitle: 'Live JSX Editor', editorTabTitle: 'Live JSX Editor',
showCompiledJSTab: true showCompiledJSTab: true,
showLineNumbers: false
}; };
}, },
@ -122,6 +133,7 @@ var ReactPlayground = React.createClass({
onChange={this.handleCodeChange} onChange={this.handleCodeChange}
codeText={compiledCode} codeText={compiledCode}
readOnly={true} readOnly={true}
lineNumbers={this.props.showLineNumbers}
/>; />;
var JSXContent = var JSXContent =
@ -130,6 +142,7 @@ var ReactPlayground = React.createClass({
onChange={this.handleCodeChange} onChange={this.handleCodeChange}
className="playgroundStage" className="playgroundStage"
codeText={this.state.code} codeText={this.state.code}
lineNumbers={this.props.showLineNumbers}
/>; />;
var JSXTabClassName = var JSXTabClassName =

4
css/react.scss

@ -608,8 +608,8 @@ div.CodeMirror pre, div.CodeMirror-linenumber, code {
@include code-typography; @include code-typography;
} }
div.CodeMirror-linenumber:after { div.CodeMirror-linenumber {
content: '.'; text-align: right;
} }
.CodeMirror, div.CodeMirror-gutters, div.highlight { .CodeMirror, div.CodeMirror-gutters, div.highlight {

Loading…
Cancel
Save