Skip to content

Commit

Permalink
🚀 feat: add a toast notification
Browse files Browse the repository at this point in the history
  • Loading branch information
eshanized committed Jan 16, 2025
1 parent 276854a commit b383fd4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/components/features/Toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Toast.tsx
import { motion } from 'framer-motion';

interface ToastProps {
message: string;
onClose: () => void;
}

export const Toast = ({ message, onClose }: ToastProps) => (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 20 }}
transition={{ duration: 0.3 }}
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"
>
<div className="flex items-center gap-2">
<span>{message}</span>
</div>
<button
onClick={onClose}
className="absolute top-0 right-0 p-1 text-white hover:bg-cornflower-blue/80 rounded-full"
aria-label="Close toast"
>
&times;
</button>
</motion.div>
);
15 changes: 14 additions & 1 deletion src/components/features/ToolCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { motion } from 'framer-motion';
import { Terminal, Clipboard } from 'lucide-react';
import { useState } from 'react';
import { Toast } from './Toast'; // Make sure to import the Toast component

interface ToolCardProps {
name: string;
Expand All @@ -11,12 +12,17 @@ interface ToolCardProps {

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

const handleCopyClick = () => {
navigator.clipboard.writeText(command)
.then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 2000); // Reset copied status after 2 seconds
setShowToast(true);
setTimeout(() => {
setCopied(false);
setShowToast(false);
}, 3000); // Hide toast after 3 seconds
})
.catch((error) => console.error('Failed to copy: ', error));
};
Expand Down Expand Up @@ -55,6 +61,13 @@ export function ToolCard({ name, description, category, command }: ToolCardProps
</button>
</div>
</div>

{showToast && (
<Toast
message="Command copied! Paste it in your terminal with Ctrl + Shift + V (Cmd + Shift + V on Mac)"
onClose={() => setShowToast(false)}
/>
)}
</motion.div>
);
}

0 comments on commit b383fd4

Please sign in to comment.