2023-05-15 08:51:32 +08:00
|
|
|
'use client'
|
2024-08-26 13:00:02 +08:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2023-05-24 16:11:25 +08:00
|
|
|
import copy from 'copy-to-clipboard'
|
2023-05-15 08:51:32 +08:00
|
|
|
import { t } from 'i18next'
|
2023-06-01 23:19:36 +08:00
|
|
|
import Tooltip from '@/app/components/base/tooltip'
|
2025-05-14 09:06:14 +08:00
|
|
|
import CopyFeedback from '@/app/components/base/copy-feedback'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
type IInputCopyProps = {
|
|
|
|
value?: string
|
|
|
|
className?: string
|
|
|
|
children?: React.ReactNode
|
|
|
|
}
|
|
|
|
|
|
|
|
const InputCopy = ({
|
2023-07-21 11:15:00 +08:00
|
|
|
value = '',
|
2023-05-15 08:51:32 +08:00
|
|
|
className,
|
|
|
|
children,
|
|
|
|
}: IInputCopyProps) => {
|
|
|
|
const [isCopied, setIsCopied] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isCopied) {
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
setIsCopied(false)
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearTimeout(timeout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [isCopied])
|
|
|
|
|
|
|
|
return (
|
2025-03-21 17:41:03 +08:00
|
|
|
<div className={`flex items-center rounded-lg bg-components-input-bg-normal py-2 hover:bg-state-base-hover ${className}`}>
|
|
|
|
<div className="flex h-5 grow items-center">
|
2023-05-15 08:51:32 +08:00
|
|
|
{children}
|
2025-03-21 17:41:03 +08:00
|
|
|
<div className='relative h-full grow text-[13px]'>
|
|
|
|
<div className='r-0 absolute left-0 top-0 w-full cursor-pointer truncate pl-2 pr-2' onClick={() => {
|
2024-08-26 13:00:02 +08:00
|
|
|
copy(value)
|
|
|
|
setIsCopied(true)
|
|
|
|
}}>
|
|
|
|
<Tooltip
|
|
|
|
popupContent={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
|
|
|
|
position='bottom'
|
|
|
|
>
|
2025-05-14 09:06:14 +08:00
|
|
|
<span className='text-text-secondary'>{value}</span>
|
2024-08-26 13:00:02 +08:00
|
|
|
</Tooltip>
|
|
|
|
</div>
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
2025-05-14 09:06:14 +08:00
|
|
|
<div className="h-4 w-px shrink-0 bg-divider-regular" />
|
|
|
|
<div className='mx-1'><CopyFeedback content={value} /></div>
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default InputCopy
|