<commit_before>import React from 'react';
import DatePicker from 'react-toolbox/lib/date_picker';
import { Date as SugarDate } from 'sugar';
import asSchemaField from './asSchemaField';
import { formShape } from './schemaFormPropTypes';

class DateField extends React.Component {

  constructor(props) {
    super(props);

    this.state = {
      minDate: props.formField.min ? SugarDate.create(props.formField.min) : null,
      maxDate: props.formField.max ? SugarDate.create(props.formField.max) : null,
      active: false,
    };
  }

  /* All these handlers and state.active management are a workaround for this bug:
   https://github.com/react-toolbox/react-toolbox/issues/930 */

  onClick = () => {
    this.setState({ active: true });
  };

  onDismiss = () => {
    this.setState({ active: false });
  };

  onChange = (...args) => {
    this.setState({ active: false });
    this.props.onChange(...args);
  };

  render() {
    const { formField, disabled, onChange, ...others } = this.props; // eslint-disable-line no-unused-vars
    return (
      <DatePicker
        {...others}
        onClick={this.onClick}
        onDismiss={this.onDismiss}
        onChange={this.onChange}
        active={this.state.active}
        readonly={disabled}
        autoOk
        label={formField.description}
        placeholder={formField.placeholder}
        inputFormat={(value) => value.toLocaleDateString()}
        minDate={this.state.minDate}
        maxDate={this.state.maxDate}
        {...formField.props}
      />
    );
  }
}

DateField.propTypes = {
  formField: formShape,
  disabled: React.PropTypes.bool,
  onChange: React.PropTypes.func,<commit_msg>refactor: remove workaround for React-Toolbox bug now included in 1.3.0+ and simplify DateField to be a functional component<commit_after>import React from 'react';
import DatePicker from 'react-toolbox/lib/date_picker';
import { Date as SugarDate } from 'sugar';
import asSchemaField from './asSchemaField';
import { formShape } from './schemaFormPropTypes';

const DateField = (props) => {
  const { formField, readOnly, ...others } = props;
  const minDate = formField.min ? SugarDate.create(formField.min) : null;
  const maxDate = formField.max ? SugarDate.create(formField.max) : null;
  return (
    <DatePicker
      {...others}
      readonly={readOnly}
      autoOk
      label={formField.description}
      placeholder={formField.placeholder}
      inputFormat={(value) => value.toLocaleDateString()}
      minDate={minDate}
      maxDate={maxDate}
      {...formField.props}
    />
  );
};

DateField.propTypes = {
  formField: formShape,
  readOnly: React.PropTypes.bool,
{'fraction_non_alphanumeric': 0.13617502829121086, 'fraction_numerical': 0.002263296869105998, 'mean_word_length': 3.130841121495327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 1, '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': '1828338', 'n_tokens_mistral': 807, 'n_tokens_neox': 804, 'n_words': 171}