fix: copy icon indicator when success (#5091)

This commit is contained in:
Faisal Amir 2025-05-25 01:08:06 +07:00 committed by GitHub
parent cdd13594a3
commit 3443c42947
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
import { useState } from 'react' import { useState } from 'react'
import { Input } from '@/components/ui/input' import { Input } from '@/components/ui/input'
import { Copy, Eye, EyeOff } from 'lucide-react' import { Copy, Eye, EyeOff, CopyCheck } from 'lucide-react'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
type InputControl = { type InputControl = {
@ -21,11 +21,16 @@ export function InputControl({
inputActions = [], inputActions = [],
}: InputControl) { }: InputControl) {
const [showPassword, setShowPassword] = useState(false) const [showPassword, setShowPassword] = useState(false)
const [isCopied, setIsCopied] = useState(false)
const hasInputActions = inputActions && inputActions.length > 0 const hasInputActions = inputActions && inputActions.length > 0
const copyToClipboard = () => { const copyToClipboard = () => {
if (value) { if (value) {
navigator.clipboard.writeText(value) navigator.clipboard.writeText(value)
setIsCopied(true)
setTimeout(() => {
setIsCopied(false)
}, 1000)
} }
} }
@ -65,7 +70,11 @@ export function InputControl({
onClick={copyToClipboard} onClick={copyToClipboard}
className="p-1 rounded hover:bg-main-view-fg/5 text-main-view-fg/70" className="p-1 rounded hover:bg-main-view-fg/5 text-main-view-fg/70"
> >
{isCopied ? (
<CopyCheck className="text-accent" size={16} />
) : (
<Copy size={16} /> <Copy size={16} />
)}
</button> </button>
)} )}
</div> </div>