Skip to content

Commit 3d14902

Browse files
committed
feat: toast animation
1 parent 597684e commit 3d14902

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/components/Toast.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useEffect } from 'react';
2+
import { motion } from 'framer-motion';
23

34
import { X } from '@phosphor-icons/react';
45

@@ -14,9 +15,13 @@ const Toast = ({ title, message, duration, onClose }) => {
1415
}, [duration, onClose]);
1516

1617
return (
17-
<div
18-
className="fixed top-28 left-1/2 -translate-x-1/2 text-gray-300 py-4 px-10 rounded-lg shadow-lg border backdrop-blur-sm flex items-center justify-between w-96"
19-
style={{ backgroundColor: 'rgba(68, 64, 59, 0.65)', borderColor: '#5a5e64' }}
18+
<motion.div
19+
initial={{ y: -100, opacity: 0 }}
20+
animate={{ y: 0, opacity: 1 }}
21+
exit={{ y: -100, opacity: 0 }}
22+
transition={{ type: 'spring', stiffness: 120, damping: 20 }}
23+
className="fixed top-28 -translate-y-1/2 left-0 right-0 mx-auto text-gray-300 py-4 px-10 rounded-lg shadow-lg border backdrop-blur-sm flex items-center justify-between w-96"
24+
style={{ backgroundColor: 'rgba(68, 64, 59, 0.8)', borderColor: '#5a5e64' }}
2025
>
2126
<div className="flex flex-col text-sm">
2227
<span>{title}</span>
@@ -25,7 +30,7 @@ const Toast = ({ title, message, duration, onClose }) => {
2530
<button onClick={onClose} className="pr-2">
2631
<X size={24} weight="bold" />
2732
</button>
28-
</div>
33+
</motion.div>
2934
);
3035
};
3136

src/pages/BlogPostPage.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { customTheme } from '../utils/customTheme';
66
import PostMetadata from '../components/PostMetadata';
77
import CodeModal from '../components/CodeModal';
88
import Toast from '../components/Toast';
9+
import { AnimatePresence } from 'framer-motion';
910
import { ArrowLeftIcon, ArrowSquareOutIcon, ClipboardIcon, ArrowsOutSimpleIcon } from '@phosphor-icons/react';
1011

1112
const LinkRenderer = ({ href, children }) => {
@@ -187,7 +188,9 @@ const BlogPostPage = () => {
187188
<CodeModal isOpen={isModalOpen} onClose={closeModal}>
188189
{modalContent}
189190
</CodeModal>
190-
{toastMessage && <Toast title={toastMessage.title} message={toastMessage.message} duration={3000} onClose={() => setToastMessage(null)} />}
191+
<AnimatePresence>
192+
{toastMessage && <Toast title={toastMessage.title} message={toastMessage.message} duration={3000} onClose={() => setToastMessage(null)} />}
193+
</AnimatePresence>
191194
</div>
192195
);
193196
};

0 commit comments

Comments
 (0)