From 73685da78b35fc67a81f43172c4b5d38b48f9987 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 10 Jul 2017 20:42:24 +0800 Subject: [PATCH] [web] Try StringSequence update logic and add tooltip. --- web/src/js/components/Modal/OptionMaster.jsx | 176 +++++++++++++++---- 1 file changed, 138 insertions(+), 38 deletions(-) diff --git a/web/src/js/components/Modal/OptionMaster.jsx b/web/src/js/components/Modal/OptionMaster.jsx index 3b4bae805..ac65a22aa 100644 --- a/web/src/js/components/Modal/OptionMaster.jsx +++ b/web/src/js/components/Modal/OptionMaster.jsx @@ -6,12 +6,19 @@ PureBooleanOption.PropTypes = { onChange: PropTypes.func.isRequired, } -function PureBooleanOption({ value, onChange, help}) { +function PureBooleanOption({ value, onChange, ...props}) { + let onFocus = () => { props.onFocus() }, + onBlur = () => { props.onBlur() }, + onMouseEnter = () => { props.onMouseEnter() }, + onMouseLeave = () => { props.onMouseLeave() } return ( ) } @@ -21,14 +28,21 @@ PureStringOption.PropTypes = { onChange: PropTypes.func.isRequired, } -function PureStringOption( { value, onChange, help }) { - let onKeyDown = (e) => {e.stopPropagation()} +function PureStringOption( { value, onChange, ...props }) { + let onKeyDown = (e) => {e.stopPropagation()}, + onFocus = () => { props.onFocus() }, + onBlur = () => { props.onBlur() }, + onMouseEnter = () => { props.onMouseEnter() }, + onMouseLeave = () => { props.onMouseLeave() } return ( ) } @@ -38,14 +52,22 @@ PureNumberOption.PropTypes = { onChange: PropTypes.func.isRequired, } -function PureNumberOption( {value, onChange, help }) { - let onKeyDown = (e) => {e.stopPropagation()} +function PureNumberOption( {value, onChange, ...props }) { + let onKeyDown = (e) => {e.stopPropagation()}, + onFocus = () => { props.onFocus() }, + onBlur = () => { props.onBlur() }, + onMouseEnter = () => { props.onMouseEnter() }, + onMouseLeave = () => { props.onMouseLeave() } + return ( ) } @@ -55,9 +77,21 @@ PureChoicesOption.PropTypes = { onChange: PropTypes.func.isRequired, } -function PureChoicesOption( { value, onChange, name, help, choices }) { +function PureChoicesOption( { value, onChange, name, choices, ...props}) { + let onFocus = () => { props.onFocus() }, + onBlur = () => { props.onBlur() }, + onMouseEnter = () => { props.onMouseEnter() }, + onMouseLeave = () => { props.onMouseLeave() } return ( - { choices.map((choice, index) => ( ))} @@ -68,34 +102,42 @@ function PureChoicesOption( { value, onChange, name, help, choices }) { class PureStringSequenceOption extends Component { constructor(props, context) { super(props, context) - this.state = { height: 1, focus: false } + this.state = { height: 1, focus: false, value: this.props.value} this.onFocus = this.onFocus.bind(this) this.onBlur = this.onBlur.bind(this) this.onKeyDown = this.onKeyDown.bind(this) + this.onChange = this.onChange.bind(this) } onFocus() { this.setState( {focus: true, height: 3 }) + this.props.onFocus() } onBlur() { this.setState( {focus: false, height: 1}) + this.props.onBlur() } onKeyDown(e) { e.stopPropagation() } + onChange(e) { + const value = e.target.value.split("\n") + console.log(value) + this.props.onChange(e) + this.setState({ value }) + } + render() { - const {value, onChange, help} = this.props - const {height, focus} = this.state + const {height, value} = this.state return (