options-wrap.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use client'
  2. import { useBoolean } from 'ahooks'
  3. import type { FC } from 'react'
  4. import React, { useEffect } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import cn from '@/utils/classnames'
  7. import { Settings04 } from '@/app/components/base/icons/src/vender/line/general'
  8. import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
  9. const I18N_PREFIX = 'datasetCreation.stepOne.website'
  10. type Props = {
  11. className?: string
  12. children: React.ReactNode
  13. controlFoldOptions?: number
  14. }
  15. const OptionsWrap: FC<Props> = ({
  16. className = '',
  17. children,
  18. controlFoldOptions,
  19. }) => {
  20. const { t } = useTranslation()
  21. const [fold, {
  22. toggle: foldToggle,
  23. setTrue: foldHide,
  24. }] = useBoolean(false)
  25. useEffect(() => {
  26. if (controlFoldOptions)
  27. foldHide()
  28. // eslint-disable-next-line react-hooks/exhaustive-deps
  29. }, [controlFoldOptions])
  30. return (
  31. <div className={cn(className, !fold ? 'mb-0' : 'mb-3')}>
  32. <div
  33. className='flex justify-between items-center h-[26px] py-1 cursor-pointer select-none'
  34. onClick={foldToggle}
  35. >
  36. <div className='flex items-center text-gray-700'>
  37. <Settings04 className='mr-1 w-4 h-4' />
  38. <div className='text-[13px] font-semibold text-gray-800 uppercase'>{t(`${I18N_PREFIX}.options`)}</div>
  39. </div>
  40. <ChevronRight className={cn(!fold && 'rotate-90', 'w-4 h-4 text-gray-500')} />
  41. </div>
  42. {!fold && (
  43. <div className='mb-4'>
  44. {children}
  45. </div>
  46. )}
  47. </div>
  48. )
  49. }
  50. export default React.memo(OptionsWrap)