diff --git a/assets/js/src/form_editor/components/form_settings/codemirror_wrap.jsx b/assets/js/src/form_editor/components/form_settings/codemirror_wrap.jsx new file mode 100644 index 0000000000..85f8f1ce3d --- /dev/null +++ b/assets/js/src/form_editor/components/form_settings/codemirror_wrap.jsx @@ -0,0 +1,42 @@ +import React, { useEffect, useRef } from 'react'; +import codemirror from 'codemirror'; +import 'codemirror/mode/css/css'; // Side effect +import PropTypes from 'prop-types'; + +const CodemirrorWrap = ({ options, value, onChange }) => { + const textArea = useRef(null); + const editor = useRef(null); + + useEffect(() => { + editor.current = codemirror.fromTextArea(textArea.current, options); + editor.current.on('change', (doc) => onChange(doc.getValue())); + return () => { + if (editor.current) { + editor.current.toTextArea(); + } + }; + }, [options, onChange]); + + return ( +