field.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import Input from './input'
  5. import cn from '@/utils/classnames'
  6. import Tooltip from '@/app/components/base/tooltip'
  7. type Props = {
  8. className?: string
  9. label: string
  10. labelClassName?: string
  11. value: string | number
  12. onChange: (value: string | number) => void
  13. isRequired?: boolean
  14. placeholder?: string
  15. isNumber?: boolean
  16. tooltip?: string
  17. }
  18. const Field: FC<Props> = ({
  19. className,
  20. label,
  21. labelClassName,
  22. value,
  23. onChange,
  24. isRequired = false,
  25. placeholder = '',
  26. isNumber = false,
  27. tooltip,
  28. }) => {
  29. return (
  30. <div className={cn(className)}>
  31. <div className='flex py-[7px]'>
  32. <div className={cn(labelClassName, 'flex items-center h-[18px] text-[13px] font-medium text-gray-900')}>{label} </div>
  33. {isRequired && <span className='ml-0.5 text-xs font-semibold text-[#D92D20]'>*</span>}
  34. {tooltip && (
  35. <Tooltip
  36. popupContent={
  37. <div className='w-[200px]'>{tooltip}</div>
  38. }
  39. triggerClassName='ml-0.5 w-4 h-4'
  40. />
  41. )}
  42. </div>
  43. <Input
  44. value={value}
  45. onChange={onChange}
  46. placeholder={placeholder}
  47. isNumber={isNumber}
  48. />
  49. </div>
  50. )
  51. }
  52. export default React.memo(Field)