You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. const minNum = Number.parseFloat(`${min}`)
  29. const maxNum = Number.parseFloat(`${max}`)
  30. if (!isNaN(minNum) && Number.parseFloat(v) < minNum) {
  31. onChange(`${min}`)
  32. return
  33. }
  34. if (!isNaN(maxNum) && Number.parseFloat(v) > maxNum)
  35. onChange(`${max}`)
  36. }
  37. return (
  38. <div className='relative'>
  39. <input
  40. tabIndex={0}
  41. // Do not set autoComplete for security - prevents browser from storing sensitive API keys
  42. className={`
  43. block h-8 w-full appearance-none rounded-lg border border-transparent bg-components-input-bg-normal px-3 text-sm
  44. text-components-input-text-filled caret-primary-600 outline-none
  45. placeholder:text-sm placeholder:text-text-tertiary
  46. hover:border-components-input-border-hover hover:bg-components-input-bg-hover focus:border-components-input-border-active
  47. focus:bg-components-input-bg-active focus:shadow-xs
  48. ${validated ? 'pr-[30px]' : ''}
  49. ${className || ''}
  50. `}
  51. placeholder={placeholder || ''}
  52. onChange={e => onChange(e.target.value)}
  53. onBlur={e => toLimit(e.target.value)}
  54. onFocus={onFocus}
  55. value={value}
  56. disabled={disabled}
  57. type={type}
  58. min={min}
  59. max={max}
  60. />
  61. {validated && (
  62. <div className='absolute right-2.5 top-2.5'>
  63. <CheckCircle className='h-4 w-4 text-[#039855]' />
  64. </div>
  65. )}
  66. </div>
  67. )
  68. }
  69. export default Input