<commit_before>import React from 'react';

// Helpers for use with react-final-form-hooks

export function RadioInput({ field, value, ...additionalProps }) {
  const props = { ...field.input, checked: field.input.value === value, value, ...additionalProps };
  return <input type="radio" {...props} />;
}

export function CheckboxInput({ field, ...additionalProps }) {
  const props = { ...field.input, checked: field.input.value, ...additionalProps };
  return <input type="checkbox" {...props} />;
}

export function groupErrClass(field, whenTouched = false, baseClass = 'form-group') {
  return (
    baseClass +
    (field.meta.error !== undefined && (!whenTouched || field.meta.touched) ? ' has-error' : '')
  );
}

export function errorMessage(field, whenTouched = false) {
  return (
    field.meta.error !== undefined &&
    (!whenTouched || field.meta.touched) && <p className="help-block">{field.meta.error}</p>
  );
}

export function shouldBe(test, message = '') {
  return test ? undefined : message;
}
<commit_msg>Add component to handle checkbox that selects subset from values<commit_after>import React, { useCallback } from 'react';
import { without } from 'lodash';

// Helpers for use with react-final-form-hooks

export function RadioInput({ field, value, ...additionalProps }) {
  const props = { ...field.input, checked: field.input.value === value, value, ...additionalProps };
  return <input type="radio" {...props} />;
}

export function CheckboxInput({ field, ...additionalProps }) {
  const props = { ...field.input, checked: field.input.value, ...additionalProps };
  return <input type="checkbox" {...props} />;
}

/**
 * The field.input.value is array, the checked checkbox means the given value is
 * in this array.
 */
export function CheckboxInputMulti({ field, value, ...additionalProps }) {
  const checked = field.input.value.includes(value);
  const onChange = useCallback(() => {
    const vals = field.input.value;
    if (vals.includes(value)) {
      field.input.onChange(without(vals, value));
    } else {
      field.input.onChange([...vals, value]);
    }
  }, [field.input, value]);
  const props = { ...field.input, checked, value, onChange, ...additionalProps };
  return <input type="checkbox" {...props} />;
}

export function groupErrClass(field, whenTouched = false, baseClass = 'form-group') {
  return (
    baseClass +
    (field.meta.error !== undefined && (!whenTouched || field.meta.touched) ? ' has-error' : '')
  );
}

export function errorMessage(field, whenTouched = false) {
  return (
    field.meta.error !== undefined &&
    (!whenTouched || field.meta.touched) && <p className="help-block">{field.meta.error}</p>
  );
}

export function shouldBe(test, message = '') {
  return test ? undefined : message;
}

{'fraction_non_alphanumeric': 0.169009009009009, 'fraction_numerical': 0.0, 'mean_word_length': 3.7130730050933787, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, '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': '1052143', 'n_tokens_mistral': 843, 'n_tokens_neox': 820, 'n_words': 216}