Skip to content

Commit b383fd4

Browse files
committed
🚀 feat: add a toast notification
1 parent 276854a commit b383fd4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/components/features/Toast.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Toast.tsx
2+
import { motion } from 'framer-motion';
3+
4+
interface ToastProps {
5+
message: string;
6+
onClose: () => void;
7+
}
8+
9+
export const Toast = ({ message, onClose }: ToastProps) => (
10+
<motion.div
11+
initial={{ opacity: 0, y: 20 }}
12+
animate={{ opacity: 1, y: 0 }}
13+
exit={{ opacity: 0, y: 20 }}
14+
transition={{ duration: 0.3 }}
15+
className="fixed bottom-4 left-1/2 transform -translate-x-1/2 bg-cornflower-blue text-white px-4 py-2 rounded-lg shadow-lg"
16+
>
17+
<div className="flex items-center gap-2">
18+
<span>{message}</span>
19+
</div>
20+
<button
21+
onClick={onClose}
22+
className="absolute top-0 right-0 p-1 text-white hover:bg-cornflower-blue/80 rounded-full"
23+
aria-label="Close toast"
24+
>
25+
&times;
26+
</button>
27+
</motion.div>
28+
);

src/components/features/ToolCard.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { motion } from 'framer-motion';
22
import { Terminal, Clipboard } from 'lucide-react';
33
import { useState } from 'react';
4+
import { Toast } from './Toast'; // Make sure to import the Toast component
45

56
interface ToolCardProps {
67
name: string;
@@ -11,12 +12,17 @@ interface ToolCardProps {
1112

1213
export function ToolCard({ name, description, category, command }: ToolCardProps) {
1314
const [copied, setCopied] = useState(false);
15+
const [showToast, setShowToast] = useState(false);
1416

1517
const handleCopyClick = () => {
1618
navigator.clipboard.writeText(command)
1719
.then(() => {
1820
setCopied(true);
19-
setTimeout(() => setCopied(false), 2000); // Reset copied status after 2 seconds
21+
setShowToast(true);
22+
setTimeout(() => {
23+
setCopied(false);
24+
setShowToast(false);
25+
}, 3000); // Hide toast after 3 seconds
2026
})
2127
.catch((error) => console.error('Failed to copy: ', error));
2228
};
@@ -55,6 +61,13 @@ export function ToolCard({ name, description, category, command }: ToolCardProps
5561
</button>
5662
</div>
5763
</div>
64+
65+
{showToast && (
66+
<Toast
67+
message="Command copied! Paste it in your terminal with Ctrl + Shift + V (Cmd + Shift + V on Mac)"
68+
onClose={() => setShowToast(false)}
69+
/>
70+
)}
5871
</motion.div>
5972
);
6073
}

0 commit comments

Comments
 (0)