index.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. type="text"
  25. data-testid="input"
  26. ref={ref}
  27. disabled={disabled}
  28. onChange={handleChange}
  29. {...rest}
  30. />
  31. );
  32. },
  33. );
  34. InputBox.defaultProps = {
  35. id: '',
  36. name: '',
  37. onChange: () => {
  38. // do something
  39. },
  40. onBlur: () => {
  41. // do something
  42. },
  43. value: undefined,
  44. defaultValue: undefined,
  45. placeholder: '',
  46. disabled: false,
  47. error: false,
  48. shouldFitContainer: false,
  49. };
  50. export default InputBox;