{"size": 1753, "ext": "js", "max_stars_repo_path": "app/_renderer/ui/features/shared/form/Input.js", "max_stars_repo_name": "alexemorris/Structured-Load-Manager", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/_renderer/ui/features/shared/form/Input.js", "max_issues_repo_name": "alexemorris/Structured-Load-Manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/_renderer/ui/features/shared/form/Input.js", "max_forks_repo_name": "alexemorris/Structured-Load-Manager", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.6419753086, "max_line_length": 53, "alphanum_fraction": 0.5761551626}
import React, { Component } from 'react';
import PropTypes from 'prop-types';

export default class Input extends Component {

  static propTypes = {
    updateValue: PropTypes.func,
    value: PropTypes.string,
    type: PropTypes.oneOf(['text', 'password']),
    className: PropTypes.string,
    disabled: PropTypes.bool,
    label: PropTypes.node,
    justify: PropTypes.bool,
    flip: PropTypes.bool
  }

  static defaultProps = {
    updateValue: () => null,
    value: '',
    type: 'text',
    className: 'pt-input',
    disabled: false,
    label: null,
    justify: false,
    flip: false
  }

  constructor(props) {
    super(props);
    this.state = {
      value: this.props.value,
      changed: false
    };
  }

  setValue(event) {
    this.setState({ value: event.target.value });
  }

  updateValue(event) {
    this.props.updateValue(event.target.value);
  }

  handleKeyPress = (e) => {
    if (e.key === 'Enter') {
      this.props.updateValue(e.target.value);
      this.ref.blur();
    }
  }

  render() {
    let className = this.props.className;
    if (this.props.disabled) {
      className += ' pt-disabled';
    }

    const styles = {};

    if (this.props.justify) {
      styles.textAlign = 'right';
    }
    const label = (<span>{this.props.label}</span>);
    return (
      <label className="pt-label">
        {this.props.flip || label}
        <input
          onChange={this.setValue.bind(this)}
          type={this.props.type}
          value={this.state.value}
          onBlur={this.updateValue.bind(this)}
          onKeyPress={this.handleKeyPress.bind(this)}
          className={className}
          ref={(r) => { this.ref = r; }}
        />
        {!this.props.flip || label}
      </label>
    );
  }

}
