import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import autobind from 'autobind-decorator'; import Modal from '../base/modal'; import ModalBody from '../base/modal-body'; import ModalHeader from '../base/modal-header'; import ModalFooter from '../base/modal-footer'; import CodeEditor from '../codemirror/code-editor'; import Dropdown from '../base/dropdown/dropdown'; import DropdownButton from '../base/dropdown/dropdown-button'; import DropdownItem from '../base/dropdown/dropdown-item'; import DropdownDivider from '../base/dropdown/dropdown-divider'; import MarkdownEditor from '../markdown-editor'; const MODES = { 'text/plain': 'Plain Text', 'application/json': 'JSON', 'application/xml': 'XML', 'text/x-markdown': 'Markdown', 'text/html': 'HTML' }; @autobind class CodePromptModal extends PureComponent { constructor (props) { super(props); this.state = { title: 'Not Set', defaultValue: '', submitName: 'Not Set', placeholder: '', hint: '', mode: 'text/plain', enableRender: false }; } _setModalRef (n) { this.modal = n; } _handleChange (value) { this._onChange(value); } _handleChangeMode (mode) { this.setState({mode}); this._onModeChange && this._onModeChange(mode); } hide () { this.modal.hide(); } show (options) { const { title, defaultValue, submitName, placeholder, hint, mode, enableRender, onChange, onModeChange } = options; this._onChange = onChange; this._onModeChange = onModeChange; this.setState({ title, defaultValue, submitName, placeholder, hint, enableRender, mode: mode || this.state.mode }); this.modal.show(); } render () { const { handleGetRenderContext, handleRender, editorKeyMap, editorIndentSize, editorFontSize, editorLineWrapping } = this.props; const { submitName, title, placeholder, defaultValue, hint, mode, enableRender } = this.state; return ( {title} {mode === 'text/x-markdown' ? (
) : (
)}
{MODES[mode]} Editor Syntax {Object.keys(MODES).map(mode => ( {MODES[mode]} ))}
{hint ? `* ${hint}` : ''}
); } } CodePromptModal.propTypes = { // Required editorFontSize: PropTypes.number.isRequired, editorIndentSize: PropTypes.number.isRequired, editorKeyMap: PropTypes.string.isRequired, editorLineWrapping: PropTypes.bool.isRequired, // Optional handleGetRenderContext: PropTypes.func, handleRender: PropTypes.func }; export default CodePromptModal;