luom2645's picture
Upload folder using huggingface_hub
9dd9a58 verified
Raw History Blame Contribute Delete
2.54 kB
import React, { useEffect, useState } from 'react';
import { NotificationData } from '../../types';
import { XMarkIcon, CheckCircleIcon, ExclamationCircleIcon, ExclamationTriangleIcon, InformationCircleIcon } from '@heroicons/react/24/outline';
interface NotificationProps {
notification: NotificationData;
onClose: () => void;
}
const Notification: React.FC<NotificationProps> = ({ notification, onClose }) => {
const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
// 动画显示
const timer = setTimeout(() => setIsVisible(true), 50);
return () => clearTimeout(timer);
}, []);
const handleClose = () => {
setIsVisible(false);
setTimeout(onClose, 300); // 等待动画结束
};
const getIcon = () => {
switch (notification.type) {
case 'success':
return <CheckCircleIcon className="w-6 h-6 text-success-green" />;
case 'error':
return <ExclamationCircleIcon className="w-6 h-6 text-danger-red" />;
case 'warning':
return <ExclamationTriangleIcon className="w-6 h-6 text-warning-yellow" />;
default:
return <InformationCircleIcon className="w-6 h-6 text-accent-blue" />;
}
};
const getColorClasses = () => {
switch (notification.type) {
case 'success':
return 'border-success-green/50 bg-success-green/20';
case 'error':
return 'border-danger-red/50 bg-danger-red/20';
case 'warning':
return 'border-warning-yellow/50 bg-warning-yellow/20';
default:
return 'border-accent-blue/50 bg-accent-blue/20';
}
};
return (
<div
className={`
max-w-sm w-full glass-panel p-4 transition-all duration-300 transform
${isVisible ? 'translate-x-0 opacity-100' : 'translate-x-full opacity-0'}
${getColorClasses()}
`}
>
<div className="flex items-start space-x-3">
<div className="flex-shrink-0">
{getIcon()}
</div>
<div className="flex-1 min-w-0">
<h4 className="font-medium text-text-highlight">
{notification.title}
</h4>
<p className="text-sm text-text-secondary mt-1">
{notification.message}
</p>
</div>
<button
onClick={handleClose}
className="flex-shrink-0 text-text-secondary hover:text-text-primary transition-colors duration-200"
>
<XMarkIcon className="w-5 h-5" />
</button>
</div>
</div>
);
};
export default Notification;