wwf
3 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use client'
import { ChevronDoubleDownIcon } from '@heroicons/react/20/solid'
import type { FC } from 'react'
import { useTranslation } from 'react-i18next'
import React, { useCallback } from 'react'
import Tooltip from '@/app/components/base/tooltip'
 
const I18N_PREFIX = 'app.tracing'
 
type Props = {
  isFold: boolean
  onFoldChange: (isFold: boolean) => void
}
 
const ToggleFoldBtn: FC<Props> = ({
  isFold,
  onFoldChange,
}) => {
  const { t } = useTranslation()
 
  const handleFoldChange = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
    e.stopPropagation()
    onFoldChange(!isFold)
  }, [isFold, onFoldChange])
  return (
    // text-[0px] to hide spacing between tooltip elements
    <div className='shrink-0 cursor-pointer text-[0px]' onClick={handleFoldChange}>
      <Tooltip
        popupContent={t(`${I18N_PREFIX}.${isFold ? 'expand' : 'collapse'}`)}
      >
        {isFold && (
          <div className='p-1 rounded-md text-gray-500 hover:text-gray-800 hover:bg-black/5'>
            <ChevronDoubleDownIcon className='w-4 h-4' />
          </div>
        )}
        {!isFold && (
          <div className='p-2 rounded-lg text-gray-500 border-[0.5px] border-gray-200 hover:text-gray-800 hover:bg-black/5'>
            <ChevronDoubleDownIcon className='w-4 h-4 transform rotate-180' />
          </div>
        )}
      </Tooltip>
    </div>
  )
}
export default React.memo(ToggleFoldBtn)