field.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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?: string
  15. supportFold?: boolean
  16. children?: JSX.Element | string | null
  17. operations?: JSX.Element
  18. inline?: boolean
  19. }
  20. const Filed: FC<Props> = ({
  21. className,
  22. title,
  23. tooltip,
  24. children,
  25. operations,
  26. inline,
  27. supportFold,
  28. }) => {
  29. const [fold, {
  30. toggle: toggleFold,
  31. }] = useBoolean(true)
  32. return (
  33. <div className={cn(className, inline && 'flex justify-between items-center w-full')}>
  34. <div
  35. onClick={() => supportFold && toggleFold()}
  36. className={cn('flex justify-between items-center', supportFold && 'cursor-pointer')}>
  37. <div className='flex items-center h-6'>
  38. <div className='system-sm-semibold-uppercase text-text-secondary'>{title}</div>
  39. {tooltip && (
  40. <Tooltip
  41. popupContent={tooltip}
  42. popupClassName='ml-1'
  43. triggerClassName='w-4 h-4 ml-1'
  44. />
  45. )}
  46. </div>
  47. <div className='flex'>
  48. {operations && <div>{operations}</div>}
  49. {supportFold && (
  50. <RiArrowDownSLine className='w-4 h-4 text-text-tertiary cursor-pointer transform transition-transform' style={{ transform: fold ? 'rotate(-90deg)' : 'rotate(0deg)' }} />
  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)