Skip to content

Commit 6400ca3

Browse files
committed
feat : 주소 복사 기능 추가
1 parent 4c7e001 commit 6400ca3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/shared/container/components/AddressCopy.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Icon } from '@/shared/icons';
22
import { cn } from '@/shared/lib';
33
import { cva, type VariantProps } from 'class-variance-authority';
4+
import type * as React from 'react';
5+
import { useState } from 'react';
46

57
const addressCopyStyle = cva(
68
'flex items-center justify-start flex-shrink-0 rounded-full transition-all duration-200',
@@ -21,16 +23,31 @@ interface AddressCopyProps
2123
extends React.HTMLAttributes<HTMLDivElement>,
2224
VariantProps<typeof addressCopyStyle> {
2325
label?: string;
26+
value?: string;
2427
}
2528

2629
const AddressCopy = ({
2730
label = 'address copy',
31+
value = label,
2832
variant = 'gray',
2933
className,
3034
...props
3135
}: AddressCopyProps) => {
36+
const [copied, setCopied] = useState(false);
37+
38+
const handleCopy = async () => {
39+
try {
40+
await navigator.clipboard.writeText(value);
41+
setCopied(true);
42+
setTimeout(() => setCopied(false), 1500);
43+
} catch (err) {
44+
console.error('주소 복사 실패:', err);
45+
}
46+
};
47+
3248
return (
3349
<div
50+
onClick={handleCopy}
3451
className={cn(
3552
addressCopyStyle({ variant }),
3653
'w-[35.4rem] h-[4rem] px-[1.3rem] py-[1rem] gap-[0.4rem]',

0 commit comments

Comments
 (0)