-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddressCopy.tsx
More file actions
83 lines (77 loc) · 1.98 KB
/
AddressCopy.tsx
File metadata and controls
83 lines (77 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use client';
import { Icon } from '@/shared/icons';
import { cn } from '@/shared/lib';
import { cva, type VariantProps } from 'class-variance-authority';
import { useState } from 'react';
import { Copy } from '@/shared/utils/copy';
const addressCopyStyle = cva(
'flex items-center justify-start flex-shrink-0 rounded-full transition-all duration-200 overflow-hidden',
{
variants: {
variant: {
gray: 'border border-gray-300 bg-gray-50 text-gray-400',
mint: 'border border-mint-300 bg-mint-50 text-mint-500',
},
},
defaultVariants: {
variant: 'gray',
},
},
);
interface AddressCopyProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof addressCopyStyle> {
label: string;
truncate?: boolean;
}
const AddressCopy = ({
label,
variant = 'gray',
truncate = true,
className,
...props
}: AddressCopyProps) => {
const [copied, setCopied] = useState(false);
const handleCopy = () => {
Copy(
label,
() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
},
undefined,
);
};
return (
<div
onClick={handleCopy}
className={cn(
addressCopyStyle({ variant }),
'w-full h-[4rem] px-[1.3rem] py-[1rem] gap-[0.4rem]',
'cursor-pointer select-none',
className,
)}
{...props}
>
<div className='flex-shrink-0'>
<Icon
name={copied ? 'Check' : 'CopySimple'}
size={18}
color={variant === 'mint' ? 'mint-400' : 'gray-400'}
/>
</div>
<span
className={cn(
'text-label-lg flex-1 min-w-0',
variant === 'mint' ? 'text-mint-400' : 'text-gray-400',
truncate &&
'truncate whitespace-nowrap overflow-hidden text-ellipsis',
)}
title={label}
>
{label}
</span>
</div>
);
};
export default AddressCopy;