<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { enableUniqueIds } from 'react-html-id';
import classNames from 'classnames';
import FieldRequiredFeedback from './FieldRequiredFeedback';
import MarkdownInput from '../../BuiltInFormControls/MarkdownInput';
import RequiredIndicator from './RequiredIndicator';

class FreeTextItem extends React.Component {
  static propTypes = {
    formItem: PropTypes.shape({
      identifier: PropTypes.string.isRequired,
      properties: PropTypes.shape({
        caption: PropTypes.string.isRequired,
        format: PropTypes.string,
      }).isRequired,
    }).isRequired,
    value: PropTypes.string,
    valueInvalid: PropTypes.bool,
    onChange: PropTypes.func.isRequired,
    onInteract: PropTypes.func.isRequired,
  };

  static defaultProps = {
    value: null,
    valueInvalid: false,
  };

  constructor(props) {
    super(props);
    enableUniqueIds(this);
  }

  userDidInteract = () => {
    this.props.onInteract(this.props.formItem.identifier);
  }

  valueDidChange = (event) => {
    this.props.onChange(event.target.value);
    this.userDidInteract();
  }

  markdownDidChange = (newValue) => {
    this.props.onChange(newValue);
    this.userDidInteract();
  }

  renderLabel = (formItem, domId) => (
    <label htmlFor={domId} className="form-item-label">
      <span
          // eslint-disable-next-line react/no-danger
        dangerouslySetInnerHTML={{ __html: formItem.properties.caption }}
      />
      <RequiredIndicator formItem={formItem} />
    </label>
  )

  renderInput = (formItem, domId) => {
    if (formItem.properties.format === 'markdown') {
      return (
        <MarkdownInput
          value={this.props.value || ''}
          onChange={this.markdownDidChange}
          onBlur={this.userDidInteract}
          lines={formItem.properties.lines}
          formControlClassName={classNames({ 'is-invalid': this.props.valueInvalid })}
        >
          <FieldRequiredFeedback valueInvalid={this.props.valueInvalid} />
        </MarkdownInput>
      );
    }
    if (formItem.lines === 1) {
      return (
        <input
          id={domId}
          type={formItem.properties.free_text_type || 'text'}
          className={classNames('form-control', { 'is-invalid': this.props.valueInvalid })}
          value={this.props.value || ''}
          onChange={this.valueDidChange}
          onBlur={this.userDidInteract}
        />
      );
    }
    return (
      <textarea
        id={domId}
        rows={formItem.properties.lines}
        className={classNames('form-control', { 'is-invalid': this.props.valueInvalid })}
        value={this.props.value || ''}
        onChange={this.valueDidChange}
        onBlur={this.userDidInteract}
      />
    );
  }

  render = () => {
    const { formItem } = this.props;
    const domId = this.nextUniqueId();
<commit_msg>Actually use single-line text inputs where appropriate<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { enableUniqueIds } from 'react-html-id';
import classNames from 'classnames';
import FieldRequiredFeedback from './FieldRequiredFeedback';
import MarkdownInput from '../../BuiltInFormControls/MarkdownInput';
import RequiredIndicator from './RequiredIndicator';

class FreeTextItem extends React.Component {
  static propTypes = {
    formItem: PropTypes.shape({
      identifier: PropTypes.string.isRequired,
      properties: PropTypes.shape({
        caption: PropTypes.string.isRequired,
        format: PropTypes.string,
      }).isRequired,
    }).isRequired,
    value: PropTypes.string,
    valueInvalid: PropTypes.bool,
    onChange: PropTypes.func.isRequired,
    onInteract: PropTypes.func.isRequired,
  };

  static defaultProps = {
    value: null,
    valueInvalid: false,
  };

  constructor(props) {
    super(props);
    enableUniqueIds(this);
  }

  userDidInteract = () => {
    this.props.onInteract(this.props.formItem.identifier);
  }

  valueDidChange = (event) => {
    this.props.onChange(event.target.value);
    this.userDidInteract();
  }

  markdownDidChange = (newValue) => {
    this.props.onChange(newValue);
    this.userDidInteract();
  }

  renderLabel = (formItem, domId) => (
    <label htmlFor={domId} className="form-item-label">
      <span
          // eslint-disable-next-line react/no-danger
        dangerouslySetInnerHTML={{ __html: formItem.properties.caption }}
      />
      <RequiredIndicator formItem={formItem} />
    </label>
  )

  renderInput = (formItem, domId) => {
    if (formItem.properties.format === 'markdown') {
      return (
        <MarkdownInput
          value={this.props.value || ''}
          onChange={this.markdownDidChange}
          onBlur={this.userDidInteract}
          lines={formItem.properties.lines}
          formControlClassName={classNames({ 'is-invalid': this.props.valueInvalid })}
        >
          <FieldRequiredFeedback valueInvalid={this.props.valueInvalid} />
        </MarkdownInput>
      );
    }
    if (formItem.properties.lines === 1) {
      return (
        <input
          id={domId}
          type={formItem.properties.free_text_type || 'text'}
          className={classNames('form-control', { 'is-invalid': this.props.valueInvalid })}
          value={this.props.value || ''}
          onChange={this.valueDidChange}
          onBlur={this.userDidInteract}
        />
      );
    }
    return (
      <textarea
        id={domId}
        rows={formItem.properties.lines}
        className={classNames('form-control', { 'is-invalid': this.props.valueInvalid })}
        value={this.props.value || ''}
        onChange={this.valueDidChange}
        onBlur={this.userDidInteract}
      />
    );
  }

  render = () => {
    const { formItem } = this.props;
    const domId = this.nextUniqueId();

{'fraction_non_alphanumeric': 0.13520933424845574, 'fraction_numerical': 0.00034317089910775565, 'mean_word_length': 2.7973941368078177, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '6885607', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1716, 'n_words': 280}