inputField.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import FormField from 'sentry/components/deprecatedforms/formField';
  2. type InputFieldProps = FormField['props'] & {
  3. autoComplete?: string;
  4. inputStyle?: object;
  5. min?: number;
  6. onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
  7. onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
  8. onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
  9. onKeyPress?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
  10. placeholder?: string;
  11. step?: 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. step={this.props.step}
  37. />
  38. );
  39. }
  40. getClassName() {
  41. return 'control-group';
  42. }
  43. getType(): string {
  44. throw new Error('Must be implemented by child.');
  45. }
  46. }
  47. export default InputField;