inputField.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as React from 'react';
  2. import FormField from 'app/components/forms/formField';
  3. type InputFieldProps = FormField['props'] & {
  4. placeholder?: string;
  5. inputStyle?: object;
  6. onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
  7. onKeyPress?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
  8. onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
  9. onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
  10. autoComplete?: string;
  11. min?: number;
  12. };
  13. class InputField<
  14. Props extends InputFieldProps = InputFieldProps,
  15. State extends FormField['state'] = FormField['state']
  16. > extends FormField<Props, State> {
  17. getField() {
  18. return (
  19. <input
  20. id={this.getId()} // TODO(Priscila): check the reason behind this. We are getting warnings if we have 2 or more fields with the same name, for instance in the DATA PRIVACY RULES
  21. type={this.getType()}
  22. className="form-control"
  23. autoComplete={this.props.autoComplete}
  24. placeholder={this.props.placeholder}
  25. onChange={this.onChange}
  26. disabled={this.props.disabled}
  27. name={this.props.name}
  28. required={this.props.required}
  29. value={this.state.value as string | number} // can't pass in boolean here
  30. style={this.props.inputStyle}
  31. onBlur={this.props.onBlur}
  32. onFocus={this.props.onFocus}
  33. onKeyPress={this.props.onKeyPress}
  34. onKeyDown={this.props.onKeyDown}
  35. min={this.props.min}
  36. />
  37. );
  38. }
  39. getClassName() {
  40. return 'control-group';
  41. }
  42. getType(): string {
  43. throw new Error('Must be implemented by child.');
  44. }
  45. }
  46. export default InputField;