import React, { useState, useMemo } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Search } from "lucide-react"; import { searchLucideIcons, ICON_CATEGORIES } from '@/config/lucideIcons'; import DynamicIcon from '@/components/DynamicIcon'; interface LucideIconSelectProps { /** 当前选中的图标名称 */ value?: string; /** 图标变化回调 */ onChange?: (iconName: string) => void; /** 是否显示弹窗 */ open: boolean; /** 关闭弹窗回调 */ onOpenChange: (open: boolean) => void; } /** * Lucide 图标选择器组件 * * 支持: * - 搜索图标 * - 分类浏览 * - 点击选择 */ const LucideIconSelect: React.FC = ({ value, onChange, open, onOpenChange }) => { const [search, setSearch] = useState(''); const [category, setCategory] = useState('all'); // 过滤图标列表 const iconList = useMemo(() => { return searchLucideIcons(search, category); }, [search, category]); // 选择图标 const handleSelect = (iconName: string) => { onChange?.(iconName); onOpenChange(false); setSearch(''); setCategory('all'); }; return ( 选择图标
{/* 搜索框 */}
setSearch(e.target.value)} className="pl-10" />
{/* 分类标签 */} 全部 ({iconList.length}) {Object.keys(ICON_CATEGORIES).map((cat) => ( {cat} ))} {/* 图标网格 */}
{iconList.length > 0 ? ( iconList.map(({ name, component: Icon }) => ( )) ) : (
未找到匹配的图标
)}
{/* 当前选中 */} {value && (
当前选中:
{value}
)}
); }; export default LucideIconSelect;