<commit_before>import React from 'react';
import rcUtil from 'rc-util';

const cx = rcUtil.classSet;

function prefixClsFn(prefixCls, ...args) {
  return args.map((s)=> {
    return prefixCls + '-' + s;
  }).join(' ');
}

class FormItem extends React.Component {
  renderHelp() {
    const prefixCls = this.props.prefixCls;
    return this.props.help ? (
      <div className={prefixClsFn(prefixCls, 'explain')} key="help">
        {this.props.help}
      </div>
    ) : null;
  }

  renderValidateWrapper(children) {
    if (this.props.validateStatus) {
      const classes = cx(
        {
          'has-feedback': this.props.hasFeedback,
          'has-success': this.props.validateStatus === 'success',
          'has-warning': this.props.validateStatus === 'warning',
          'has-error': this.props.validateStatus === 'error',
          'is-validating': this.props.validateStatus === 'validating',
        }
      );
      return (
        <div className={classes}>
          {children}
        </div>
      );
    }
    return children;
  }

  renderWrapper(children) {
    return this.props.wrapperClassName ? (
      <div className={this.props.wrapperClassName} key="wrapper">
        {children}
      </div>
    ) : children;
  }

  renderLabel() {
    const labelClassName = this.props.labelClassName;
    const required = this.props.required ? 'required' : '';

    return this.props.label ? (
      <label htmlFor={this.props.id} className={labelClassName} required={required} key="label">
        {this.props.label}
      </label>
    ) : '';
  }

  renderChildren() {
    return [
      this.renderLabel(),
      this.renderWrapper(
        this.renderValidateWrapper(
          [
            this.props.children,
            this.renderHelp(),
          ]
        )
      ),
    ];
  }

  renderFormItem(children) {
    const prefixCls = this.props.prefixCls;
    const itemClassName = {
      [`${prefixCls}-item`]: true,
      [`${prefixCls}-item-compact`]: this.props.isCompact,
    };

    return (
      <div className={cx(itemClassName)} key="form-item">
        {children}
      </div>
    );
  }

  render() {
    const children = this.renderChildren();
    return this.renderFormItem(children);
  }
}

FormItem.propTypes = {
  prefixCls: React.PropTypes.string,
  label: React.PropTypes.node,
  labelClassName: React.PropTypes.string,
  help: React.PropTypes.node,
  validateStatus: React.PropTypes.oneOf(['success', 'warning', 'error', 'validating']),
  hasFeedback: React.PropTypes.bool,
  wrapperClassName: React.PropTypes.string,
  isCompact: React.PropTypes.bool,
  className: React.PropTypes.string,
  children: React.PropTypes.any,
};

FormItem.defaultProps = {
  hasFeedback: false,
  isCompact: false,
  required: false,
  prefixCls: 'ant-form',
};
<commit_msg>去除 isCompact 属性，将是否添加 ant-form-item-compact 类在程序内部判断。<commit_after>import React from 'react';
import rcUtil from 'rc-util';

const cx = rcUtil.classSet;

function prefixClsFn(prefixCls, ...args) {
  return args.map((s)=> {
    return prefixCls + '-' + s;
  }).join(' ');
}

class FormItem extends React.Component {
  renderHelp() {
    const prefixCls = this.props.prefixCls;
    return this.props.help ? (
      <div className={prefixClsFn(prefixCls, 'explain')} key="help">
        {this.props.help}
      </div>
    ) : null;
  }

  renderValidateWrapper(children) {
    if (this.props.validateStatus) {
      const classes = cx(
        {
          'has-feedback': this.props.hasFeedback,
          'has-success': this.props.validateStatus === 'success',
          'has-warning': this.props.validateStatus === 'warning',
          'has-error': this.props.validateStatus === 'error',
          'is-validating': this.props.validateStatus === 'validating',
        }
      );
      return (
        <div className={classes}>
          {children}
        </div>
      );
    }
    return children;
  }

  renderWrapper(children) {
    return this.props.wrapperClassName ? (
      <div className={this.props.wrapperClassName} key="wrapper">
        {children}
      </div>
    ) : children;
  }

  renderLabel() {
    const labelClassName = this.props.labelClassName;
    const required = this.props.required ? 'required' : '';

    return this.props.label ? (
      <label htmlFor={this.props.id} className={labelClassName} required={required} key="label">
        {this.props.label}
      </label>
    ) : '';
  }

  renderChildren() {
    return [
      this.renderLabel(),
      this.renderWrapper(
        this.renderValidateWrapper(
          [
            this.props.children,
            this.renderHelp(),
          ]
        )
      ),
    ];
  }

  // 判断是否要 `.ant-form-item-compact` 样式类
  _isCompact(children) {
    const compactControls = ['checkbox', 'radio', 'radio-group', 'static', 'file'];
    let isCompact = false;

    if (!Array.isArray(children)) {
      children = [children];
    }
    children.map((child, i) => {
      const type = child.props && child.props.type;
      let prefixCls = child.props && child.props.prefixCls;
      prefixCls = prefixCls ? prefixCls.substring(prefixCls.indexOf('-') + 1) : '';

      if ((type && compactControls.indexOf(type) > -1) || (prefixCls && compactControls.indexOf(prefixCls) > -1) ) {
        isCompact = true;
      } else if (child.props && typeof child.props.children === 'object') {
        isCompact = this._isCompact(child.props.children);
      }
    });

    return isCompact;
  }

  renderFormItem(children) {
    const props = this.props;
    const prefixCls = props.prefixCls;
    const itemClassName = {
      [`${prefixCls}-item`]: true,
      [`${prefixCls}-item-compact`]:  this._isCompact(props.children),
    };

    return (
      <div className={cx(itemClassName)} key="form-item">
        {children}
      </div>
    );
  }

  render() {
    const children = this.renderChildren();
    return this.renderFormItem(children);
  }
}

FormItem.propTypes = {
  prefixCls: React.PropTypes.string,
  label: React.PropTypes.node,
  labelClassName: React.PropTypes.string,
  help: React.PropTypes.node,
  validateStatus: React.PropTypes.oneOf(['success', 'warning', 'error', 'validating']),
  hasFeedback: React.PropTypes.bool,
  wrapperClassName: React.PropTypes.string,
  className: React.PropTypes.string,
  children: React.PropTypes.any,
};

FormItem.defaultProps = {
  hasFeedback: false,
  required: false,
  prefixCls: 'ant-form',
};

{'fraction_non_alphanumeric': 0.1494700748129676, 'fraction_numerical': 0.0004675810473815461, 'mean_word_length': 2.6836969001148105, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 28, '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': '6316586', 'n_tokens_mistral': 2043, 'n_tokens_neox': 2032, 'n_words': 358}