Files
freeCodeCamp/common/app/routes/challenges/components/Editor.jsx

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-03-05 21:06:04 -08:00
import React, { PropTypes } from 'react';
import { createSelector } from 'reselect';
import { connect } from 'react-redux';
import Codemirror from 'react-codemirror';
import NoSSR from 'react-no-ssr';
import PureComponent from 'react-pure-render/component';
const mapStateToProps = createSelector(
state => state.app.windowHeight,
state => state.app.navHeight,
(windowHeight, navHeight) => ({ height: windowHeight - navHeight - 50 })
);
const options = {
lint: true,
lineNumbers: true,
mode: 'javascript',
theme: 'monokai',
runnable: true,
matchBrackets: true,
autoCloseBrackets: true,
scrollbarStyle: 'null',
lineWrapping: true,
gutters: ['CodeMirror-lint-markers']
};
export class Editor extends PureComponent {
static displayName = 'Editor';
static propTypes = {
height: PropTypes.number,
content: PropTypes.string,
mode: PropTypes.string
};
static defaultProps = {
content: '// Happy Coding!',
mode: 'javascript'
2016-03-05 21:06:04 -08:00
};
render() {
const { content, height, mode } = this.props;
2016-03-05 21:06:04 -08:00
const style = {};
if (height) {
style.height = height + 'px';
}
return (
<div
className='challenges-editor'
style={ style }>
<NoSSR>
<Codemirror
options={{ ...options, mode }}
value={ content } />
2016-03-05 21:06:04 -08:00
</NoSSR>
</div>
);
}
}
export default connect(mapStateToProps)(Editor);