@moontra/moonui-pro 2.4.6 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,344 @@
1
+ "use client"
2
+
3
+ import React from 'react'
4
+ import { motion, AnimatePresence } from 'framer-motion'
5
+ import { Card, CardContent, CardHeader, CardTitle } from '../../ui/card'
6
+ import { Button } from '../../ui/button'
7
+ import { Avatar, AvatarFallback, AvatarImage } from '../../ui/avatar'
8
+ import { Badge } from '../../ui/badge'
9
+ import { cn } from '../../../lib/utils'
10
+ import {
11
+ Activity,
12
+ Info,
13
+ CheckCircle,
14
+ AlertCircle,
15
+ XCircle,
16
+ Clock,
17
+ MoreHorizontal,
18
+ Filter,
19
+ RefreshCw,
20
+ Bell,
21
+ BellOff
22
+ } from 'lucide-react'
23
+ import { ActivityItem } from '../types'
24
+ import { formatDistanceToNow } from 'date-fns'
25
+ import {
26
+ DropdownMenu,
27
+ DropdownMenuContent,
28
+ DropdownMenuItem,
29
+ DropdownMenuSeparator,
30
+ DropdownMenuTrigger,
31
+ } from '../../ui/dropdown-menu'
32
+ import { ScrollArea } from '../../ui/scroll-area'
33
+
34
+ interface ActivityFeedProps {
35
+ items: ActivityItem[]
36
+ title?: string
37
+ className?: string
38
+ height?: number
39
+ onItemClick?: (item: ActivityItem) => void
40
+ onAction?: (action: string, data?: any) => void
41
+ loading?: boolean
42
+ showFilters?: boolean
43
+ showNotifications?: boolean
44
+ glassmorphism?: boolean
45
+ realtime?: boolean
46
+ }
47
+
48
+ export function ActivityFeed({
49
+ items,
50
+ title = "Activity Feed",
51
+ className,
52
+ height = 400,
53
+ onItemClick,
54
+ onAction,
55
+ loading = false,
56
+ showFilters = true,
57
+ showNotifications = true,
58
+ glassmorphism = false,
59
+ realtime = false
60
+ }: ActivityFeedProps) {
61
+ const [filter, setFilter] = React.useState<'all' | 'info' | 'success' | 'warning' | 'error'>('all')
62
+ const [notificationsEnabled, setNotificationsEnabled] = React.useState(true)
63
+ const [newItems, setNewItems] = React.useState<ActivityItem[]>([])
64
+
65
+ // Simüle edilmiş real-time güncellemeler
66
+ React.useEffect(() => {
67
+ if (!realtime) return
68
+
69
+ const interval = setInterval(() => {
70
+ const randomItem: ActivityItem = {
71
+ id: `new-${Date.now()}`,
72
+ type: ['info', 'success', 'warning', 'error'][Math.floor(Math.random() * 4)] as any,
73
+ title: 'New activity',
74
+ description: 'Something happened just now',
75
+ timestamp: new Date(),
76
+ user: {
77
+ name: 'System',
78
+ avatar: undefined
79
+ }
80
+ }
81
+
82
+ setNewItems(prev => [randomItem, ...prev].slice(0, 3))
83
+
84
+ setTimeout(() => {
85
+ setNewItems(prev => prev.filter(item => item.id !== randomItem.id))
86
+ }, 5000)
87
+ }, 10000)
88
+
89
+ return () => clearInterval(interval)
90
+ }, [realtime])
91
+
92
+ // Tip ikonları
93
+ const getTypeIcon = (type: ActivityItem['type']) => {
94
+ switch (type) {
95
+ case 'info':
96
+ return <Info className="h-4 w-4" />
97
+ case 'success':
98
+ return <CheckCircle className="h-4 w-4" />
99
+ case 'warning':
100
+ return <AlertCircle className="h-4 w-4" />
101
+ case 'error':
102
+ return <XCircle className="h-4 w-4" />
103
+ }
104
+ }
105
+
106
+ // Tip renkleri
107
+ const getTypeColor = (type: ActivityItem['type']) => {
108
+ switch (type) {
109
+ case 'info':
110
+ return 'text-blue-500 bg-blue-100 dark:bg-blue-900/20'
111
+ case 'success':
112
+ return 'text-green-500 bg-green-100 dark:bg-green-900/20'
113
+ case 'warning':
114
+ return 'text-yellow-500 bg-yellow-100 dark:bg-yellow-900/20'
115
+ case 'error':
116
+ return 'text-red-500 bg-red-100 dark:bg-red-900/20'
117
+ }
118
+ }
119
+
120
+ // Filtrelenmiş öğeler
121
+ const filteredItems = [...newItems, ...items].filter(item =>
122
+ filter === 'all' || item.type === filter
123
+ )
124
+
125
+ // Activity item renderer
126
+ const renderActivityItem = (item: ActivityItem, isNew: boolean = false) => (
127
+ <motion.div
128
+ key={item.id}
129
+ layout
130
+ initial={{ opacity: 0, x: -20 }}
131
+ animate={{ opacity: 1, x: 0 }}
132
+ exit={{ opacity: 0, x: 20 }}
133
+ whileHover={{ x: 4 }}
134
+ transition={{ duration: 0.2 }}
135
+ className={cn(
136
+ "group relative flex gap-3 p-3 rounded-lg cursor-pointer transition-colors",
137
+ "hover:bg-muted/50",
138
+ isNew && "bg-primary/5 border-l-2 border-primary"
139
+ )}
140
+ onClick={() => onItemClick?.(item)}
141
+ >
142
+ {/* Timeline çizgisi */}
143
+ <div className="absolute left-7 top-12 bottom-0 w-px bg-border" />
144
+
145
+ {/* İkon veya Avatar */}
146
+ <div className="relative z-10 flex-shrink-0">
147
+ {item.user?.avatar ? (
148
+ <Avatar className="h-8 w-8">
149
+ <AvatarImage src={item.user.avatar} />
150
+ <AvatarFallback>{item.user.name[0]}</AvatarFallback>
151
+ </Avatar>
152
+ ) : (
153
+ <div className={cn(
154
+ "h-8 w-8 rounded-full flex items-center justify-center",
155
+ getTypeColor(item.type)
156
+ )}>
157
+ {item.icon || getTypeIcon(item.type)}
158
+ </div>
159
+ )}
160
+ </div>
161
+
162
+ {/* İçerik */}
163
+ <div className="flex-1 min-w-0">
164
+ <div className="flex items-start justify-between gap-2">
165
+ <div className="flex-1 min-w-0">
166
+ <p className="text-sm font-medium leading-tight">
167
+ {item.user?.name && (
168
+ <span className="text-foreground">{item.user.name} </span>
169
+ )}
170
+ <span className="text-muted-foreground">{item.title}</span>
171
+ </p>
172
+ {item.description && (
173
+ <p className="text-sm text-muted-foreground mt-0.5 line-clamp-2">
174
+ {item.description}
175
+ </p>
176
+ )}
177
+ </div>
178
+
179
+ {/* Zaman damgası */}
180
+ <div className="flex items-center gap-1 text-xs text-muted-foreground whitespace-nowrap">
181
+ <Clock className="h-3 w-3" />
182
+ {formatDistanceToNow(item.timestamp, { addSuffix: true })}
183
+ </div>
184
+ </div>
185
+
186
+ {/* Yeni öğe badge'i */}
187
+ {isNew && (
188
+ <motion.div
189
+ initial={{ scale: 0 }}
190
+ animate={{ scale: 1 }}
191
+ className="inline-block mt-1"
192
+ >
193
+ <Badge variant="default" className="text-xs">New</Badge>
194
+ </motion.div>
195
+ )}
196
+ </div>
197
+
198
+ {/* Hover aksiyonları */}
199
+ <div className="opacity-0 group-hover:opacity-100 transition-opacity">
200
+ <Button
201
+ variant="ghost"
202
+ size="sm"
203
+ className="h-6 w-6 p-0"
204
+ onClick={(e) => {
205
+ e.stopPropagation()
206
+ onAction?.('more', item)
207
+ }}
208
+ >
209
+ <MoreHorizontal className="h-3 w-3" />
210
+ </Button>
211
+ </div>
212
+ </motion.div>
213
+ )
214
+
215
+ return (
216
+ <Card className={cn(
217
+ "relative overflow-hidden",
218
+ glassmorphism && "bg-background/60 backdrop-blur-md border-white/10",
219
+ className
220
+ )}>
221
+ {/* Header */}
222
+ <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-3">
223
+ <div className="flex items-center gap-2">
224
+ <Activity className="h-4 w-4 text-muted-foreground" />
225
+ <CardTitle className="text-base font-semibold">{title}</CardTitle>
226
+ {realtime && (
227
+ <Badge variant="secondary" className="text-xs">
228
+ <span className="mr-1 h-1.5 w-1.5 rounded-full bg-green-500 animate-pulse" />
229
+ Live
230
+ </Badge>
231
+ )}
232
+ </div>
233
+
234
+ {/* Aksiyonlar */}
235
+ <div className="flex items-center gap-1">
236
+ {showFilters && (
237
+ <DropdownMenu>
238
+ <DropdownMenuTrigger asChild>
239
+ <Button variant="ghost" size="sm" className="h-8 px-2">
240
+ <Filter className="h-4 w-4 mr-1" />
241
+ {filter !== 'all' && <Badge variant="secondary" className="ml-1">{filter}</Badge>}
242
+ </Button>
243
+ </DropdownMenuTrigger>
244
+ <DropdownMenuContent align="end">
245
+ <DropdownMenuItem onClick={() => setFilter('all')}>
246
+ All Activities
247
+ </DropdownMenuItem>
248
+ <DropdownMenuSeparator />
249
+ <DropdownMenuItem onClick={() => setFilter('info')}>
250
+ <Info className="mr-2 h-4 w-4 text-blue-500" />
251
+ Information
252
+ </DropdownMenuItem>
253
+ <DropdownMenuItem onClick={() => setFilter('success')}>
254
+ <CheckCircle className="mr-2 h-4 w-4 text-green-500" />
255
+ Success
256
+ </DropdownMenuItem>
257
+ <DropdownMenuItem onClick={() => setFilter('warning')}>
258
+ <AlertCircle className="mr-2 h-4 w-4 text-yellow-500" />
259
+ Warning
260
+ </DropdownMenuItem>
261
+ <DropdownMenuItem onClick={() => setFilter('error')}>
262
+ <XCircle className="mr-2 h-4 w-4 text-red-500" />
263
+ Error
264
+ </DropdownMenuItem>
265
+ </DropdownMenuContent>
266
+ </DropdownMenu>
267
+ )}
268
+
269
+ {showNotifications && (
270
+ <Button
271
+ variant="ghost"
272
+ size="sm"
273
+ className="h-8 w-8 p-0"
274
+ onClick={() => {
275
+ setNotificationsEnabled(!notificationsEnabled)
276
+ onAction?.('notifications', { enabled: !notificationsEnabled })
277
+ }}
278
+ >
279
+ {notificationsEnabled ? (
280
+ <Bell className="h-4 w-4" />
281
+ ) : (
282
+ <BellOff className="h-4 w-4 text-muted-foreground" />
283
+ )}
284
+ </Button>
285
+ )}
286
+
287
+ <Button
288
+ variant="ghost"
289
+ size="sm"
290
+ className="h-8 w-8 p-0"
291
+ onClick={() => onAction?.('refresh')}
292
+ >
293
+ <RefreshCw className="h-4 w-4" />
294
+ </Button>
295
+ </div>
296
+ </CardHeader>
297
+
298
+ {/* İçerik */}
299
+ <CardContent className="p-0">
300
+ <ScrollArea className="px-4 pb-4" style={{ height }}>
301
+ <AnimatePresence mode="popLayout">
302
+ {loading ? (
303
+ <motion.div
304
+ key="loading"
305
+ initial={{ opacity: 0 }}
306
+ animate={{ opacity: 1 }}
307
+ exit={{ opacity: 0 }}
308
+ className="space-y-3"
309
+ >
310
+ {[...Array(5)].map((_, i) => (
311
+ <div key={i} className="flex gap-3">
312
+ <div className="h-8 w-8 rounded-full bg-muted animate-pulse" />
313
+ <div className="flex-1 space-y-2">
314
+ <div className="h-4 bg-muted rounded animate-pulse" />
315
+ <div className="h-3 bg-muted rounded w-3/4 animate-pulse" />
316
+ </div>
317
+ </div>
318
+ ))}
319
+ </motion.div>
320
+ ) : filteredItems.length === 0 ? (
321
+ <motion.div
322
+ key="empty"
323
+ initial={{ opacity: 0 }}
324
+ animate={{ opacity: 1 }}
325
+ className="flex flex-col items-center justify-center py-12 text-muted-foreground"
326
+ >
327
+ <Activity className="h-8 w-8 mb-2" />
328
+ <p className="text-sm">No activities to show</p>
329
+ </motion.div>
330
+ ) : (
331
+ <div className="space-y-1">
332
+ {filteredItems.map(item =>
333
+ renderActivityItem(item, newItems.some(newItem => newItem.id === item.id))
334
+ )}
335
+ </div>
336
+ )}
337
+ </AnimatePresence>
338
+ </ScrollArea>
339
+ </CardContent>
340
+ </Card>
341
+ )
342
+ }
343
+
344
+ export default ActivityFeed