CustomHeaderEditor.jsx 1.6 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('codemirror/addon/hint/html-hint');
  9. require('codemirror/addon/edit/closetag');
  10. require('~/client/util/codemirror/autorefresh.ext');
  11. require('jquery-ui/ui/widgets/resizable');
  12. export default class CustomHeaderEditor extends React.Component {
  13. render() {
  14. return (
  15. <CodeMirror
  16. value={this.props.value}
  17. autoFocus
  18. detach
  19. options={{
  20. mode: 'htmlmixed',
  21. autoCloseTags: true,
  22. lineNumbers: true,
  23. tabSize: 2,
  24. indentUnit: 2,
  25. theme: 'eclipse',
  26. autoRefresh: { force: true }, // force option is enabled by autorefresh.ext.js -- Yuki Takei
  27. matchBrackets: true,
  28. autoCloseBrackets: true,
  29. extraKeys: { 'Ctrl-Space': 'autocomplete' },
  30. }}
  31. editorDidMount={(editor, next) => {
  32. // resizable with jquery.ui
  33. $(editor.getWrapperElement()).resizable({
  34. resize() {
  35. editor.setSize($(this).width(), $(this).height());
  36. },
  37. });
  38. }}
  39. onChange={(editor, data, value) => {
  40. this.props.onChange(value);
  41. }}
  42. />
  43. );
  44. }
  45. }
  46. CustomHeaderEditor.propTypes = {
  47. value: PropTypes.string.isRequired,
  48. onChange: PropTypes.func.isRequired,
  49. };