Skip to content

Commit 50ce4eb

Browse files
committed
fix copy animation
1 parent 2dbd91b commit 50ce4eb

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

packages/insight/src/components/copy-text.tsx

+36-17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import TickSvg from '../assets/images/tick.svg';
88
const CopyImg = styled(motion.div)`
99
margin: auto 0.25rem;
1010
display: inline-block;
11+
width: 12px;
12+
height: 12px;
13+
position: relative;
14+
`;
15+
16+
const IconImage = styled(motion.img)`
17+
position: absolute;
18+
top: 0;
19+
left: 0;
20+
width: 100%;
21+
height: 100%;
1122
`;
1223

1324
interface CopyTextProps {
@@ -49,25 +60,33 @@ const CopyText: FC<CopyTextProps> = ({text}) => {
4960
};
5061

5162
return (
52-
<AnimatePresence>
53-
{copied ? (
54-
<CopyImg key='tick' variants={copyAnime} exit='exit' initial='initial' animate='animate'>
55-
<img src={TickSvg} width={12} height={12} alt='tick' />
56-
</CopyImg>
57-
) : (
58-
<CopyToClipboard text={text} onCopy={() => onClickCopy()}>
59-
<CopyImg
60-
key='copy'
63+
<CopyImg>
64+
<AnimatePresence mode={'wait'}>
65+
{copied ? (
66+
<IconImage
67+
key='tick'
68+
src={TickSvg}
69+
alt='tick'
6170
variants={copyAnime}
62-
whileHover='whileHover'
63-
exit='exit'
6471
initial='initial'
65-
animate='animate'>
66-
<img src={CopySvg} width={12} height={12} alt='copy' />
67-
</CopyImg>
68-
</CopyToClipboard>
69-
)}
70-
</AnimatePresence>
72+
animate='animate'
73+
exit='exit'
74+
/>
75+
) : (
76+
<CopyToClipboard text={text} onCopy={() => onClickCopy()}>
77+
<IconImage
78+
key='copy'
79+
src={CopySvg}
80+
alt='copy'
81+
variants={copyAnime}
82+
initial='initial'
83+
animate='animate'
84+
whileHover='whileHover'
85+
/>
86+
</CopyToClipboard>
87+
)}
88+
</AnimatePresence>
89+
</CopyImg>
7190
);
7291
};
7392

0 commit comments

Comments
 (0)