Skip to content

Commit 01ea1fd

Browse files
committed
fix: add exit animations
1 parent 57dd7d0 commit 01ea1fd

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

src/components/SnippetList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const SnippetList = () => {
6969
))}
7070
</motion.ul>
7171

72-
<AnimatePresence>
72+
<AnimatePresence mode="wait">
7373
{isModalOpen && snippet && (
7474
<SnippetModal
7575
snippet={snippet}

src/components/SnippetModal.tsx

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,59 @@ const SnippetModal: React.FC<Props> = ({
2424
useEscapeKey(handleCloseModal);
2525

2626
return ReactDOM.createPortal(
27-
<AnimatePresence>
27+
<motion.div
28+
key="modal-overlay"
29+
className="modal-overlay"
30+
onClick={(e) => {
31+
if (e.target === e.currentTarget) {
32+
handleCloseModal();
33+
}
34+
}}
35+
initial={{ opacity: 0 }}
36+
animate={{ opacity: 1 }}
37+
exit={{ opacity: 0 }}
38+
transition={{ duration: 0.2 }}
39+
>
2840
<motion.div
29-
className="modal-overlay"
30-
onClick={(e) => {
31-
if (e.target === e.currentTarget) {
32-
handleCloseModal();
33-
}
34-
}}
35-
initial={{ opacity: 0 }}
36-
animate={{ opacity: 1 }}
37-
exit={{ opacity: 0 }}
41+
key="modal-content"
42+
className="modal | flow"
43+
data-flow-space="lg"
44+
initial={{ scale: 0.8, opacity: 0, y: 20 }}
45+
animate={{ scale: 1, opacity: 1, y: 0 }}
46+
exit={{ scale: 0.8, opacity: 0, y: 20 }}
47+
transition={{ type: "spring", duration: 0.5 }}
3848
>
39-
<motion.div
40-
className="modal | flow"
41-
data-flow-space="lg"
42-
initial={{ scale: 0.8, opacity: 0, y: 20 }}
43-
animate={{ scale: 1, opacity: 1, y: 0 }}
44-
exit={{ scale: 0.8, opacity: 0, y: 20 }}
45-
transition={{ type: "spring", duration: 0.5 }}
46-
>
47-
<div className="modal__header">
48-
<h2 className="section-title">{snippet.title}</h2>
49-
<Button isIcon={true} onClick={handleCloseModal}>
50-
<CloseIcon />
51-
</Button>
52-
</div>
53-
<CodePreview language={slugify(language)} code={snippet.code} />
54-
<p>
55-
<b>Description: </b>
56-
{snippet.description}
57-
</p>
58-
<p>
59-
Contributed by{" "}
60-
<a
61-
href={`https://github.com/${snippet.author}`}
62-
target="_blank"
63-
rel="noopener noreferrer"
64-
className="styled-link"
65-
>
66-
@{snippet.author}
67-
</a>
68-
</p>
69-
<ul role="list" className="modal__tags">
70-
{snippet.tags.map((tag) => (
71-
<li key={tag} className="modal__tag">
72-
{tag}
73-
</li>
74-
))}
75-
</ul>
76-
</motion.div>
49+
<div className="modal__header">
50+
<h2 className="section-title">{snippet.title}</h2>
51+
<Button isIcon={true} onClick={handleCloseModal}>
52+
<CloseIcon />
53+
</Button>
54+
</div>
55+
<CodePreview language={slugify(language)} code={snippet.code} />
56+
<p>
57+
<b>Description: </b>
58+
{snippet.description}
59+
</p>
60+
<p>
61+
Contributed by{" "}
62+
<a
63+
href={`https://github.com/${snippet.author}`}
64+
target="_blank"
65+
rel="noopener noreferrer"
66+
className="styled-link"
67+
>
68+
@{snippet.author}
69+
</a>
70+
</p>
71+
<ul role="list" className="modal__tags">
72+
{snippet.tags.map((tag) => (
73+
<li key={tag} className="modal__tag">
74+
{tag}
75+
</li>
76+
))}
77+
</ul>
7778
</motion.div>
78-
</AnimatePresence>,
79+
</motion.div>,
7980
modalRoot
8081
);
8182
};

0 commit comments

Comments
 (0)