CustomHeaderEditor.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { UnControlled as CodeMirror } from 'react-codemirror2';
  4. require('codemirror/addon/hint/show-hint');
  5. require('codemirror/addon/edit/matchbrackets');
  6. require('codemirror/addon/edit/closebrackets');
  7. require('codemirror/mode/htmlmixed/htmlmixed');
  8. require('../../util/codemirror/autorefresh.ext');
  9. require('jquery-ui/ui/widgets/resizable');
  10. export default class CustomHeaderEditor extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. }
  14. render() {
  15. // get initial value from inputElem
  16. const value = this.props.inputElem.value;
  17. return (
  18. <CodeMirror
  19. value={value}
  20. autoFocus={true}
  21. options={{
  22. mode: 'htmlmixed',
  23. lineNumbers: true,
  24. tabSize: 2,
  25. indentUnit: 2,
  26. theme: 'eclipse',
  27. autoRefresh: {force: true}, // force option is enabled by autorefresh.ext.js -- Yuki Takei
  28. matchBrackets: true,
  29. autoCloseBrackets: true,
  30. extraKeys: {'Ctrl-Space': 'autocomplete'},
  31. }}
  32. editorDidMount={(editor, next) => {
  33. // resizable with jquery.ui
  34. $(editor.getWrapperElement()).resizable({
  35. resize: function() {
  36. editor.setSize($(this).width(), $(this).height());
  37. }
  38. });
  39. }}
  40. onChange={(editor, data, value) => {
  41. this.props.inputElem.value = value;
  42. }}
  43. />
  44. );
  45. }
  46. }
  47. CustomHeaderEditor.propTypes = {
  48. inputElem: PropTypes.object.isRequired,
  49. };