Spaces:
Sleeping
Sleeping
Download frontend/components/Toast.tsx from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 2.69 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/components/Toast.tsx
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/frontend/components/Toast.tsx
-
curl -L -o Toast.tsx https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/components/Toast.tsx
2.69 kB
| 'use client' | |
| import { useEffect } from 'react' | |
| import { CheckCircle, XCircle, AlertCircle, Info, X } from 'lucide-react' | |
| export type ToastType = 'success' | 'error' | 'warning' | 'info' | |
| export interface ToastProps { | |
| id: string | |
| type: ToastType | |
| title: string | |
| message?: string | |
| duration?: number | |
| onClose: (id: string) => void | |
| } | |
| export default function Toast({ id, type, title, message, duration = 5000, onClose }: ToastProps) { | |
| useEffect(() => { | |
| if (duration > 0) { | |
| const timer = setTimeout(() => { | |
| onClose(id) | |
| }, duration) | |
| return () => clearTimeout(timer) | |
| } | |
| }, [duration, id, onClose]) | |
| const configs = { | |
| success: { | |
| icon: CheckCircle, | |
| bgColor: 'bg-gradient-to-r from-emerald-500 to-teal-500', | |
| iconColor: 'text-white', | |
| borderColor: 'border-emerald-400', | |
| }, | |
| error: { | |
| icon: XCircle, | |
| bgColor: 'bg-gradient-to-r from-red-500 to-pink-500', | |
| iconColor: 'text-white', | |
| borderColor: 'border-red-400', | |
| }, | |
| warning: { | |
| icon: AlertCircle, | |
| bgColor: 'bg-gradient-to-r from-yellow-500 to-orange-500', | |
| iconColor: 'text-white', | |
| borderColor: 'border-yellow-400', | |
| }, | |
| info: { | |
| icon: Info, | |
| bgColor: 'bg-gradient-to-r from-blue-500 to-indigo-500', | |
| iconColor: 'text-white', | |
| borderColor: 'border-blue-400', | |
| }, | |
| } | |
| const config = configs[type] | |
| const Icon = config.icon | |
| return ( | |
| <div | |
| className={`${config.bgColor} rounded-xl shadow-2xl border-2 ${config.borderColor} p-4 min-w-[320px] max-w-md animate-slide-in-right`} | |
| role="alert" | |
| > | |
| <div className="flex items-start gap-3"> | |
| {/* Icon */} | |
| <div className="flex-shrink-0"> | |
| <Icon className={`w-6 h-6 ${config.iconColor}`} /> | |
| </div> | |
| {/* Content */} | |
| <div className="flex-1 min-w-0"> | |
| <h4 className="text-white font-bold text-sm mb-1">{title}</h4> | |
| {message && ( | |
| <p className="text-white/90 text-xs leading-relaxed">{message}</p> | |
| )} | |
| </div> | |
| {/* Close button */} | |
| <button | |
| onClick={() => onClose(id)} | |
| className="flex-shrink-0 p-1 hover:bg-white/20 rounded-lg transition-colors" | |
| aria-label="Закрыть" | |
| > | |
| <X className="w-4 h-4 text-white" /> | |
| </button> | |
| </div> | |
| {/* Progress bar */} | |
| {duration > 0 && ( | |
| <div className="mt-2 h-1 bg-white/20 rounded-full overflow-hidden"> | |
| <div | |
| className="h-full bg-white/60 rounded-full animate-progress" | |
| style={{ animationDuration: `${duration}ms` }} | |
| /> | |
| </div> | |
| )} | |
| </div> | |
| ) | |
| } | |