<commit_before>/**
 * @jsx React.DOM
 */

var React = require('react');

var delimiters = {' ': 'Space'};

var KEY_CODES = {
  ENTER: 13,
  BACKSPACE: 8
};

var tagItemStyles = {
  'display': 'inline-block',
  'marginLeft': '2px',
  'marginRight': '2px'
};

var DefaultTagComponent = React.createClass({

  render: function() {
    var self = this,
      p = self.props;

    return (
      <div style={tagItemStyles}>
        {p.item}
      </div>
    );
  }

});

var TaggedInput = React.createClass({

  propTypes: {
    onAddTag: React.PropTypes.func,
    onRemoveTag: React.PropTypes.func
  },

  getInitialState: function () {
    return {
      tags: this.props.tags || [],
      currentInput: null
    };
  },

  render: function() {
    var self = this,
      s = self.state,
      p = self.props,
      tags = [],
      i;

    var TagComponent = p.tagComponent || DefaultTagComponent;

    for (i = 0 ; i < s.tags.length; i++) {
      tags.push(<TagComponent item={s.tags[i]} />);
    }

    var input = (
      <input type="text"
        ref='input'
        onKeyUp={this._handleKeyUp}
        onKeyDown={this._handleKeyDown}
        onChange={this._handleChange}
        value={s.currentInput}>
      </input>
    );

    return (
      <div className="tagged-input-wrapper">
        {tags}
        {input}
      </div>
    );
  },

  _handleKeyUp: function (e) {
    var s = this.state,
      enteredValue = e.target.value;

    switch (e.keyCode) {
      case KEY_CODES.ENTER:
        s.tags.push(enteredValue);
        this.setState({
          currentInput: ''
        });
        if (p.onAddTag) {
          p.onAddTag(enteredValue);
        }
        break;
    }

  },

  _handleKeyDown: function (e) {
    var s = this.state,
      p = this.props,
      poppedValue;

    switch (e.keyCode) {
      case KEY_CODES.BACKSPACE:
        if (!e.target.value || e.target.value.length < 0) {
          poppedValue = s.tags.pop();
          this.forceUpdate();<commit_msg>Added some inline styling for now to make it work<commit_after>/**
 * @jsx React.DOM
 */

var React = require('react');

var delimiters = {' ': 'Space'};

var KEY_CODES = {
  ENTER: 13,
  BACKSPACE: 8
};

var wrapperStyles = {
  'borderWidth': '1px',
  'borderStyle': 'solid',
  'borderColor': '#dadada',
  'padding': '2px'
};

var tagItemStyles = {
  'display': 'inline-block',
  'marginLeft': '2px',
  'marginRight': '2px'
};

var inputFieldStyles = {
  'border':'none',
  'outline': 'none'
};



var DefaultTagComponent = React.createClass({

  render: function() {
    var self = this,
      p = self.props;

    return (
      <div style={tagItemStyles}>
        {p.item}
      </div>
    );
  }

});

var TaggedInput = React.createClass({

  propTypes: {
    onAddTag: React.PropTypes.func,
    onRemoveTag: React.PropTypes.func
  },

  getInitialState: function () {
    return {
      tags: this.props.tags || [],
      currentInput: null
    };
  },

  render: function() {
    var self = this,
      s = self.state,
      p = self.props,
      tags = [],
      i;

    var TagComponent = p.tagComponent || DefaultTagComponent;

    for (i = 0 ; i < s.tags.length; i++) {
      tags.push(<TagComponent item={s.tags[i]} />);
    }

    var input = (
      <input type="text"
        style={inputFieldStyles}
        ref='input'
        onKeyUp={this._handleKeyUp}
        onKeyDown={this._handleKeyDown}
        onChange={this._handleChange}
        value={s.currentInput}>
      </input>
    );

    return (
      <div className="tagged-input-wrapper"
        style={wrapperStyles}>
        {tags}
        {input}
      </div>
    );
  },

  _handleKeyUp: function (e) {
    var s = this.state,
      p = this.props,
      enteredValue = e.target.value;

    switch (e.keyCode) {
      case KEY_CODES.ENTER:
        s.tags.push(enteredValue);
        this.setState({
          currentInput: ''
        });
        if (p.onAddTag) {
          p.onAddTag(enteredValue);
        }
        break;
    }

  },

  _handleKeyDown: function (e) {
    var s = this.state,
      p = this.props,
      poppedValue;

    switch (e.keyCode) {
      case KEY_CODES.BACKSPACE:
        if (!e.target.value || e.target.value.length < 0) {
          poppedValue = s.tags.pop();
          this.forceUpdate();
{'fraction_non_alphanumeric': 0.15172735760971054, 'fraction_numerical': 0.003734827264239029, 'mean_word_length': 2.07168458781362, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758124', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1459, 'n_words': 289}