-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToast.jsx
More file actions
174 lines (161 loc) · 4.88 KB
/
Toast.jsx
File metadata and controls
174 lines (161 loc) · 4.88 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import React, { useEffect } from 'react';
import { motion } from 'framer-motion';
import {
XIcon,
CheckCircleIcon,
WarningCircleIcon,
TrophyIcon,
TerminalIcon,
} from '@phosphor-icons/react';
import { Link } from 'react-router-dom';
const Toast = ({
id,
title,
message,
duration = 3000,
type,
removeToast,
icon,
links,
}) => {
useEffect(() => {
const timer = setTimeout(() => {
removeToast(id);
}, duration);
return () => clearTimeout(timer);
}, [id, duration, removeToast]);
const getIcon = () => {
if (icon) return icon;
switch (type) {
case 'error':
return <WarningCircleIcon weight="fill" className="text-red-500" />;
case 'gold':
return <TrophyIcon weight="fill" className="text-amber-400" />;
case 'techno':
return <TerminalIcon weight="fill" className="text-emerald-400" />;
default:
return <CheckCircleIcon weight="fill" className="text-emerald-500" />;
}
};
const getAccentColor = () => {
switch (type) {
case 'error':
return 'bg-red-500';
case 'gold':
return 'bg-amber-400';
case 'techno':
return 'bg-emerald-400';
default:
return 'bg-emerald-500';
}
};
const getBorderColor = () => {
switch (type) {
case 'error':
return 'border-red-500/50';
case 'gold':
return 'border-amber-400/50';
case 'techno':
return 'border-emerald-400/50';
default:
return 'border-emerald-500/50';
}
};
const getGlowColor = () => {
switch (type) {
case 'error':
return 'shadow-red-500/10';
case 'gold':
return 'shadow-amber-400/10';
case 'techno':
return 'shadow-emerald-400/10';
default:
return 'shadow-emerald-500/10';
}
};
return (
<motion.div
layout
initial={{ x: 100, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: 100, opacity: 0 }}
className={`relative w-80 md:w-96 bg-[#050505]/95 backdrop-blur-xl border-2 ${getBorderColor()} rounded-sm shadow-2xl ${getGlowColor()} overflow-hidden mb-4 group`}
>
{/* Dynamic Timer Bar */}
<motion.div
initial={{ width: '100%' }}
animate={{ width: 0 }}
transition={{ duration: duration / 1000, ease: 'linear' }}
className={`absolute bottom-0 left-0 h-1 z-20 ${getAccentColor()}`}
/>
<div className="p-6 flex gap-4 items-start">
<div className="flex-shrink-0 mt-1">
<div className="text-xl">{getIcon()}</div>
</div>
<div className="flex-grow min-w-0 space-y-1">
<h4 className="text-xs font-black uppercase tracking-widest text-white leading-tight">
{title}
</h4>
<p className="text-[11px] font-mono leading-relaxed text-gray-400">
{message}
</p>
{links && links.length > 0 && (
<div className="flex flex-wrap gap-2 pt-3">
{links.map((link, index) => {
const btnClass =
'text-[9px] font-black uppercase tracking-widest px-3 py-1.5 bg-white/5 border border-white/10 text-white hover:bg-white hover:text-black transition-all rounded-sm';
if (link.to)
return (
<Link
key={index}
to={link.to}
className={btnClass}
onClick={() => removeToast(id)}
>
{link.label}
</Link>
);
if (link.href)
return (
<a
key={index}
href={link.href}
target="_blank"
rel="noopener noreferrer"
className={btnClass}
onClick={() => removeToast(id)}
>
{link.label}
</a>
);
if (link.onClick)
return (
<button
key={index}
onClick={() => {
link.onClick();
removeToast(id);
}}
className={btnClass}
>
{link.label}
</button>
);
return null;
})}
</div>
)}
</div>
<button
onClick={() => removeToast(id)}
className="flex-shrink-0 text-gray-600 hover:text-white transition-colors p-1"
>
<XIcon size={16} weight="bold" />
</button>
</div>
{/* Glossy Overlay */}
<div className="absolute inset-0 bg-gradient-to-tr from-white/[0.02] to-transparent pointer-events-none" />
</motion.div>
);
};
export default Toast;