CustomTitleEditor.js 1.5 KB

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