-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageDialog.tsx
More file actions
94 lines (84 loc) · 2.59 KB
/
MessageDialog.tsx
File metadata and controls
94 lines (84 loc) · 2.59 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
'use client';
import { AlertCircle, CheckCircle2, Info, XCircle } from 'lucide-react';
import { useEffect } from 'react';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import useModalStore from '@/stores/useModalStore';
import { cn } from '@/utils/cn';
export default function MessageDialog() {
const { isOpen, title, message, variant, buttonText, onButtonClick, closeMessage } =
useModalStore();
// 버튼 클릭 핸들러
const handleButtonClick = () => {
if (onButtonClick) {
onButtonClick();
}
closeMessage();
};
// ESC 키로 닫기 방지 (필요한 경우)
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape' && isOpen) {
e.preventDefault();
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [isOpen]);
// 아이콘 선택
const IconComponent = (() => {
switch (variant) {
case 'success':
return CheckCircle2;
case 'error':
return XCircle;
case 'warning':
case 'info':
return AlertCircle;
default:
return Info;
}
})();
return (
<Dialog open={isOpen} onOpenChange={open => !open && closeMessage()}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<div className="flex items-center gap-2">
<IconComponent
className={cn(
'h-5 w-5',
variant === 'success' && 'text-green-500',
variant === 'error' && 'text-red-500',
variant === 'warning' && 'text-yellow-500',
variant === 'info' && 'text-accent',
)}
/>
{title && <DialogTitle>{title}</DialogTitle>}
</div>
</DialogHeader>
<div className="py-4">
<p className="text-muted-foreground text-sm">{message}</p>
</div>
<DialogFooter>
<Button
onClick={handleButtonClick}
className={cn(
variant === 'success' && 'bg-green-500 hover:bg-green-600',
variant === 'error' && 'bg-red-500 hover:bg-red-600',
variant === 'warning' && 'bg-yellow-500 hover:bg-yellow-600',
variant === 'info' && 'bg-accent hover:bg-accent/90 text-accent-foreground',
)}
>
{buttonText || '확인'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}