field.tsx 1.4 KB

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