You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

40 lines
992 B

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. function TextInput(props) {
  4. let wrapperClass = "form-group";
  5. if(props.error.length > 0){
  6. wrapperClass += "has-error";
  7. }
  8. return (
  9. <div className={wrapperClass}>
  10. <label htmlFor={props.id}>{props.label}</label>
  11. <div className="field">
  12. <input
  13. id={props.id}
  14. type="text"
  15. onChange={props.onChange}
  16. name={props.name}
  17. className="form-control"
  18. value={props.value}
  19. />
  20. </div>
  21. { props.error && <div className="alert alert-danger">{props.error}</div>}
  22. </div>
  23. )
  24. }
  25. TextInput.propTypes = {
  26. id: PropTypes.string.isRequired,
  27. name: PropTypes.string.isRequired,
  28. label: PropTypes.string.isRequired,
  29. onChange: PropTypes.func.isRequired,
  30. value: PropTypes.string,
  31. error: PropTypes.string
  32. };
  33. TextInput.defaultProps = {
  34. error: ""
  35. };
  36. export default TextInput;