index.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use client'
  2. import { useState } from 'react'
  3. import { t } from 'i18next'
  4. import copy from 'copy-to-clipboard'
  5. import s from './style.module.css'
  6. import Tooltip from '@/app/components/base/tooltip'
  7. type ICopyBtnProps = {
  8. value: string
  9. className?: string
  10. isPlain?: boolean
  11. }
  12. const CopyBtn = ({
  13. value,
  14. className,
  15. isPlain,
  16. }: ICopyBtnProps) => {
  17. const [isCopied, setIsCopied] = useState(false)
  18. return (
  19. <div className={`${className}`}>
  20. <Tooltip
  21. popupContent={(isCopied ? t('appApi.copied') : t('appApi.copy'))}
  22. >
  23. <div
  24. className={'box-border p-0.5 flex items-center justify-center rounded-md bg-white cursor-pointer'}
  25. style={!isPlain
  26. ? {
  27. boxShadow: '0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)',
  28. }
  29. : {}}
  30. onClick={() => {
  31. copy(value)
  32. setIsCopied(true)
  33. }}
  34. >
  35. <div className={`w-6 h-6 rounded-md hover:bg-gray-50 ${s.copyIcon} ${isCopied ? s.copied : ''}`}></div>
  36. </div>
  37. </Tooltip>
  38. </div>
  39. )
  40. }
  41. export default CopyBtn