-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToast.tsx
More file actions
35 lines (30 loc) · 859 Bytes
/
Toast.tsx
File metadata and controls
35 lines (30 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// src/components/Toast.tsx
// Toast通知组件 - 替代alert弹窗
import { useEffect } from 'react';
export interface ToastProps {
message: string;
type: 'success' | 'error' | 'info';
onClose: () => void;
duration?: number;
}
export default function Toast({ message, type, onClose, duration = 3000 }: ToastProps) {
useEffect(() => {
const timer = setTimeout(() => {
onClose();
}, duration);
return () => clearTimeout(timer);
}, [duration, onClose]);
return (
<div className={`toast toast-${type}`}>
<span className="toast-icon">
{type === 'success' && '✓'}
{type === 'error' && '✕'}
{type === 'info' && 'ℹ'}
</span>
<span className="toast-message">{message}</span>
<button className="toast-close" onClick={onClose}>
×
</button>
</div>
);
}