Spaces:
Runtime error
Runtime error
Download frontend-react/src/components/Toast.jsx from Amitkasar/ai-api-testing: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/Amitkasar/ai-api-testing/resolve/main/frontend-react/src/components/Toast.jsx
- Command line
-
hf download hf://spaces/Amitkasar/ai-api-testing/frontend-react/src/components/Toast.jsx
-
curl -L -o Toast.jsx https://huggingface.co/spaces/Amitkasar/ai-api-testing/resolve/main/frontend-react/src/components/Toast.jsx
1.69 kB
| import React, { useEffect } from 'react'; | |
| import { CheckCircle, XCircle, AlertTriangle, Info, X } from 'lucide-react'; | |
| const ICONS = { | |
| success: CheckCircle, | |
| error: XCircle, | |
| warning: AlertTriangle, | |
| info: Info, | |
| }; | |
| const COLORS = { | |
| success: 'border-emerald-500/40 bg-emerald-500/10 text-emerald-400', | |
| error: 'border-red-500/40 bg-red-500/10 text-red-400', | |
| warning: 'border-amber-500/40 bg-amber-500/10 text-amber-400', | |
| info: 'border-blue-500/40 bg-blue-500/10 text-blue-400', | |
| }; | |
| const Toast = ({ toast, onRemove }) => { | |
| const Icon = ICONS[toast.type] || Info; | |
| useEffect(() => { | |
| const t = setTimeout(() => onRemove(toast.id), toast.duration ?? 4000); | |
| return () => clearTimeout(t); | |
| }, [toast.id, toast.duration, onRemove]); | |
| return ( | |
| <div className={`flex items-start space-x-3 px-4 py-3 rounded-xl border shadow-2xl backdrop-blur-sm max-w-sm animate-in slide-in-from-right-4 duration-300 ${COLORS[toast.type] || COLORS.info}`}> | |
| <Icon size={15} className="shrink-0 mt-0.5" /> | |
| <p className="text-xs font-medium flex-1 leading-relaxed">{toast.message}</p> | |
| <button onClick={() => onRemove(toast.id)} className="shrink-0 opacity-50 hover:opacity-100 transition-opacity"> | |
| <X size={13} /> | |
| </button> | |
| </div> | |
| ); | |
| }; | |
| export const ToastContainer = ({ toasts, removeToast }) => { | |
| if (!toasts.length) return null; | |
| return ( | |
| <div className="fixed bottom-6 right-6 z-[9999] flex flex-col space-y-2 pointer-events-none"> | |
| {toasts.map(t => ( | |
| <div key={t.id} className="pointer-events-auto"> | |
| <Toast toast={t} onRemove={removeToast} /> | |
| </div> | |
| ))} | |
| </div> | |
| ); | |
| }; | |
| export default Toast; | |