Input.tsx 938 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import { RegisterOptions, useFormContext } from 'react-hook-form';
  3. import SearchIcon from 'components/common/Icons/SearchIcon';
  4. import * as S from './Input.styled';
  5. export interface InputProps
  6. extends React.InputHTMLAttributes<HTMLInputElement>,
  7. Omit<S.InputProps, 'hasLeftIcon'> {
  8. name?: string;
  9. hookFormOptions?: RegisterOptions;
  10. search?: boolean;
  11. }
  12. const Input: React.FC<InputProps> = ({
  13. name,
  14. hookFormOptions,
  15. search,
  16. inputSize = 'L',
  17. ...rest
  18. }) => {
  19. const methods = useFormContext();
  20. return (
  21. <S.Wrapper>
  22. {search && <SearchIcon />}
  23. {name ? (
  24. <S.Input
  25. inputSize={inputSize}
  26. {...methods.register(name, { ...hookFormOptions })}
  27. hasLeftIcon={!!search}
  28. {...rest}
  29. />
  30. ) : (
  31. <S.Input inputSize={inputSize} hasLeftIcon={!!search} {...rest} />
  32. )}
  33. </S.Wrapper>
  34. );
  35. };
  36. export default Input;