// @flow import * as React from 'react'; import ReactDOMServer from 'react-dom/server'; import classnames from 'classnames'; import MarkdownPreview from 'component/common/markdown-preview'; import SimpleMDE from 'react-simplemde-editor'; import 'simplemde/dist/simplemde.min.css'; // eslint-disable-line import/no-extraneous-dependencies import Toggle from 'react-toggle'; import { openEditorMenu, stopContextMenu } from 'util/contextMenu'; type Props = { name: string, label?: string, render?: () => React.Node, prefix?: string, postfix?: string, error?: string | boolean, helper?: string | React.Node, type?: string, onChange?: any => any, defaultValue?: string | number, placeholder?: string | number, children?: React.Node, stretch?: boolean, affixClass?: string, // class applied to prefix/postfix label firstInList?: boolean, // at the top of a list, no padding top autoFocus?: boolean, inputProps?: { disabled?: boolean, }, }; export class FormField extends React.PureComponent { constructor(props) { super(props); this.input = React.createRef(); } componentDidMount() { const { autoFocus } = this.props; const input = this.input.current; if (input && autoFocus) { input.focus(); } } render() { const { render, label, prefix, postfix, error, helper, name, type, children, stretch, affixClass, autoFocus, ...inputProps } = this.props; const errorMessage = typeof error === 'object' ? error.message : error; let input; if (type) { if (type === 'select') { input = ( ); } else if (type === 'markdown') { const handleEvents = { contextmenu: openEditorMenu, }; input = (
; return ReactDOMServer.renderToString(preview); }, }} />
); } else if (type === 'textarea') { input =