forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmDialog.tsx
More file actions
149 lines (141 loc) · 4.95 KB
/
Copy pathConfirmDialog.tsx
File metadata and controls
149 lines (141 loc) · 4.95 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
'use client';
import * as Dialog from '@radix-ui/react-dialog';
import { motion, AnimatePresence } from 'framer-motion';
import { X, AlertTriangle } from 'lucide-react';
import { cn } from '@/lib/utils';
interface ConfirmDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
description: string;
confirmLabel?: string;
cancelLabel?: string;
variant?: 'danger' | 'default';
onConfirm: () => void;
isLoading?: boolean;
}
export function ConfirmDialog({
open,
onOpenChange,
title,
description,
confirmLabel = 'Confirm',
cancelLabel = 'Cancel',
variant = 'default',
onConfirm,
isLoading = false,
}: ConfirmDialogProps) {
const handleConfirm = () => {
onConfirm();
if (!isLoading) {
onOpenChange(false);
}
};
return (
<Dialog.Root open={open} onOpenChange={onOpenChange}>
<AnimatePresence>
{open && (
<Dialog.Portal forceMount>
<Dialog.Overlay asChild>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
className="fixed inset-0 bg-black/50 z-[100]"
/>
</Dialog.Overlay>
<Dialog.Content asChild>
<motion.div
initial={{ opacity: 0, scale: 0.95, y: 10 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 10 }}
transition={{ duration: 0.15, ease: 'easeOut' }}
className={cn(
'fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-[101]',
'w-[90vw] max-w-[400px]',
'bg-bg-secondary rounded-2xl',
'border border-bg-tertiary',
'shadow-2xl',
'p-6',
'focus:outline-none'
)}
>
{/* Close button */}
<Dialog.Close asChild>
<button
className="absolute top-4 right-4 p-1.5 rounded-lg hover:bg-bg-tertiary transition-colors"
aria-label="Close"
>
<X className="w-4 h-4 text-text-quaternary" />
</button>
</Dialog.Close>
{/* Icon */}
<div
className={cn(
'w-12 h-12 rounded-full flex items-center justify-center mb-4',
variant === 'danger'
? 'bg-error/10'
: 'bg-purple-primary/10'
)}
>
<AlertTriangle
className={cn(
'w-6 h-6',
variant === 'danger' ? 'text-error' : 'text-purple-primary'
)}
/>
</div>
{/* Title */}
<Dialog.Title className="text-lg font-semibold text-text-primary mb-2">
{title}
</Dialog.Title>
{/* Description */}
<Dialog.Description className="text-sm text-text-tertiary mb-6">
{description}
</Dialog.Description>
{/* Actions */}
<div className="flex gap-3">
<Dialog.Close asChild>
<button
className={cn(
'flex-1 px-4 py-2.5 rounded-xl',
'bg-bg-tertiary hover:bg-bg-quaternary',
'text-text-secondary text-sm font-medium',
'transition-colors'
)}
>
{cancelLabel}
</button>
</Dialog.Close>
<button
onClick={handleConfirm}
disabled={isLoading}
className={cn(
'flex-1 px-4 py-2.5 rounded-xl',
'text-white text-sm font-medium',
'transition-colors',
'disabled:opacity-50 disabled:cursor-not-allowed',
variant === 'danger'
? 'bg-error hover:bg-error/90'
: 'bg-purple-primary hover:bg-purple-secondary'
)}
>
{isLoading ? (
<span className="flex items-center justify-center gap-2">
<span className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin" />
<span>Clearing...</span>
</span>
) : (
confirmLabel
)}
</button>
</div>
</motion.div>
</Dialog.Content>
</Dialog.Portal>
)}
</AnimatePresence>
</Dialog.Root>
);
}