| // src/components/multimodal/CsvDataTable.tsx | |
| import { useState, useMemo } from "react"; | |
| import { Search, ChevronLeft, ChevronRight } from "lucide-react"; | |
| interface CsvDataTableProps { | |
| headers: string[]; | |
| rows: string[][]; | |
| pageSize?: number; | |
| } | |
| export function CsvDataTable({ headers, rows, pageSize = 5 }: CsvDataTableProps) { | |
| const [search, setSearch] = useState(""); | |
| const [page, setPage] = useState(0); | |
| const filtered = useMemo(() => { | |
| if (!search.trim()) return rows; | |
| const q = search.toLowerCase(); | |
| return rows.filter((row) => | |
| row.some((cell) => cell.toLowerCase().includes(q)) | |
| ); | |
| }, [rows, search]); | |
| const totalPages = Math.ceil(filtered.length / pageSize); | |
| const displayed = filtered.slice(page * pageSize, (page + 1) * pageSize); | |
| return ( | |
| <div className="space-y-2"> | |
| {/* Search */} | |
| <div className="relative"> | |
| <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-gray-400" /> | |
| <input | |
| type="text" | |
| placeholder="Search data..." | |
| value={search} | |
| onChange={(e) => { | |
| setSearch(e.target.value); | |
| setPage(0); | |
| }} | |
| className="w-full pl-7 pr-3 py-1.5 text-xs border rounded-lg dark:bg-gray-700 dark:border-gray-600" | |
| /> | |
| </div> | |
| {/* Table */} | |
| <div className="overflow-x-auto border rounded-lg dark:border-gray-600"> | |
| <table className="min-w-full text-xs"> | |
| <thead> | |
| <tr className="bg-gray-100 dark:bg-gray-800"> | |
| {headers.map((h, i) => ( | |
| <th key={i} className="px-3 py-2 text-left font-semibold text-gray-600 dark:text-gray-300 whitespace-nowrap"> | |
| {h} | |
| </th> | |
| ))} | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {displayed.map((row, ri) => ( | |
| <tr key={ri} className="border-t dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-800/50"> | |
| {row.map((cell, ci) => ( | |
| <td key={ci} className="px-3 py-1.5 text-gray-700 dark:text-gray-300 whitespace-nowrap max-w-[200px] truncate"> | |
| {cell} | |
| </td> | |
| ))} | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </div> | |
| {/* Pagination */} | |
| {totalPages > 1 && ( | |
| <div className="flex items-center justify-between text-xs text-gray-500"> | |
| <span> | |
| {filtered.length} row{filtered.length !== 1 ? "s" : ""} | |
| </span> | |
| <div className="flex items-center gap-2"> | |
| <button | |
| onClick={() => setPage((p) => Math.max(0, p - 1))} | |
| disabled={page === 0} | |
| className="p-1 disabled:opacity-30" | |
| > | |
| <ChevronLeft className="w-4 h-4" /> | |
| </button> | |
| <span>{page + 1} / {totalPages}</span> | |
| <button | |
| onClick={() => setPage((p) => Math.min(totalPages - 1, p + 1))} | |
| disabled={page === totalPages - 1} | |
| className="p-1 disabled:opacity-30" | |
| > | |
| <ChevronRight className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 3.24 kB
- Xet hash:
- 0ef45b63b413ddc78d168162bc8c6bde7f905bd031bc3d6816f0e7e69e2da692
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.