All files / src/components/Form/TextInput index.jsx

77.78% Statements 7/9
100% Branches 0/0
66.67% Functions 4/6
77.78% Lines 7/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                3x 4x       4x 4x 8x 4x                             3x                        
import styles from './style.postcss';
 
import React from 'react';
import { HOC as formsyDecorator } from 'formsy-react';
import classnames from 'classnames';
import Field from '../Field';
import PropTypes from 'prop-types';
 
const TextInput = (props) => {
  const classes = classnames(styles.TextInput,
      { [styles.__required]: props.showRequired() },
      { [styles.__error]: props.showError() });
 
  return <Field label={props.label}
      getErrorMessage={() => props.getErrorMessage()}
      showError={() => props.showError()}
      showRequired={() => props.showRequired()}
      useLabel>
    <input type="text"
        className={classes}
        name={props.name}
        disabled={props.disabled}
        value={props.getValue()}
        onChange={(e) => handleChange(e)} />
  </Field>;
 
  function handleChange(e) {
    props.setValue(e.currentTarget.value);
  }
};
 
TextInput.propTypes = {
  getErrorMessage: PropTypes.func.isRequired,
  showRequired: PropTypes.func.isRequired,
  name: PropTypes.string,
  disabled: PropTypes.bool,
  getValue: PropTypes.func.isRequired,
  setValue: PropTypes.func.isRequired,
  showError: PropTypes.func.isRequired,
  label: PropTypes.string,
};
 
export default formsyDecorator(TextInput);