Input.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import clsx from 'clsx';
  3. interface IProps {
  4. placeholder?: string;
  5. error?: string;
  6. label?: string;
  7. className?: string;
  8. isInvalid?: boolean;
  9. type?: HTMLInputElement['type'];
  10. onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
  11. name?: string;
  12. onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
  13. disabled?: boolean;
  14. value?: string;
  15. }
  16. export const Input = React.forwardRef<HTMLInputElement, IProps>(({ onChange, onBlur, name, label, placeholder, error, type = 'text', className, value, isInvalid, disabled }, ref) => (
  17. <div className={clsx(className)}>
  18. {label && (
  19. <label htmlFor={name} className="form-label">
  20. {label}
  21. </label>
  22. )}
  23. <input
  24. disabled={disabled}
  25. name={name}
  26. id={name}
  27. onBlur={onBlur}
  28. onChange={onChange}
  29. value={value}
  30. type={type}
  31. ref={ref}
  32. className={clsx('form-control', { 'is-invalid is-invalid-lite': error || isInvalid })}
  33. placeholder={placeholder}
  34. />
  35. {error && <div className="invalid-feedback">{error}</div>}
  36. </div>
  37. ));