field.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import {
  5. RiArrowDownSLine,
  6. RiQuestionLine,
  7. } from '@remixicon/react'
  8. import { useBoolean } from 'ahooks'
  9. import type { DefaultTFuncReturn } from 'i18next'
  10. import cn from '@/utils/classnames'
  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='system-sm-semibold-uppercase text-text-secondary'>{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-text-quaternary' />
  46. </TooltipPlus>
  47. )}
  48. </div>
  49. <div className='flex'>
  50. {operations && <div>{operations}</div>}
  51. {supportFold && (
  52. <RiArrowDownSLine className='w-4 h-4 text-text-tertiary cursor-pointer transform transition-transform' style={{ transform: fold ? 'rotate(-90deg)' : 'rotate(0deg)' }} />
  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)