index.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { forwardRef } from 'react';
  2. import { TextArea } 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<HTMLTextAreaElement, Props>(
  16. ({ onChange, disabled = false, ...rest }: Props, ref) => {
  17. const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {
  18. if (onChange && !disabled) {
  19. onChange(e.target.value);
  20. }
  21. };
  22. return (
  23. <TextArea
  24. ref={ref}
  25. disabled={disabled}
  26. onChange={handleChange}
  27. {...rest}
  28. />
  29. );
  30. },
  31. );
  32. InputBox.defaultProps = {
  33. id: '',
  34. name: '',
  35. onChange: () => {
  36. // do something
  37. },
  38. onBlur: () => {
  39. // do something
  40. },
  41. value: '',
  42. defaultValue: undefined,
  43. placeholder: '',
  44. disabled: false,
  45. error: false,
  46. shouldFitContainer: false,
  47. };
  48. export default InputBox;