46 lines
1.1 KiB
TypeScript
Raw Normal View History

'use client'
2024-08-26 13:00:02 +08:00
import { useState } from 'react'
import { t } from 'i18next'
import copy from 'copy-to-clipboard'
2023-08-07 10:20:40 +08:00
import s from './style.module.css'
import Tooltip from '@/app/components/base/tooltip'
type ICopyBtnProps = {
value: string
className?: string
2023-08-30 18:08:47 +08:00
isPlain?: boolean
}
const CopyBtn = ({
value,
className,
2023-08-30 18:08:47 +08:00
isPlain,
}: ICopyBtnProps) => {
2023-09-20 12:27:06 +08:00
const [isCopied, setIsCopied] = useState(false)
return (
<div className={`${className}`}>
<Tooltip
2024-08-26 13:00:02 +08:00
popupContent={(isCopied ? t('appApi.copied') : t('appApi.copy'))}
>
2023-08-07 10:20:40 +08:00
<div
className={'box-border p-0.5 flex items-center justify-center rounded-md bg-white cursor-pointer'}
2023-08-30 18:08:47 +08:00
style={!isPlain
? {
boxShadow: '0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)',
}
: {}}
2023-08-07 10:20:40 +08:00
onClick={() => {
copy(value)
setIsCopied(true)
}}
>
2023-08-30 18:08:47 +08:00
<div className={`w-6 h-6 rounded-md hover:bg-gray-50 ${s.copyIcon} ${isCopied ? s.copied : ''}`}></div>
2023-08-07 10:20:40 +08:00
</div>
</Tooltip>
</div>
)
}
export default CopyBtn