File size: 6,482 Bytes
582ba4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { CheckCircle2, AlertTriangle, Info, XCircle, X, Bell } from 'lucide-react';
import { motion } from 'framer-motion';

const categoryConfig = {
  success: {
    icon: CheckCircle2,
    bg: 'bg-emerald-950/60',
    border: 'border-emerald-400/15',
    iconBg: 'bg-emerald-400/12',
    iconColor: 'text-emerald-400',
    title: 'text-emerald-300',
    glow: 'shadow-emerald-500/10',
    progress: 'bg-emerald-400/40',
  },
  error: {
    icon: XCircle,
    bg: 'bg-red-950/60',
    border: 'border-red-400/15',
    iconBg: 'bg-red-400/12',
    iconColor: 'text-red-400',
    title: 'text-red-300',
    glow: 'shadow-red-500/10',
    progress: 'bg-red-400/40',
  },
  warning: {
    icon: AlertTriangle,
    bg: 'bg-amber-950/60',
    border: 'border-amber-400/15',
    iconBg: 'bg-amber-400/12',
    iconColor: 'text-amber-400',
    title: 'text-amber-300',
    glow: 'shadow-amber-500/10',
    progress: 'bg-amber-400/40',
  },
  info: {
    icon: Info,
    bg: 'bg-blue-950/60',
    border: 'border-blue-400/15',
    iconBg: 'bg-blue-400/12',
    iconColor: 'text-blue-400',
    title: 'text-blue-300',
    glow: 'shadow-blue-500/10',
    progress: 'bg-blue-400/40',
  },
  neutral: {
    icon: Bell,
    bg: 'bg-zinc-900/80',
    border: 'border-zinc-400/15',
    iconBg: 'bg-zinc-400/12',
    iconColor: 'text-zinc-400',
    title: 'text-zinc-300',
    glow: 'shadow-zinc-500/10',
    progress: 'bg-zinc-400/40',
  },
};

const positionStyles = {
  'top-left': 'items-start justify-start',
  'top-center': 'items-start justify-center',
  'top-right': 'items-start justify-end',
  'bottom-left': 'items-end justify-start',
  'bottom-center': 'items-end justify-center',
  'bottom-right': 'items-end justify-end',
  'center': 'items-center justify-center',
};

export default function AlertCard({
  id,
  category,
  title,
  message,
  position,
  dismissible,
  autoClose,
  duration,
  onDismiss,
  animationVariant,
}) {
  const config = categoryConfig[category] || categoryConfig.neutral;
  const Icon = config.icon;

  const variants = {
    slideIn: {
      hidden: { x: 100, opacity: 0, scale: 0.9 },
      visible: { x: 0, opacity: 1, scale: 1, transition: { type: 'spring', stiffness: 350, damping: 25 } },
      exit: { x: 100, opacity: 0, scale: 0.9, transition: { duration: 0.25 } },
    },
    slideInLeft: {
      hidden: { x: -100, opacity: 0, scale: 0.9 },
      visible: { x: 0, opacity: 1, scale: 1, transition: { type: 'spring', stiffness: 350, damping: 25 } },
      exit: { x: -100, opacity: 0, scale: 0.9, transition: { duration: 0.25 } },
    },
    slideUp: {
      hidden: { y: 60, opacity: 0 },
      visible: { y: 0, opacity: 1, transition: { type: 'spring', stiffness: 350, damping: 25 } },
      exit: { y: 60, opacity: 0, transition: { duration: 0.25 } },
    },
    slideDown: {
      hidden: { y: -60, opacity: 0 },
      visible: { y: 0, opacity: 1, transition: { type: 'spring', stiffness: 350, damping: 25 } },
      exit: { y: -60, opacity: 0, transition: { duration: 0.25 } },
    },
    fade: {
      hidden: { opacity: 0 },
      visible: { opacity: 1, transition: { duration: 0.35 } },
      exit: { opacity: 0, transition: { duration: 0.2 } },
    },
    scale: {
      hidden: { scale: 0.7, opacity: 0 },
      visible: { scale: 1, opacity: 1, transition: { type: 'spring', stiffness: 400, damping: 20 } },
      exit: { scale: 0.7, opacity: 0, transition: { duration: 0.2 } },
    },
    bounce: {
      hidden: { scale: 0.5, opacity: 0 },
      visible: { scale: 1, opacity: 1, transition: { type: 'spring', stiffness: 500, damping: 12 } },
      exit: { scale: 0.5, opacity: 0, transition: { duration: 0.2 } },
    },
    elastic: {
      hidden: { scale: 0.3, opacity: 0, x: 40 },
      visible: { scale: 1, opacity: 1, x: 0, transition: { type: 'spring', stiffness: 260, damping: 12 } },
      exit: { scale: 0.3, opacity: 0, x: -40, transition: { duration: 0.3 } },
    },
    flip: {
      hidden: { rotateX: -90, opacity: 0 },
      visible: { rotateX: 0, opacity: 1, transition: { duration: 0.5, ease: 'easeOut' } },
      exit: { rotateX: 90, opacity: 0, transition: { duration: 0.3 } },
    },
    swing: {
      hidden: { rotate: -15, opacity: 0, y: 30 },
      visible: { rotate: 0, opacity: 1, y: 0, transition: { type: 'spring', stiffness: 300, damping: 15 } },
      exit: { rotate: 15, opacity: 0, y: -30, transition: { duration: 0.3 } },
    },
    zoomBounce: {
      hidden: { scale: 0.1, opacity: 0 },
      visible: {
        scale: 1,
        opacity: 1,
        transition: {
          type: 'spring',
          stiffness: 200,
          damping: 10,
          restDelta: 0.001,
        },
      },
      exit: { scale: 0.1, opacity: 0, transition: { duration: 0.25 } },
    },
  };

  const variant = variants[animationVariant] || variants.slideIn;

  return (
    <motion.div
      layout
      initial="hidden"
      animate="visible"
      exit="exit"
      variants={variant}
      className={`pointer-events-auto w-full max-w-sm overflow-hidden rounded-xl border ${config.border} ${config.bg} backdrop-blur-sm shadow-lg ${config.glow}`}
    >
      <div className="relative flex gap-3 p-4">
        <div className={`flex-shrink-0 flex h-10 w-10 items-center justify-center rounded-lg ${config.iconBg}`}>
          <Icon className={`h-5 w-5 ${config.iconColor}`} />
        </div>

        <div className="flex-1 min-w-0">
          <h4 className={`text-sm font-semibold ${config.title} mb-0.5 truncate`}>
            {title}
          </h4>
          <p className="text-xs text-zinc-400 leading-relaxed">
            {message}
          </p>
        </div>

        {dismissible && (
          <button
            onClick={() => onDismiss(id)}
            className="flex-shrink-0 h-7 w-7 inline-flex items-center justify-center rounded-lg text-zinc-500 hover:text-white hover:bg-white/10 transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-400/50"
            aria-label="Dismiss alert"
          >
            <X className="h-3.5 w-3.5" />
          </button>
        )}
      </div>

      {autoClose && (
        <div className="h-0.5 w-full bg-white/[0.06]">
          <motion.div
            initial={{ width: '100%' }}
            animate={{ width: '0%' }}
            transition={{ duration: duration / 1000, ease: 'linear' }}
            className={`h-full ${config.progress} rounded-full`}
          />
        </div>
      )}
    </motion.div>
  );
}