{"size": 928, "ext": "js", "max_stars_repo_path": "src/InputTypes/PercentInput.js", "max_stars_repo_name": "jschirrmacher/cosmoteer-mod-editor", "max_stars_repo_stars_event_min_datetime": "2017-07-11T18:36:29.000Z", "max_stars_repo_stars_event_max_datetime": "2017-07-11T18:36:29.000Z", "max_issues_repo_path": "src/InputTypes/PercentInput.js", "max_issues_repo_name": "jschirrmacher/cosmoteer-mod-editor", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/InputTypes/PercentInput.js", "max_forks_repo_name": "jschirrmacher/cosmoteer-mod-editor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.935483871, "max_line_length": 95, "alphanum_fraction": 0.4795258621}
/**
 * Created by Jasper on 24.07.2017.
 */
import React, { Component } from 'react'               // eslint-disable-line no-unused-vars

class IntInput extends Component {

    change(e) {
        let val = e.target.value
        let isEmpty = val === ''
        val = parseInt(val.replace(/[^0-9.]+/g, ''))
        val = isEmpty ? 0 : val
        if((val > -1 && val < 101)){
            this.props.edit(this.props.name, val)
        }
    }

    render() {
        return (
            <div>
                <label>{this.props.name}</label>
                <input type="text" onFocus={() => this.setState({focus: true})}
                    onBlur={() => this.setState({focus: false})} onChange={e => this.change(e)}
                    value={this.props ? this.state && this.state.focus ? this.props.value
                        : this.props.value + '%': ''} />
            </div>
        )
    }
}

export default IntInput