CustomCssEditor.jsx 1.5 KB

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