Input.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type { FC } from 'react'
  2. import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
  3. type InputProps = {
  4. value?: string
  5. onChange: (v: string) => void
  6. onFocus?: () => void
  7. placeholder?: string
  8. validated?: boolean
  9. className?: string
  10. disabled?: boolean
  11. type?: string
  12. min?: number
  13. max?: number
  14. }
  15. const Input: FC<InputProps> = ({
  16. value,
  17. onChange,
  18. onFocus,
  19. placeholder,
  20. validated,
  21. className,
  22. disabled,
  23. type = 'text',
  24. min,
  25. max,
  26. }) => {
  27. const toLimit = (v: string) => {
  28. if (min !== undefined && parseFloat(v) < min) {
  29. onChange(`${min}`)
  30. return
  31. }
  32. if (max !== undefined && parseFloat(v) > max)
  33. onChange(`${max}`)
  34. }
  35. return (
  36. <div className='relative'>
  37. <input
  38. tabIndex={-1}
  39. className={`
  40. block px-3 w-full h-9 bg-gray-100 text-sm rounded-lg border border-transparent
  41. appearance-none outline-none caret-primary-600
  42. hover:border-[rgba(0,0,0,0.08)] hover:bg-gray-50
  43. focus:bg-white focus:border-gray-300 focus:shadow-xs
  44. placeholder:text-sm placeholder:text-gray-400
  45. ${validated && 'pr-[30px]'}
  46. ${className}
  47. `}
  48. placeholder={placeholder || ''}
  49. onChange={e => onChange(e.target.value)}
  50. onBlur={e => toLimit(e.target.value)}
  51. onFocus={onFocus}
  52. value={value || ''}
  53. disabled={disabled}
  54. type={type}
  55. min={min}
  56. max={max}
  57. />
  58. {
  59. validated && (
  60. <div className='absolute top-2.5 right-2.5'>
  61. <CheckCircle className='w-4 h-4 text-[#039855]' />
  62. </div>
  63. )
  64. }
  65. </div>
  66. )
  67. }
  68. export default Input