diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-07-21 01:14:55 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-07-21 01:14:55 -0700 |
commit | 8a3a21bba1e6706295cc22e1b3a876a7a86cb705 (patch) | |
tree | 9408324d45850fd4def75c60cf3537a12f632217 /web/src/js/components/ValueEditor/ValidateEditor.jsx | |
parent | 427fffbcb82ba16dd65a4fee4000a05215e859b8 (diff) | |
download | mitmproxy-8a3a21bba1e6706295cc22e1b3a876a7a86cb705.tar.gz mitmproxy-8a3a21bba1e6706295cc22e1b3a876a7a86cb705.tar.bz2 mitmproxy-8a3a21bba1e6706295cc22e1b3a876a7a86cb705.zip |
web: fix ValueEditor, clean up code
Diffstat (limited to 'web/src/js/components/ValueEditor/ValidateEditor.jsx')
-rwxr-xr-x | web/src/js/components/ValueEditor/ValidateEditor.jsx | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/web/src/js/components/ValueEditor/ValidateEditor.jsx b/web/src/js/components/ValueEditor/ValidateEditor.jsx index 2f362986..7415c1b8 100755 --- a/web/src/js/components/ValueEditor/ValidateEditor.jsx +++ b/web/src/js/components/ValueEditor/ValidateEditor.jsx @@ -1,57 +1,57 @@ import React, { Component, PropTypes } from 'react' -import ReactDOM from 'react-dom' -import EditorBase from './EditorBase' +import ValueEditor from './ValueEditor' +import classnames from 'classnames' + export default class ValidateEditor extends Component { static propTypes = { content: PropTypes.string.isRequired, + readonly: PropTypes.bool, onDone: PropTypes.func.isRequired, - onInput: PropTypes.func, - isValid: PropTypes.func, className: PropTypes.string, + isValid: PropTypes.func.isRequired, } constructor(props) { super(props) - this.state = { currentContent: props.content } + this.state = { valid: props.isValid(props.content) } this.onInput = this.onInput.bind(this) this.onDone = this.onDone.bind(this) } componentWillReceiveProps(nextProps) { - this.setState({ currentContent: nextProps.content }) + this.setState({ valid: nextProps.isValid(nextProps.content) }) } - onInput(currentContent) { - this.setState({ currentContent }) - this.props.onInput && this.props.onInput(currentContent) + onInput(content) { + this.setState({ valid: this.props.isValid(content) }) } onDone(content) { - if (this.props.isValid && !this.props.isValid(content)) { - this.refs.editor.reset() + if (!this.props.isValid(content)) { + this.editor.reset() content = this.props.content } this.props.onDone(content) } render() { - let className = this.props.className || '' - if (this.props.isValid) { - if (this.props.isValid(this.state.currentContent)) { - className += ' has-success' - } else { - className += ' has-warning' + let className = classnames( + this.props.className, + { + 'has-success': this.state.valid, + 'has-warning': !this.state.valid } - } + ) return ( - <EditorBase - {...this.props} - ref="editor" - className={className} + <ValueEditor + content={this.props.content} + readonly={this.props.readonly} onDone={this.onDone} onInput={this.onInput} + className={className} + ref={(e) => this.editor = e} /> ) } |