field.tsx 1.9 KB

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