<commit_before>'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
    StyleSheetRegistry,
    StyleSheet,
    Image,
    Text,
    View,
    TouchableHighlight,
    TouchableWithoutFeedback
} = ReactNative;

var flattenStyle = ReactNative.StyleSheet.flatten;
var PropTypes = React.PropTypes;

var Checkbox = React.createClass({
  propTypes: {
    label: PropTypes.string,
    checked: PropTypes.bool.isRequired,
    onChange: PropTypes.func,
    uncheckedComponent: PropTypes.object,
    checkedComponent: PropTypes.object,
    labelStyle: ReactNative.Text.propTypes.style,
    labelContainerStyle: ReactNative.View.propTypes.style,
    containerStyle: ReactNative.View.propTypes.style,
    labelBefore: PropTypes.bool,
    children: PropTypes.element,
    highlight: PropTypes.bool
  },

  getDefaultProps() {
    return {
      label: null,
      labelBefore: false,
      checked: false,
      highlight: true
    }
  },

  onChange() {
    if(this.props.onChange){
      this.props.onChange(!this.props.checked);
    }
  },

  render() {
    if (!this.props.uncheckedComponent) {
      throw new Error('Checkbox requires a property for checkedComponent')
    }
    if (!this.props.checkedComponent) {
      throw new Error('Checkbox requires a property for uncheckedComponent')
    }

    var checkbox;
    if (this.props.checked) {
      checkbox = this.props.checkedComponent;
    } else {
      checkbox = this.props.uncheckedComponent;
    }

    var labelContainer;
    if (this.props.label) {
      labelContainer = (
        <View style={[styles.labelContainer, this.props.labelContainerStyle]}>
          <Text style={[styles.label, this.props.labelStyle]}>{this.props.label}</Text>
        </View>
      );
    } else if (this.props.children) {
      labelContainer = (
        <View style={[styles.labelContainer, this.props.labelContainerStyle]}>
          {this.props.children}
        </View>
      )
    } else {
      labelContainer = null;
    }

    var containerStyle = [
        styles.container,
        this.props.containerStyle
    ];

    var container = (
      <View style={containerStyle}>
        {checkbox}
        {labelContainer}
      </View>
    );

    if (this.props.labelBefore) {
      container = (
        <View style={containerStyle}>
          {labelContainer}
          {checkbox}
        </View>
      );
    }

    if (this.props.highlight) {
      return (
        <TouchableHighlight onPress={this.onChange} underlayColor='white'>
          {container}
        </TouchableHighlight>
      );
    } else {
      return (
        <TouchableWithoutFeedback onPress={this.onChange}>
          {container}
        </TouchableWithoutFeedback>
      );
    }
  }
});

var styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    alignItems: 'center',
    marginBottom: 5,
  },
  labelContainer: {
    marginLeft: 10,
    marginRight: 10
  },
  label: {<commit_msg>Updates Checkbox module to es6 to match codebase.<commit_after>import React from 'react';
import ReactNative from 'react-native';
import {
    StyleSheetRegistry,
    StyleSheet,
    Image,
    Text,
    View,
    TouchableHighlight,
    TouchableWithoutFeedback
} = ReactNative;

const flattenStyle = ReactNative.StyleSheet.flatten;
const PropTypes = React.PropTypes;

const Checkbox = React.createClass({
  propTypes: {
    label: PropTypes.string,
    checked: PropTypes.bool.isRequired,
    onChange: PropTypes.func,
    uncheckedComponent: PropTypes.object,
    checkedComponent: PropTypes.object,
    labelStyle: ReactNative.Text.propTypes.style,
    labelContainerStyle: ReactNative.View.propTypes.style,
    containerStyle: ReactNative.View.propTypes.style,
    labelBefore: PropTypes.bool,
    children: PropTypes.element,
    highlight: PropTypes.bool
  },

  getDefaultProps() {
    return {
      label: null,
      labelBefore: false,
      checked: false,
      highlight: true
    }
  },

  onChange() {
    if(this.props.onChange){
      this.props.onChange(!this.props.checked);
    }
  },

  render() {
    if (!this.props.uncheckedComponent) {
      throw new Error('Checkbox requires a property for checkedComponent')
    }
    if (!this.props.checkedComponent) {
      throw new Error('Checkbox requires a property for uncheckedComponent')
    }

    let checkbox;
    if (this.props.checked) {
      checkbox = this.props.checkedComponent;
    } else {
      checkbox = this.props.uncheckedComponent;
    }

    let labelContainer;
    if (this.props.label) {
      labelContainer = (
        <View style={[styles.labelContainer, this.props.labelContainerStyle]}>
          <Text style={[styles.label, this.props.labelStyle]}>{this.props.label}</Text>
        </View>
      );
    } else if (this.props.children) {
      labelContainer = (
        <View style={[styles.labelContainer, this.props.labelContainerStyle]}>
          {this.props.children}
        </View>
      )
    } else {
      labelContainer = null;
    }

    const containerStyle = [
        styles.container,
        this.props.containerStyle
    ];

    let container = (
      <View style={containerStyle}>
        {checkbox}
        {labelContainer}
      </View>
    );

    if (this.props.labelBefore) {
      container = (
        <View style={containerStyle}>
          {labelContainer}
          {checkbox}
        </View>
      );
    }

    if (this.props.highlight) {
      return (
        <TouchableHighlight onPress={this.onChange} underlayColor='white'>
          {container}
        </TouchableHighlight>
      );
    } else {
      return (
        <TouchableWithoutFeedback onPress={this.onChange}>
          {container}
        </TouchableWithoutFeedback>
      );
    }
  }
});

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    alignItems: 'center',
    marginBottom: 5,
  },
  labelContainer: {
    marginLeft: 10,
    marginRight: 10
  },
  label: {
{'fraction_non_alphanumeric': 0.11545561335794596, 'fraction_numerical': 0.0018459473065950663, 'mean_word_length': 2.520378027170703, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '5492442', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1733, 'n_words': 337}