Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ReportSelector.tsx

113 lines4.0 KB

1'use client'
2​
3import { useState } from 'react'
4import { ChevronDown, X, Trash2 } from 'lucide-react'
5import { motion, AnimatePresence } from 'framer-motion'
6import type { Report } from '@/lib/reports/types'
7​
8interface ReportSelectorProps {
9 reports: Report[]
10 activeReportId: string
11 onSelectReport: (reportId: string) => void
12 onCloseReport: () => void
13 onClearAll: () => void
15​
16export function ReportSelector({
17 reports,
18 activeReportId,
19 onSelectReport,
20 onCloseReport,
21 onClearAll,
22}: ReportSelectorProps) {
23 const [isOpen, setIsOpen] = useState(false)
24 const activeReport = reports.find((r) => r.id === activeReportId)
25​
26 return (
27 <div className="flex items-center gap-2 p-3 border-b border-sky-200/60 bg-sky-100/50">
28 <div className="relative flex-1">
29 <button
30 onClick={() => setIsOpen(!isOpen)}
31 className="w-full flex items-center justify-between px-3 py-2 text-left bg-white/60 hover:bg-white/80 rounded-lg transition-colors border border-sky-200/40"
32 >
33 <span className="truncate font-medium text-slate-700">
34 {activeReport?.title ?? 'Select Report'}
35 </span>
36 <ChevronDown className="w-4 h-4 text-slate-500 flex-shrink-0 ml-2" />
37 </button>
38​
39 <AnimatePresence>
40 {isOpen && (
41 <>
42 {/* Backdrop */}
43 <div
44 className="fixed inset-0 z-40"
45 onClick={() => setIsOpen(false)}
46 />
47​
48 {/* Dropdown */}
49 <motion.div
50 initial={{ opacity: 0, y: -8, scale: 0.96 }}
51 animate={{ opacity: 1, y: 0, scale: 1 }}
52 exit={{ opacity: 0, y: -8, scale: 0.96 }}
53 transition={{ duration: 0.15 }}
54 className="absolute left-0 right-0 top-full mt-1 bg-white border border-sky-200/60 rounded-lg shadow-xl z-50 overflow-hidden"
55 >
56 <div className="py-1 max-h-64 overflow-auto">
57 {reports.map((report) => (
58 <button
59 key={report.id}
60 onClick={() => {
61 onSelectReport(report.id)
62 setIsOpen(false)
63 }}
64 className="w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-sky-50 transition-colors"
65 >
66 {report.id === activeReportId && (
67 <div className="w-1.5 h-1.5 rounded-full bg-cyan-500 flex-shrink-0" />
68 )}
69 <span
70 className={`truncate ${
71 report.id === activeReportId
72 ? 'font-medium text-slate-800'
73 : 'text-slate-600'
74 }`}
75 >
76 {report.title}
77 </span>
78 </button>
79 ))}
80 </div>
81​
82 {reports.length > 0 && (
83 <div className="border-t border-sky-200/60">
84 <button
85 onClick={() => {
86 if (confirm('Clear all reports?')) {
87 onClearAll()
88 setIsOpen(false)
89 }
90 }}
91 className="w-full flex items-center gap-2 px-3 py-2 text-left text-red-600 hover:text-red-700 hover:bg-red-50 transition-colors"
92 >
93 <Trash2 className="w-4 h-4" />
94 <span>Clear All Reports</span>
95 </button>
96 </div>
97 )}
98 </motion.div>
99 </>
100 )}
101 </AnimatePresence>
102 </div>
103​
104 <button
105 onClick={onCloseReport}
106 className="p-2 text-slate-500 hover:text-slate-700 hover:bg-sky-100 rounded-lg transition-colors"
107 title="Close report panel"
108 >
109 <X className="w-4 h-4" />
110 </button>
111 </div>
112 )