Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Input.tsx 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. autoComplete="new-password"
  41. tabIndex={0}
  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. {
  62. validated && (
  63. <div className='absolute right-2.5 top-2.5'>
  64. <CheckCircle className='h-4 w-4 text-[#039855]' />
  65. </div>
  66. )
  67. }
  68. </div>
  69. )
  70. }
  71. export default Input