index.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use client'
  2. import React, { useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { debounce } from 'lodash-es'
  5. import copy from 'copy-to-clipboard'
  6. import Tooltip from '../tooltip'
  7. import {
  8. Clipboard,
  9. ClipboardCheck,
  10. } from '@/app/components/base/icons/src/vender/line/files'
  11. type Props = {
  12. content: string
  13. }
  14. const prefixEmbedded = 'appOverview.overview.appInfo.embedded'
  15. export const CopyIcon = ({ content }: Props) => {
  16. const { t } = useTranslation()
  17. const [isCopied, setIsCopied] = useState<boolean>(false)
  18. const onClickCopy = debounce(() => {
  19. copy(content)
  20. setIsCopied(true)
  21. }, 100)
  22. const onMouseLeave = debounce(() => {
  23. setIsCopied(false)
  24. }, 100)
  25. return (
  26. <Tooltip
  27. popupContent={
  28. (isCopied
  29. ? t(`${prefixEmbedded}.copied`)
  30. : t(`${prefixEmbedded}.copy`)) || ''
  31. }
  32. >
  33. <div onMouseLeave={onMouseLeave}>
  34. {!isCopied
  35. ? (
  36. <Clipboard className='mx-1 w-3 h-3 text-gray-500 cursor-pointer' onClick={onClickCopy} />
  37. )
  38. : (
  39. <ClipboardCheck className='mx-1 w-3 h-3 text-gray-500' />
  40. )
  41. }
  42. </div>
  43. </Tooltip>
  44. )
  45. }
  46. export default CopyIcon