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. } from '@remixicon/react'
  7. import { useBoolean } from 'ahooks'
  8. import type { DefaultTFuncReturn } from 'i18next'
  9. import cn from '@/utils/classnames'
  10. import Tooltip from '@/app/components/base/tooltip'
  11. type Props = {
  12. className?: string
  13. title: JSX.Element | string | DefaultTFuncReturn
  14. tooltip?: React.ReactNode
  15. isSubTitle?: boolean
  16. supportFold?: boolean
  17. children?: JSX.Element | string | null
  18. operations?: JSX.Element
  19. inline?: boolean
  20. }
  21. const Field: FC<Props> = ({
  22. className,
  23. title,
  24. isSubTitle,
  25. tooltip,
  26. children,
  27. operations,
  28. inline,
  29. supportFold,
  30. }) => {
  31. const [fold, {
  32. toggle: toggleFold,
  33. }] = useBoolean(true)
  34. return (
  35. <div className={cn(className, inline && 'flex justify-between items-center w-full')}>
  36. <div
  37. onClick={() => supportFold && toggleFold()}
  38. className={cn('flex justify-between items-center', supportFold && 'cursor-pointer')}>
  39. <div className='flex items-center h-6'>
  40. <div className={cn(isSubTitle ? 'system-xs-medium-uppercase text-text-tertiary' : 'system-sm-semibold-uppercase text-text-secondary')}>{title}</div>
  41. {tooltip && (
  42. <Tooltip
  43. popupContent={tooltip}
  44. popupClassName='ml-1'
  45. triggerClassName='w-4 h-4 ml-1'
  46. />
  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(Field)