Editor.js 882 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { UnControlled as CodeMirror } from 'react-codemirror2';
  4. require('codemirror/addon/display/autorefresh');
  5. require('codemirror/mode/gfm/gfm');
  6. require('codemirror/lib/codemirror.css');
  7. export default class Editor extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. value: this.props.value,
  12. };
  13. }
  14. render() {
  15. return (
  16. <CodeMirror
  17. value={this.state.value}
  18. autoFocus={true}
  19. options={{
  20. mode: 'gfm',
  21. lineNumbers: true,
  22. autoRefresh: true
  23. }}
  24. onChange={(editor, data, value) => {
  25. if (this.props.onChange != null) {
  26. this.props.onChange(value);
  27. }
  28. }}
  29. />
  30. )
  31. }
  32. }
  33. Editor.propTypes = {
  34. value: PropTypes.string,
  35. onChange: PropTypes.func,
  36. };