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 = {
|
2016-05-09 13:42:39 -07:00
|
|
|
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() {
|
2016-05-09 13:42:39 -07:00
|
|
|
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
|
2016-05-09 13:42:39 -07:00
|
|
|
options={{ ...options, mode }}
|
|
|
|
value={ content } />
|
2016-03-05 21:06:04 -08:00
|
|
|
</NoSSR>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Editor);
|