index.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { forwardRef } from 'react';
  2. import { Input } from './styled';
  3. type Props = {
  4. id?: string;
  5. name?: string;
  6. onChange?: (val: string) => void;
  7. onBlur?: () => void;
  8. value?: string | number;
  9. defaultValue?: string | number;
  10. placeholder?: string;
  11. disabled?: boolean;
  12. error?: boolean;
  13. shouldFitContainer?: boolean;
  14. };
  15. const InputBox = forwardRef<HTMLInputElement, Props>(
  16. ({ onChange, disabled = false, ...rest }: Props, ref) => {
  17. const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
  18. if (onChange && !disabled) {
  19. onChange(e.target.value);
  20. }
  21. };
  22. return (
  23. <Input
  24. data-testid="input"
  25. ref={ref}
  26. disabled={disabled}
  27. onChange={handleChange}
  28. {...rest}
  29. />
  30. );
  31. },
  32. );
  33. InputBox.defaultProps = {
  34. id: '',
  35. name: '',
  36. onChange: () => {
  37. // do something
  38. },
  39. onBlur: () => {
  40. // do something
  41. },
  42. value: '',
  43. defaultValue: undefined,
  44. placeholder: '',
  45. disabled: false,
  46. error: false,
  47. shouldFitContainer: false,
  48. };
  49. export default InputBox;