field.tsx 1.8 KB

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