-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathAlertWidget.jsx
More file actions
62 lines (56 loc) · 1.68 KB
/
AlertWidget.jsx
File metadata and controls
62 lines (56 loc) · 1.68 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
import { AlertTriangle, CheckCircle2, Info, XCircle } from 'lucide-react';
import React from 'react';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip';
import { cn } from '@/lib/utils';
const levelConfig = {
success: {
icon: CheckCircle2,
variant: 'success',
title: 'Success',
},
warning: {
icon: AlertTriangle,
variant: 'warning',
title: 'Warning',
},
error: {
icon: XCircle,
variant: 'destructive',
title: 'Error',
},
info: {
icon: Info,
variant: 'default',
title: 'Information',
},
};
const AlertWidget = ({ id, message, level = 'info', className, error }) => {
const config = levelConfig[level] || levelConfig.info;
const Icon = config.icon;
return (
<div id={id} className='relative'>
{error && (
<Tooltip>
<TooltipTrigger asChild>
<div className="absolute top-2 right-2 text-destructive z-10 pointer-events-auto cursor-pointer">
<AlertTriangle className="w-5 h-5" />
</div>
</TooltipTrigger>
<TooltipContent>
<span>{error.toString()}</span>
</TooltipContent>
</Tooltip>
)}
<Alert variant={config.variant}
className={cn('alertwidget-container',
className,
error && 'border-destructive border-2 bg-red-50 rounded-md')}>
<Icon className={cn("alertwidget-icon", error && 'text-gray-300')} />
<AlertTitle>{config.title}</AlertTitle>
<AlertDescription>{message}</AlertDescription>
</Alert>
</div>
);
};
export default AlertWidget;