field.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. import { useBoolean } from 'ahooks'
  6. import type { DefaultTFuncReturn } from 'i18next'
  7. import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
  8. import TooltipPlus from '@/app/components/base/tooltip-plus'
  9. import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
  10. type Props = {
  11. className?: string
  12. title: JSX.Element | string | DefaultTFuncReturn
  13. tooltip?: string
  14. supportFold?: boolean
  15. children?: JSX.Element | string | null
  16. operations?: JSX.Element
  17. inline?: boolean
  18. }
  19. const Filed: FC<Props> = ({
  20. className,
  21. title,
  22. tooltip,
  23. children,
  24. operations,
  25. inline,
  26. supportFold,
  27. }) => {
  28. const [fold, {
  29. toggle: toggleFold,
  30. }] = useBoolean(true)
  31. return (
  32. <div className={cn(className, inline && 'flex justify-between items-center')}>
  33. <div
  34. onClick={() => supportFold && toggleFold()}
  35. className={cn('flex justify-between items-center', supportFold && 'cursor-pointer')}>
  36. <div className='flex items-center h-6'>
  37. <div className='text-[13px] font-medium text-gray-700 uppercase'>{title}</div>
  38. {tooltip && (
  39. <TooltipPlus popupContent={
  40. <div className='w-[120px]'>
  41. {tooltip}
  42. </div>}>
  43. <HelpCircle className='w-3.5 h-3.5 ml-0.5 text-gray-400' />
  44. </TooltipPlus>
  45. )}
  46. </div>
  47. <div className='flex'>
  48. {operations && <div>{operations}</div>}
  49. {supportFold && (
  50. <ChevronRight className='w-3.5 h-3.5 text-gray-500 cursor-pointer transform transition-transform' style={{ transform: fold ? 'rotate(0deg)' : 'rotate(90deg)' }} />
  51. )}
  52. </div>
  53. </div>
  54. {children && (!supportFold || (supportFold && !fold)) && <div className={cn(!inline && 'mt-1')}>{children}</div>}
  55. </div>
  56. )
  57. }
  58. export default React.memo(Filed)