'use client' import * as React from 'react' import { Search, type LucideIcon } from 'lucide-react' import { Input } from '@/components/ui/input' import { cn } from '@/lib/utils' export interface DetailListProps { items: Array<{ id: string label: string description?: string icon?: LucideIcon onClick?: () => void }> searchable?: boolean emptyText?: string maxHeight?: string className?: string } /** * 通用列表组件 * 展示项目列表,支持图标、描述、操作和搜索 */ export function DetailList({ items, searchable = false, emptyText = '暂无数据', maxHeight = '300px', className, }: DetailListProps) { const [searchQuery, setSearchQuery] = React.useState('') const filteredItems = React.useMemo(() => { if (!searchQuery) return items const query = searchQuery.toLowerCase() return items.filter( (item) => item.label.toLowerCase().includes(query) || item.description?.toLowerCase().includes(query) ) }, [items, searchQuery]) if (items.length === 0) { return (
{emptyText}
) } return (
{searchable && (
setSearchQuery(e.target.value)} className="pl-9 h-9" />
)}
{filteredItems.length === 0 ? (
未找到匹配项
) : ( filteredItems.map((item) => { const Icon = item.icon return (
{Icon && ( )}
{item.label}
{item.description && (
{item.description}
)}
) }) )}
) }