ConfirmDialog.tsx
2.27 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use client";
import { AlertTriangle, Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";
interface ConfirmDialogProps {
open: boolean;
title: string;
description: string;
confirmText?: string;
danger?: boolean;
loading?: boolean;
onConfirm: () => void;
onCancel: () => void;
}
/** 通用二次确认弹窗。删除会话、清空长期记忆等不可逆操作复用。 */
export default function ConfirmDialog({
open,
title,
description,
confirmText = "确定",
danger = true,
loading = false,
onConfirm,
onCancel,
}: ConfirmDialogProps) {
if (!open) return null;
return (
<div
className="fixed inset-0 z-[60] flex items-center justify-center bg-slate-900/40 backdrop-blur-sm"
onClick={onCancel}
>
<div
className="w-[360px] bg-white rounded-2xl shadow-2xl p-5"
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-start gap-3">
<div
className={cn(
"w-9 h-9 rounded-xl flex items-center justify-center shrink-0",
danger ? "bg-red-50 text-red-600" : "bg-blue-50 text-blue-600"
)}
>
<AlertTriangle className="w-4.5 h-4.5" />
</div>
<div className="flex-1 min-w-0">
<h3 className="text-sm font-bold text-slate-800">{title}</h3>
<p className="text-xs text-slate-500 mt-1.5 leading-relaxed">{description}</p>
</div>
</div>
<div className="flex justify-end gap-2 mt-5">
<button
onClick={onCancel}
disabled={loading}
className="px-3.5 py-1.5 text-xs font-semibold text-slate-600 hover:bg-slate-100 rounded-lg transition"
>
取消
</button>
<button
onClick={onConfirm}
disabled={loading}
className={cn(
"px-3.5 py-1.5 text-xs font-semibold text-white rounded-lg transition flex items-center gap-1.5",
danger ? "bg-red-600 hover:bg-red-700" : "bg-blue-600 hover:bg-blue-700",
loading && "opacity-60"
)}
>
{loading && <Loader2 className="w-3 h-3 animate-spin" />}
{confirmText}
</button>
</div>
</div>
</div>
);
}